This probably happened on the same candle.
If so, one solution is to remember candle time when the cross is detected and then stop detecting crosses until new candle opens.
This probably happened on the same candle.
If so, one solution is to remember candle time when the cross is detected and then stop detecting crosses until new candle opens.
Thanks Drazen Penic,
and can u guide me what the command is?
Thanks a lot
Define variable and assign time when you detect cross. Something like this:
// define static variable for last cross time static datetime lastCrossTime = 0; // compare lastCrossTime with current candle time // if we did not discovered cross on the current candle (Time[0]) - search for MA crossing if(lastCrossTime < Time[0]) { bool crossDetected = SearchForCross(); // <-- here goes your code for cross detection // check if cross is detected if(crossDetected == true) { // Record that we detected cross on the current candle lastCrossTime = Time[0]; // Open orders or whatever else you do when cross is detected // .... } }
Above code is not tested in compiler. It's just sketch of one possible solution.
Define variable and assign time when you detect cross. Something like this:
Above code is not tested in compiler. It's just sketch of one possible solution.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've build my first EA ,but I've got some problem about it...
I've set my EA to open an order(buy) when MA5 above MA15 and then close the order at tp = 100 points...
the problem is when the order was closed while MA5 still aboved MA15 so my EA opened a new order suddenly. :(
I wanted my EA to open a new order when the next cross up of the MA5 and MA15...
How can i solve this?
Thanks for all the comments :)