EBParticipant
Senior
Hi,
I am struggling with a code for some time. It seems to work for some cases, but strange enough not all of the times during the backtest.
I am trying to code the following:
c1 = Moving average 20 > Moving average 50
c2 = Stochastic close [1] < 21 and stochastic close [0] >= 21
c3 = abs(bollingerup close[0] – abs(bollowingerdown close[0])>1
the combination of c1, c2 and c3 is reguired to buy a contract. Attached a screenshot of the graph with a example where I should expect a trade opening and a screenshot of the code.
As a test I changed c1, c2 and c3 variables and each time the result shows different results, so apparently all conditions seems to work.
Could please somebody take a look and see what I am doing wrong? Why does it generate trades, but not for all the situations, when c1, c2 and c3 are valid?
Thank you!
EBParticipant
Senior
c1 = (Average[20](close[0]) > Average[50](close[0]))
c2 = (Stochastic[5,3](close[1]) < 21 and Stochastic[5,3](close[0])>= 21)
c3= abs(BollingerUp[20](close[0]) - BollingerDown[20](close[0]))> 1
IF (c1 and c2 and c3) THEN
BUY 1 CONTRACT AT MARKET
SET STOP LOSS 0.7
SET TARGET PROFIT 1.0
ENDIF
You can GRAPH your 3 conditions on the chart while doing your backtest, this is how you should debug your problem:
c1 = (Average[20](close[0]) > Average[50](close[0]))
c2 = (Stochastic[5,3](close[1]) < 21 and Stochastic[5,3](close[0])>= 21)
c3= abs(BollingerUp[20](close[0]) - BollingerDown[20](close[0]))> 1
IF (c1 and c2 and c3) THEN
BUY 1 CONTRACT AT MARKET
SET STOP LOSS 0.7
SET TARGET PROFIT 1.0
ENDIF
signal = c1 and c2 and c3
graph signal
You’ll be able to compare what you expect as a signal and the one your code is actually returning.