How do I hold a value for X intervals?

 

I am just starting to code and I have review several examples of operational EA. However nothing that I have reviewed seem to help me with this problem. Based on indicators I am seeing a possible trade. I would like to keep the possibility of the trade open for a certain number of intervals. The trade will be executing based on a secondary indicator, if it occurs with in the allotted time. If the secondary indicator does not occur the EA should go back to normal mode of operations.

Setting up the possibility of the trade is easy, how do I keep the value for a certain amount of tick/intervals.

Say for instance:

if(MA1>MA2) {

possible_buy=1 ;

}

Then at some at some future time:

if(MA1>MA3 && possible_buy ==1){

real_buy=1;

}

I hope this is clear as English is not my first language.

MM

 

Try keeping track of the time:

if(MA1>MA2) {

possible_buy_time=TimeCurrent();

}


if(MA1>MA3 && (TimeCurrent()-possible_buy_time)>some_value){

real_buy=1;

}

You would probably need a few more flags/criteria to reset the values if the "real_buy" doesn't happen for whatever reason with the X intervals.

 

If I understand correctly :

if(MA1>MA2) {

hold_time=(TimeCurrent()+15); // for 15 seconds

possible_buy=1; // Not needed for the equation but could be used as additional flag

}

if(MA1>MA3 && (TimeCurrent()>=hold_time) && possible_buy==1){

real_buy=1;

}

I would only need define hold time as an additional variable.

int hold_time =0 ;

After the time has passed the allotted X units then the logic of the MA1>MA3 conditional would be false and no real buy would occur.

Do you seen any errors?

Thank you for your response.