Lesson 3. SendInstantOrder. Error in strategy

Examples step by step how to make your own automated strategy or user indicator
Message
Author
javierp
Posts: 8
Joined: Thu Apr 16, 2015 6:04 am

Lesson 3. SendInstantOrder. Error in strategy

#1 Postby javierp » 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 == 8) && (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
Attachments
FF2_SendInstantOrder.jpg
ForexTester image with the error in the journal terminal
FF2_SendInstantOrder.jpg (168.65 KiB) Viewed 32124 times

javierp
Posts: 8
Joined: Thu Apr 16, 2015 6:04 am

Re: Lesson 3. SendInstantOrder. Error in strategy

#2 Postby javierp » Wed Apr 29, 2015 2:23 pm

Hello

I have just see the post:

viewtopic.php?f=9&t=3066

Posted by EVE : Wed Mar 28, 2012 3:37 pm

The problem is similar to mine.
At the end EVE found the solution (Post: Fri Apr 06, 2012 7:41 am)

EVE, your solution can be mine.

Could you help me?

Thanks

javierp
Posts: 8
Joined: Thu Apr 16, 2015 6:04 am

Re: Lesson 3. SendInstantOrder. Error in strategy

#3 Postby javierp » Thu Apr 30, 2015 12:52 am

Hello

As I have seen that several problems solves doing a reinstalation, I have reinstalled FT2, but the problem continues

Some idea ?

By the way, is there any way to insert an image (jpg), or the clipboard, directly in a post?

Thanks


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 22 guests