Hello folks,
I think someone with a bit more expertise than me will find this easy…
I’m getting a rogue entry at 11:35 (see screengrab). I’ve graphed stochconf which is correctly false at 11:35, and yet it still enters. I suspect this is something to do with all of the consecutive ‘and’ statements, but I’ve tried juggling things around and still can’t stop it entering at 11:35 when not all of the entry rules are true.
Does anyone know how I can solve this?
DEFPARAM CumulateOrders = False
back=30
longhihgerlow2=0
CurLow2 = lowest[back/2](low)
IF low = CurLow2 THEN
CurMACD2 = MACD[12,26,9](close)
PriorLow2 = lowest[back/2](low[back/2])//goes back twice and finds lowest
FOR i = 0 TO (back/2 - 1)
//i is how many extra bars beyond [back] it goes back
IF low[i + back/2] = PriorLow2 THEN
PriorMACD2 = MACD[12,26,9](close)[i + back/2]
PriorBAR = BarIndex[i + back]
Break
ENDIF
NEXT
ENDIF
osmaconf= MACD[12,26,9](close) > MACD[12,26,9](close)[1]
stochconf=Stochastic[14,3](close) <40 and Stochastic[14,3](close)> Stochastic[14,3](close)[1]
macconf2= CurMACD2 < PriorMACD2
IF Curlow2 > PriorLow2 and Curlow2 =lowest[3](low) and close > open and close > ExponentialAverage[5](low) and close < ExponentialAverage[5](high) and macconf2 and osmaconf and stochconf THEN
longhigherlow2=1
endif
if not onmarket and longhigherlow2=1 then
sl=max(5,AverageTrueRange[14](close))
tp= sl*2
Set target profit tp
Set stop loss sl
BUY 1 PERPOINT AT MARKET
longhigherlow2=0
endif
graph stochconf
Try replacing line 26 with:
c1 = Curlow2 > PriorLow2
c2 = Curlow2 = lowest[3](low)
c3 = close > open
c4 = close > ExponentialAverage[5](low)
c5 = close < ExponentialAverage[5](high)
c6 = macconf2 and osmaconf and stochconf
Cond = c1 and c2 and c3 and c4 and c5 and c6
IF Cond THEN
you should be able to better spot any logical issue.
This gives me the same result. I can’t understand why it is entering with false conditions. This is what the code looks like now:
DEFPARAM CumulateOrders = False
back=30
longhihgerlow2=0
CurLow2 = lowest[back/2](low)
IF low = CurLow2 THEN
CurMACD2 = MACD[12,26,9](close)
PriorLow2 = lowest[back/2](low[back/2])//goes back twice and finds lowest
FOR i = 0 TO (back/2 - 1)
//i is how many extra bars beyond [back] it goes back
IF low[i + back/2] = PriorLow2 THEN
PriorMACD2 = MACD[12,26,9](close)[i + back/2]
PriorBAR = BarIndex[i + back]
Break
ENDIF
NEXT
ENDIF
osmaconf= MACD[12,26,9](close) > MACD[12,26,9](close)[1]
stochconf=Stochastic[14,3](close) <40 and Stochastic[14,3](close)> Stochastic[14,3](close)[1]
macconf2= CurMACD2 < PriorMACD2
c1 = Curlow2 > PriorLow2
c2 = Curlow2 = lowest[3](low)
c3 = close > open
c4 = close > ExponentialAverage[5](low)
c5 = close < ExponentialAverage[5](high)
c6 = macconf2 and osmaconf and stochconf
Cond = c1 and c2 and c3 and c4 and c5 and c6
IF Cond THEN
longhigherlow2=1
endif
if not onmarket and longhigherlow2=1 then
sl=max(5,AverageTrueRange[14](close))
tp= sl*2
Set target profit tp
Set stop loss sl
BUY 1 PERPOINT AT MARKET
longhigherlow2=0
endif
At line 27 you change the value CurLow2 was assigned at line 7, besides changing it just after checking it at line 26.
I don’t know if this is made on purpose or not.
Thanks for the suggestion.
I didn’t want to change the variable there – that is a good point – I just wanted to say “Curlow 2 needs to be the lowest of the last three bars in order for there to be an entry”.
But I’ve removed the whole of line 27 and deleted C2, and I still get the same wrong entry, so that isn’t the problem.
I’m struggling 🙁
What were the TF and asset/instrument that you used in your pic above?
It’s EUR USD, 5 minute chart.
This works (after adding PIPSIZE conversion to the calculation of the SL):
c1 = Curlow2 > PriorLow2
c2 = Curlow2 = lowest[3](low)
c3 = close > open
c4 = close > ExponentialAverage[5](low)
c5 = close < ExponentialAverage[5](high)
c6 = macconf2 and osmaconf and stochconf
longhigherlow2 = c1 and c2 and c3 and c4 and c5 and c6
if not onmarket and longhigherlow2=1 then
sl=max(5*pipsize,AverageTrueRange[14](close))
tp= sl*2
Set target profit tp
Set stop loss sl
BUY 1 PERPOINT AT MARKET
longhigherlow2=0
endif
I can’t exactly tell you why. I can only guess it doesn’t like too many AND’s on a single line PLUS it doesn’t like both Cond and longhigherlow2 sharing the same logical value.
Someone got a working itf and backtest?
Yes, this now works.
Thank you very much Roberto! 🙂