Problem with lesson 3

Examples step by step how to make your own automated strategy or user indicator
Message
Author
Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

Problem with lesson 3

#1 Postby Eve » Wed Mar 28, 2012 10:37 am

Hi,

I'm trying to compile the code from lesson 3 in c++. The complier is returning zero mistakes but i can't get the strategy to work.

When i set all the parameters and start testing in forex tester nothing is happening:

Here is my code:


#include <windows.h>
#include "StrategyInterfaceUnit.h"
#include "TechnicalFunctions.h"
#include <time.h>
#include <ctime>


int w_min, w_wday, w_hour, w_year, w_month, w_day;

//external parameter
char* Currency;
int OpenTime=8;
int StopLoss=100;
int TakeProfit=50;
double LotSize=0.1;

EXPORT void __stdcall InitStrategy()
{
StrategyShortName("8 hour order");
StrategyDescription("Strategy opens orders at 8 a.m.");

RegOption("Currency", ot_Currency, &Currency);
RegOption("OpenTime", ot_Integer, &OpenTime);
RegOption("StopLoss", ot_Integer, &StopLoss);
RegOption("TakeProfit", ot_Integer, &TakeProfit);
RegOption("LotSize", ot_Double, &LotSize);
SetOptionDigits("LotSize",1);
}

EXPORT void __stdcall DoneStrategy()
{
free(Currency);
}

EXPORT void __stdcall ResetStrategy()
{
}


void EstablishDateTimeValues()
{
time_t mytime; // define structure of type time_t, c++ base date is 01/01/1970 (25569 days after FT start date of 30/12/1899)
mytime = (time_t) ((TimeCurrent() - 25569) * 86400); // Convert FT date/time to c++ equivalent
struct tm * timeinfo; // define local structure 'tm' to hold calendar date in component parts
timeinfo = gmtime(&mytime); // Copy that time to modifiable structure 'timeinfo (note GMT)
w_year = 1900 + timeinfo->tm_year; // save year, adjusted (years since 1900)
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
}

EXPORT void __stdcall GetSingleTick()
{
TDateTime time;
int OrderHandle;

if (Symbol() != Currency)
{return;}

time = iTime(Symbol(), PERIOD_M1, 0);
EstablishDateTimeValues();

if (w_hour == 8 && OrdersTotal() == 0) {
SendInstantOrder(Symbol(), op_Buy, LotSize, Ask() - StopLoss*Point(), Ask() + TakeProfit*Point(), "", 0, OrderHandle);
}
}

Please help with some advice!

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Wed Mar 28, 2012 11:52 pm

Hello,

Please check that strategies are enabled in your Forex Tester ("Testing -> Enable/Disable Strategies") also make sure that your strategy is checked in "Strategies list".
If it does not help then add "Print" statements to your strategy code and review the logs. "Print" statements are a good way to find a problem in code.
Also you can try to debug your strategy, i do not know how to do that with your IDE but here are the instructions how to debug strategy in Delphi: http://forextester.com/forum/viewtopic. ... ight=debug

Let us know if you still have problems.
Check our other product here:
http://www.forexcopier.com

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#3 Postby Eve » Thu Mar 29, 2012 3:20 am

Hello,

I have previously checked that the strategy is enabled as well as checked in the strategy list, but i can't figure out how to do the debugging...

I added a few lines to my code:

sprintf (buff,"Current DateTime values are: Year=%d Month=%d Date=%d DayOfWeek=%d Time=%d:%d", w_year, w_month, w_day, w_wday, w_hour,w_min);
Print(buff);

but to be honest I don't know where to expect the output. When I start my strategy still nothing is happening.

As you can see it's pretty new to me so I'm apologizing for my maybe silly questions.

Cheers!

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#4 Postby FT Support » Thu Mar 29, 2012 1:25 pm

Hello,

Please review "Print" messages on the "Journal" tab of the "Terminal" window (see the screenshot below)
Attachments
journal.jpg
journal.jpg (117.2 KiB) Viewed 17207 times
Check our other product here:
http://www.forexcopier.com

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#5 Postby Eve » Fri Mar 30, 2012 2:38 am

Thank you for the tip but still nothing.

I thought it might be something about the part of code which examines the time of the bar so i changed that part into a simple order:

SetCurrencyAndTimeframe("EURCHF", PERIOD_M15);

if (Close(0) > Close (1) && Close(1) > Close(2) && Close(2)>Close(3) && Close(3) > Close(4) && Close(4)>Close(5) && OrdersTotal() == 0)
{SendInstantOrder(Symbol(), op_Buy, LotSize, Ask() - StopLoss*Point(), Ask() + TakeProfit*Point(), "", 0, OrderHandle);
},

just to see what happens, but in Forex Tester still nothing is happenenig.

The weired thing is that compiler says there are no mistakes, data for testing is well prepared, the strategy is installed, enabled, and checked in the strategy list... Any ideas where to look for the mistake next?

Thank you a lot for the help!!

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#6 Postby Eve » Mon Apr 02, 2012 2:59 am

One more thing, on the Jurnal box i can't se that my strategy is loaded and although i have it on my strategy list it seems that FT just doesn't recognize it...

Any ideas?

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#7 Postby FT Support » Mon Apr 02, 2012 6:48 am

Hello,

What can you see in Journal log?
How did you install the strategy into Forex Tester? did you use "File -> Install -> Install new strategy"?

Can you please create a strategy with only one "Print" code line in "GetSingleTick" method?
Check our other product here:
http://www.forexcopier.com

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#8 Postby Eve » Mon Apr 02, 2012 8:39 am

I put a print line inside the GetSingleTick code:

sprintf (buff,"Current DateTime values are: Year=%d Month=%d Date=%d DayOfWeek=%d Time=%d:%d", w_year, w_month, w_day, w_wday, w_hour,w_min);
Print(buff);

Output from debugging is just:
'ForexTester.exe': Loaded 'C:\ForexTester2\Strategies\EightHour.dll', Symbols loaded.

And after I start the strategy in forex tester i get lots of lines like:

First-chance exception at 0x7c812afb in ForexTester.exe: 0x0EEDFADE: 0xeedfade.

After I start the strategy , in jurnal window absolutely nothing is happening.

And yes, I installed the strategy via "File -> Install -> Install new strategy"?
It is on the strategy list, i can normally change its parameters but just can't get it to work...

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#9 Postby Eve » Tue Apr 03, 2012 11:02 am

Thank you for the attention and sorry for bothering you, but this is really driving me nuts...
Do you know what this "symbols loaded" means and could that be the problem?

"ForexTester.exe': Loaded 'C:\ForexTester2\Strategies\EightHour.dll', Symbols loaded."

I noticed that after loading al other indicators and strategies it says the opposite...

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#10 Postby FT Support » Wed Apr 04, 2012 5:20 am

Please put your code into zip archive and attach here in the forum, we'll take a look what is happening there.
Check our other product here:
http://www.forexcopier.com

Eve
Posts: 19
Joined: Wed Mar 28, 2012 10:31 am

#11 Postby Eve » Fri Apr 06, 2012 2:41 am

Thank you a lot but i figured it out :)

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#12 Postby FT Support » Fri Apr 06, 2012 2:46 am

Great! thank you for the update!
Check our other product here:
http://www.forexcopier.com


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 12 guests