Limiting trading time to x value of time after event occur.

 

Hi,

I want to check for entry price only within(let say 6 hours (21600seconds)) after MA cross.

int start()
   {
     // Moving averages
     double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
     double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
     double LastFastMA = iMA(NULL,0,FastMAPeriod,0,1,0,1);
     double LastSlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,1);
     //remember cross time in global variable "datetime TS;"
     if(FastMA > SlowMA && LastFastMA <= LastSlowMA || FastMA < SlowMA && LastFastMA >= LastSlowMA) datetime TS = TimeCurrent(); // or Time[0];??

     //Check for entry price in 6 hours period from cross happening only.     
     datetime CurrentTime = TimeCurrent();
     datetime StartTime = TS;
     datetime EndTime = TS + 21600;
     // Check for trade condition
     if(StartTime <= CurrentTime && EndTime > CurrentTime) 
              {
                     bool TradeAllowed = true;  
              }
     else TradeAllowed = false;
 

How to remeber TimeStamp of the event (MA cross)? I've tried setting TS and comparing it as u can see. But that does not work for me.  

Regards 

 
Sirru82:

Hi,

I want to check for entry price only within(let say 6 hours (21600seconds)) after MA cross.

 

How to remeber TimeStamp of the event (MA cross)? I've tried setting TS and comparing it as u can see. But that does not work for me.  

Try making TS a globally declared variable or static.
 

I did it, that makes sense. But still something wrong i think maybe with comparing times,signal...I rethink it again. thx. 

RaptorUK:
Try making TS a globally declared variable or static.

// Global variables
int BuyTicket;
int SellTicket;

double UsePoint;
int UseSlippage;

int ErrorCode;
static datetime TS;


// Start function
int start()
   {
     // Moving averages 
     double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
     double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
     double LastFastMA = iMA(NULL,0,FastMAPeriod,0,1,0,1);
     double LastSlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,1);
     //setting cross time and remembering it in global variable datetime CT.
     if(FastMA > SlowMA && LastFastMA <= LastSlowMA || FastMA < SlowMA && LastFastMA >= LastSlowMA)  TS = TimeCurrent();
     //Check for entry price in 6 hours period from cross happening only.
     
     datetime CurrentTime = TimeCurrent();
     datetime StartTime = TS;
     datetime EndTime = TS + 21600;
     // Check for trade condition
     if(StartTime <= CurrentTime && EndTime > CurrentTime) 
              {
                     bool TradeAllowed = true;  
              }
     else TradeAllowed = false;
Reason: