Flag when 2-MA crosses

 

My EA is still under development and I having trouble to simplified 1 of the process.

I was watching for 2 Moving Average to cross, SMA 2500 and SMA 3000. After the 2 MA crosses, I would like to trade on the first tick that reach the lowest or the highest MA line which can take quite some time, from hours to days in 5 minutes chart. Is it possible to flag the crosses, and wait for the tick to reach the MA without having to process each tick?

From what I understand (correct me if I'm wrong), EA usually run the function every moment there's a tick, and in case the crosses happened days before, the system will require some times to retrace back the crosses.

Back to the main question, is it possible to flag the crosses and wait for the next tick to touch then execute the order? without having to reiterate one by one? Thanks for any advise

 

If you are going to trade when the price touches one of the MA's all you need to know is where the MA's are now and which one is above the other.

 
SDC:

If you are going to trade when the price touches one of the MA's all you need to know is where the MA's are now and which one is above the other.


My issue right now is, if the price touch let say the higher MA, if possible, I don't want the program to run and check whether it is the first touch or not since the MA crosses. I would like to have a flag that say it is the first touch since the crosses. and ignore any other touch followed after that. Is it possible?

 

without processing each tick it will not be possible, but generally yes.

Insert a flag into your code, after the cross happens set the flag to true, and on the first touch put the signal and set the flag to false.

after the signal happend, you don't need to track every anymore, you will only have to look at the crosses.

//z

 
bleach77:


My issue right now is, if the price touch let say the higher MA, if possible, I don't want the program to run and check whether it is the first touch or not since the MA crosses. I would like to have a flag that say it is the first touch since the crosses. and ignore any other touch followed after that. Is it possible?

Anything is possible. Just code it to allow one trade between crosses
start(){
   static bool tradeAllowed = true;
   double ma.f  = ima(NULL,0,f.len,...,0),
          ma.f.p= ima(NULL,0,f.len,...,1),
          ma.s  = ima(NULL,0,s.len,...,0),
          ma.s.p= ima(NULL,0,s.len,...,1);
   bool cross = (ma.f-ma.s)*(ma.f.p-ma.s.p) < 0;
   if (cross) tradeAllowed = true;
   if (tradeAllowed && Bid >= ma.f && Open[0] < ma.f){ 
      tradeAllowed = false;
      orderSend(OP_BUY, ...
 
bleach77:

My EA is still under development and I having trouble to simplified 1 of the process.

I was watching for 2 Moving Average to cross, SMA 2500 and SMA 3000. After the 2 MA crosses, I would like to trade on the first tick that reach the lowest or the highest MA line which can take quite some time, from hours to days in 5 minutes chart. Is it possible to flag the crosses, and wait for the tick to reach the MA without having to process each tick?

From what I understand (correct me if I'm wrong), EA usually run the function every moment there's a tick, and in case the crosses happened days before, the system will require some times to retrace back the crosses.

Back to the main question, is it possible to flag the crosses and wait for the next tick to touch then execute the order? without having to reiterate one by one? Thanks for any advise


it is also easy to use a variable outside of start(). so set a bool outside of start() and change it if(Cross) or if(Touch)
 

Thanks for all the reply.

zzuegg : I was thinking more on how to put a flag. :)

WHRoeder: As per example, how can I retain the tradeAllowed value for the next tick? I believe in each tick they will reset the variable value.

bool tradeAllowed;
 start(){
   if (tradeAllowed = true) {
	......
	......  	
	}
   else {
   	double ma.f  = ima(NULL,0,f.len,...,0),
          	ma.f.p= ima(NULL,0,f.len,...,1),
          	ma.s  = ima(NULL,0,s.len,...,0),
          	ma.s.p= ima(NULL,0,s.len,...,1);
   	bool cross = (ma.f-ma.s)*(ma.f.p-ma.s.p) < 0;
   	if (cross) tradeAllowed = true;
	}
 

bleach77:

WHRoeder: As per example, how can I retain the tradeAllowed value for the next tick? I believe in each tick they will reset the variable value.

Either put it outside the function, or make it static inside.
Reason: