I would store the condition in three (four) variables, like:
double h = iHigh(Symbol(),PERIOD_CURRENT,0)<iLow(Symbol(),PERIOD_CURRENT,1), l = iLow(Symbol(),PERIOD_CURRENT,1); bool cond_1 = (MA3<MA1) && (MA3<MA2) && (MA4<MA1) && (MA4<MA2), cond_2 = RSI<30, cond_3 = h<l cond_4 = cond_1 && cond_2 && cond_3;
and track them either in the debugger or - in case if visual testing - show them in the Comment();
... condition 3. I want my EA to recognize that when a candlestick closes with a high that is lower than the low of the previous candlestick ...
The key here is that you wrote "when it closes", but the candle at index 0 is the CURRENT UN-CLOSED candle bar. When it closes it becomes the candle at index 1.
So instead of comparing candle [0] and candle [1], you should be comparing candle [1] with candle [2].
if( High[1] < Low[2] ) { ... } // "High[1]" is the same as "iHigh(Symbol(),PERIOD_CURRENT,1)" // "Low[2]" is the same as "iLow( Symbol(),PERIOD_CURRENT,2)"
The same applies to the Moving Averages, you should be looking at the closed candle [1] and not on the current candle [0]. However, you seem to be using a different TimeFrame (namely M5) for the Moving Averages - is that correct?
Also, be careful how you calculate the stop-loss where you might have to look at both candle [0] and candle [1] to get the lowest of the two.
Thanks a lot for your suggestions. Do you happen to know these details are explained more thoroughly? The explanation in the reference manual does not mention the information you gave me. The different Timeframe for the MA's is used to detect whether there is a upwards trend, and M5 is more suitable for that.
Thanks a lot for your suggestions. Do you happen to know these details are explained more thoroughly? The explanation in the reference manual does not mention the information you gave me. The different Timeframe for the MA's is used to detect whether there is a upwards trend, and M5 is more suitable for that.
The information I gave you is originally from the documentation. I just gave you a concise aggregated explanation of information originally scattered among the various elements involved.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey all!
I recently started programming my very first EA. It may look a little confusing at first but i hope it is readable. Th reason for this post is that i have encountered a problem. It comes down to this. I want to execute a buy order once 3 requirement are met.
The problem here is that my EA is not accurately assessing condition 3. I want my EA to recognize that when a candlestick closes with a high that is lower than the low of the previous candlestick, it is supposed to send in an order. However, when the described situation arose in a test the EA did not recognize it as such. See the picture attached for a clearer example. Any advice on what is going wrong here? Again, i apologize for the mess that is my code.
Thanks in advance!