Struggling with Strategy Tester - Hour()

 

Hi everyone


First post here, however reading a lot. 

Hoping someone here can help with this.  Im struggling quite a bit with the strategy tester.

Im not really sure what Im doing wrong as I watched a video code this EA and it showed results.

Are there any limitations to the strategy tester that I should be aware of? Like you cant use the Hour() function or something.

Ive google around but cant find anything on it.


The system is simply, @ 9am Open a new long position,  40 pips target, 40 pips stop & only take the first order. (if theres anything in the code thats wrong)

Why does this produce no backtesting results?

Any help on this would be appreciated.

extern int StartHour = 9;
extern double Lots = 1.0;
extern int TakeProft = 40;
extern int StopLoss = 40;

void OnTimer()
  {
 static bool isFirstTick = true;
 static double ticket = 0;
 
 if (Hour() == StartHour) {
   if (isFirstTick == true) {
           isFirstTick = false;
           
           ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, Bid-StopLoss*Point, Bid+TakeProft*Point, "Buy at Time System");
           if (ticket<0){
             Print("Error Opening Order.");
           }
   }
 } else {
         isFirstTick = false;
         
 }//if Hour
  }
 
bchip: Why does this produce no backtesting results?
void OnTimer()
  1. Because the timer doesn't work on the tester.
    In backtest OnTimer() not performs (M. Ali) - MQL4 forum
    Chart Event For MT4 Backtester (Migel) - MQL4 forum
  2. Why are you using a repeating timer, instead of OnTick?
 

Hi

Thanks for the quick response.

I changed to OnTick and it made no difference to the results.


Do note that if I change the code to

//if (Hour() == StartHour) {

 if (true) {


So it does run, I do get a result of 1 trade.

 
 if (Hour() == StartHour) {
 ///////
 } else {
         isFirstTick = false;
         
 }//if Hour

isFirstTick is set to false if Hour()!=StartHour

 
GumRai:

isFirstTick is set to false if Hour()!=StartHour



Oh! I think I understand what your saying,

the first run is at hour = 0, sets it as false and then it stays false continuously.

Will have to rethink the code a bit when I get a chance.


Thank you!

Reason: