Lesson 3. SendInstantOrder. Error in strategy
Posted: Sun Apr 26, 2015 2:02 am
Hello
I have problems with "SendInstant Order" in the example of Lesson 3.
I print the iTime of the bar when I arrive at 8 hour, and previous to the statement of SendInstant Order, as you can see in the image attached.
The print goes well, but when the program execute the SendInstantOrder takes me away from the
"GetSingleTick" and I can´t see what happen with the OrderHandler
I think the stop loss and take profit are correct.
I have tried also to execute: SendInstantOrder ("EURUSD", op_Buy,0.1,0.0, 0.0, "", 0, OrderHandle);
but it is the same story
My code is:
/*Our new strategy will open a market order at 8 a.m. every day
with TakeProfit = 50 and StopLoss = 100.
*/
#include <iostream>
#define DLL_EXPORT
#include <windows.h>
#include "FF2_SendInstantOrder.h"
#include "StrategyInterfaceUnit.h"
#include <time.h> // time_t, tm
// external parameters
char* Currency;
char buff[200];
int w_min, w_wday, w_hour, w_year, w_month, w_day;
int ot=0 ;
int lastHour =0 ;
int OrderHandle;
void EstablishDateTimeValues()
{
time_t mytime; // define structure (jpb.creo que no es struct sino un longint) of type time_t,
// c++ base date is 01/01/1970 (25569 days after FT start date of 30/12/1899)
// Defined in time.h
struct tm * timeinfo; // define local structure 'tm' to hold calendar date in component parts.
// Convert FT date/time to c++ equivalent.Seconds/day = 86400
mytime = ((iTime("EURUSD", PERIOD_M1, 0) - 25569) * 86400);
timeinfo = gmtime(&mytime); // Copy that time to modifiable structure 'timeinfo (note GMT)
w_year = 1900 + timeinfo->tm_year; // save year, adjusted (years since 1900), as used in FT
w_month = 1 + timeinfo->tm_mon; // save month number, adjusted (runs 0 - 11)
w_day = timeinfo->tm_mday; // save day of month (runs 1 - 31)
w_wday = timeinfo->tm_wday; // save day of week (runs 0 - 6, sunday=0)
w_hour = timeinfo->tm_hour; // save hour of day (runs 0 - 23)
w_min = timeinfo->tm_min; // save minute of hour (runs 0 - 59)
mktime ( timeinfo ); // call mktime to set timeinfo structure variables jpb¿?
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DECLDIR void InitStrategy()
{
StrategyShortName("SendInstantOrder");
StrategyDescription("SendInstantOrder essay");
RegOption("Currency", ot_Currency, &Currency);
ReplaceStr(Currency, "EURUSD");
SetCurrencyAndTimeframe("EURUSD", PERIOD_M1);
}
DECLDIR void DoneStrategy()
{
free(Currency);
}
DECLDIR void ResetStrategy()
{
}
DECLDIR void GetSingleTick()
{
EstablishDateTimeValues(); // Establish iTime date/time variables for each tick
if (lastHour!= w_hour){ // Print iTime each hour
sprintf (buff,"iTime values are: Year=%d Month=%d Date=%d DayOfWeek=%d Hour=%d",
w_year, w_month, w_day, w_wday, w_hour);
Print(buff);
lastHour = w_hour;
}
if ((w_hour == && (ot == 0)) // (OrdersTotal() == 0))
{
ot++; // To only print once
sprintf (buff,"SendInstantOrder: %s ,%d , %.1f , %.4f , %.4f, %s, %d",
Symbol(),op_Buy, 0.1,Ask()-100*Point(),Ask()+50*Point(),"Coment", 0);
Print(buff);
SendInstantOrder
(Symbol(), op_Buy,0.1,Ask()-100*Point(),Ask()+ 50*Point(),"",0,OrderHandle);
// SendInstantOrder
// ("EURUSD", op_Buy,0.1,0.0, 0.0, "", 0, OrderHandle);
sprintf(buff,"OrderHandle: %d", OrderHandle) ;
Print (buff);
}
}
can anybody help me
Thanks in advance
I have problems with "SendInstant Order" in the example of Lesson 3.
I print the iTime of the bar when I arrive at 8 hour, and previous to the statement of SendInstant Order, as you can see in the image attached.
The print goes well, but when the program execute the SendInstantOrder takes me away from the
"GetSingleTick" and I can´t see what happen with the OrderHandler
I think the stop loss and take profit are correct.
I have tried also to execute: SendInstantOrder ("EURUSD", op_Buy,0.1,0.0, 0.0, "", 0, OrderHandle);
but it is the same story
My code is:
/*Our new strategy will open a market order at 8 a.m. every day
with TakeProfit = 50 and StopLoss = 100.
*/
#include <iostream>
#define DLL_EXPORT
#include <windows.h>
#include "FF2_SendInstantOrder.h"
#include "StrategyInterfaceUnit.h"
#include <time.h> // time_t, tm
// external parameters
char* Currency;
char buff[200];
int w_min, w_wday, w_hour, w_year, w_month, w_day;
int ot=0 ;
int lastHour =0 ;
int OrderHandle;
void EstablishDateTimeValues()
{
time_t mytime; // define structure (jpb.creo que no es struct sino un longint) of type time_t,
// c++ base date is 01/01/1970 (25569 days after FT start date of 30/12/1899)
// Defined in time.h
struct tm * timeinfo; // define local structure 'tm' to hold calendar date in component parts.
// Convert FT date/time to c++ equivalent.Seconds/day = 86400
mytime = ((iTime("EURUSD", PERIOD_M1, 0) - 25569) * 86400);
timeinfo = gmtime(&mytime); // Copy that time to modifiable structure 'timeinfo (note GMT)
w_year = 1900 + timeinfo->tm_year; // save year, adjusted (years since 1900), as used in FT
w_month = 1 + timeinfo->tm_mon; // save month number, adjusted (runs 0 - 11)
w_day = timeinfo->tm_mday; // save day of month (runs 1 - 31)
w_wday = timeinfo->tm_wday; // save day of week (runs 0 - 6, sunday=0)
w_hour = timeinfo->tm_hour; // save hour of day (runs 0 - 23)
w_min = timeinfo->tm_min; // save minute of hour (runs 0 - 59)
mktime ( timeinfo ); // call mktime to set timeinfo structure variables jpb¿?
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DECLDIR void InitStrategy()
{
StrategyShortName("SendInstantOrder");
StrategyDescription("SendInstantOrder essay");
RegOption("Currency", ot_Currency, &Currency);
ReplaceStr(Currency, "EURUSD");
SetCurrencyAndTimeframe("EURUSD", PERIOD_M1);
}
DECLDIR void DoneStrategy()
{
free(Currency);
}
DECLDIR void ResetStrategy()
{
}
DECLDIR void GetSingleTick()
{
EstablishDateTimeValues(); // Establish iTime date/time variables for each tick
if (lastHour!= w_hour){ // Print iTime each hour
sprintf (buff,"iTime values are: Year=%d Month=%d Date=%d DayOfWeek=%d Hour=%d",
w_year, w_month, w_day, w_wday, w_hour);
Print(buff);
lastHour = w_hour;
}
if ((w_hour == && (ot == 0)) // (OrdersTotal() == 0))
{
ot++; // To only print once
sprintf (buff,"SendInstantOrder: %s ,%d , %.1f , %.4f , %.4f, %s, %d",
Symbol(),op_Buy, 0.1,Ask()-100*Point(),Ask()+50*Point(),"Coment", 0);
Print(buff);
SendInstantOrder
(Symbol(), op_Buy,0.1,Ask()-100*Point(),Ask()+ 50*Point(),"",0,OrderHandle);
// SendInstantOrder
// ("EURUSD", op_Buy,0.1,0.0, 0.0, "", 0, OrderHandle);
sprintf(buff,"OrderHandle: %d", OrderHandle) ;
Print (buff);
}
}
can anybody help me
Thanks in advance