Hi. Have been trying to code for the current candle and previous candle(s) being in the direction of my moving averages.
I set up 3 strategies. First strategy was the close of the current candle before opening a trade (c4)
Second strategy was the current candle and the previous candle [1]
Third strategy was the current candle and the 2 previous candles.
In the attachment, you can see the current candle (before opening the trade) was in the direction of the moving averages.
But the previous ones,[1] and [2], were not.
c4 = (close > open)
c5 = (close > open[1])
c6 = (close > open[2])
IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
Trading in demo mode. This did not work (see attachment).
The code was created in the program using simplified creation. So it should work.
What am I doing wrong? Any help greatly appreciated.
Thanks in advance.
Note: I ran all 3 strategies and they all started the trade. Only the current candle (before trade) was correct
Your question is a bit confusing because you left the part about the averages out of it. In your image there are three averages – two going up and one going down!
Your code only compares the close of the current candle to the opening prices of the previous candles. If you want to know if they were red or green then you need to do this:
c4 = summation[3](close > open) = 3 //3 greens
c5 = summation[3](close < open) = 3 //3 reds