Why does my ea send orders an hour late?

Back to topics list To post a new topic, please log in or register
avatar
5
Ramysh 2015.09.21 21:21
 
int Ticket, BUY;
bool opened=0;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//BUY=iRSI(NULL,60,3,PRICE_CLOSE,0)-iRSI(NULL,60,12,PRICE_CLOSE,0);  //Buys and sells at the same time because RSI crosses for a second, ie useless signal.
  BUY=iRSI(NULL,60,3,PRICE_CLOSE,1)-iRSI(NULL,60,12,PRICE_CLOSE,1);  //If it crosses at for example 7:38 I want to buy at 8:00 but the ea buys at 9:00
  if (( BUY > 1) && !opened ){
     opened=1;
     Ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,0,0,clrGreen);//Opening Buy
     }
  else if (( BUY < 1) && opened ){
     opened=0;
     OrderClose(Ticket,0.1,Bid,3,Red);      // Closing Sell          //Same problem here
     }
   }


I tested this on the strategy tester and the problem is that the signal lags i dunno why. Any help would be appreciated.

avatar
Moderator
3418
GumRai 2015.09.21 22:12 #
 
//If it crosses at for example 7:38 I want to buy at 8:00 but the ea buys at 9:00

You are checking the value for the last closed bar on the H1 chart, so it cannot detect a cross at 7:38

At 7:38 it is checking the 6:00 bar 

avatar
5
Ramysh 2015.09.22 14:41 #
 
GumRai:

You are checking the value for the last closed bar on the H1 chart, so it cannot detect a cross at 7:38

At 7:38 it is checking the 6:00 bar 

Thanks man.

To whom it might concern. Reading at the minute and second zero will get the last RSI reading immediately. Maybe there is a more efficient way but this is how i solved my problem.

if (Hour0 == TimeHour(TimeCurrent())) return;
        Hour0 = TimeHour(TimeCurrent());
     {
     iRSI(NULL,60,3,PRICE_OPEN,0)   //This will get you the reading at the beginning of the hour
     }


The first 2 lines I got from WHRoeder.

Back to topics list  

To add comments, please log in or register