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!
Problem with lesson 3
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
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.
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
http://www.forexcopier.com
-
- Posts: 19
- Joined: Wed Mar 28, 2012 10:31 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!
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!
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 19
- Joined: Wed Mar 28, 2012 10:31 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!!
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!!
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 19
- Joined: Wed Mar 28, 2012 10:31 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...
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...
-
- Posts: 19
- Joined: Wed Mar 28, 2012 10:31 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...
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...
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 14 guests