How to make the EA take action once when the condition happen.

 

This is my first time here writing about something I stopped out with , and sorry if my English is Poor but I will try to explain much as I can, and I will appreciate if you help me.

So I tried to make a simple cross over EA based on multiple EMAs

and I come up with this code for crossing 

if((sma5[1]>sma8[1]) && (sma8[1]>sma13[1]) && (sma13[1]>sma100[1]))
{
         SL_pips = _atrstop*2;
         signal = "buy";
        Comment(signal);
}

so without the deep details it's works fine but with simple problem , when the condition become true , it take buy trade just fine and even close it based on on strategy , whether its losing trade or wining trade , but the problem the EA Keep taking trade as long the condition remain true , so I tried this code , to make it take action only once when the condition happens.

if((sma5[1]>sma8[1]) && (sma8[1]>sma13[1]) && (sma13[1]>sma100[1]))
      if((sma5[0]<sma8[0]) && (sma8[0]<sma13[0]) && (sma13[0]<sma100[0]))
      if(_sma250Value < Bid){
         SL_pips = _atrstop*2;
         signal = "buy";
         Comment(signal);
      }

I tried this but I face another problem , that The EA will not take any trade because the huge difference between the periods of Moving averages, I hope you understand what I try to explain

So my question is : How to make the EA take the Action once when the condition happen and wait for it happen again to take action again , not take action always as the condition remain true.

I will be happy and appreciate if you can help me.

thank you already.  
 

 
Edward Anderson the EA take the Action once when the condition happen and wait for it happen again to take action again 

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

 
William Roeder:

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

Thank you I will try to read this topic , but is it the same as MQL 5