Consecutive ‘and’ statements
Forums › ProRealTime English forum › ProOrder support › Consecutive ‘and’ statements
- This topic has 10 replies, 3 voices, and was last updated 4 years ago by
Mike Boorman.
-
-
07/06/2021 at 6:52 PM #173245
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?
Sample code1234567891011121314151617181920212223242526272829303132333435363738DEFPARAM CumulateOrders = Falseback=30longhihgerlow2=0CurLow2 = lowest[back/2](low)IF low = CurLow2 THENCurMACD2 = MACD[12,26,9](close)PriorLow2 = lowest[back/2](low[back/2])//goes back twice and finds lowestFOR i = 0 TO (back/2 - 1)//i is how many extra bars beyond [back] it goes backIF low[i + back/2] = PriorLow2 THENPriorMACD2 = MACD[12,26,9](close)[i + back/2]PriorBAR = BarIndex[i + back]BreakENDIFNEXTENDIFosmaconf= 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 < PriorMACD2IF 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 THENlonghigherlow2=1endifif not onmarket and longhigherlow2=1 thensl=max(5,AverageTrueRange[14](close))tp= sl*2Set target profit tpSet stop loss slBUY 1 PERPOINT AT MARKETlonghigherlow2=0endifgraph stochconf07/06/2021 at 8:14 PM #173253Try replacing line 26 with:
12345678c1 = Curlow2 > PriorLow2c2 = Curlow2 = lowest[3](low)c3 = close > openc4 = close > ExponentialAverage[5](low)c5 = close < ExponentialAverage[5](high)c6 = macconf2 and osmaconf and stochconfCond = c1 and c2 and c3 and c4 and c5 and c6IF Cond THENyou should be able to better spot any logical issue.
1 user thanked author for this post.
07/06/2021 at 10:50 PM #173263This gives me the same result. I can’t understand why it is entering with false conditions. This is what the code looks like now:
Sample code1234567891011121314151617181920212223242526272829303132333435363738394041424344DEFPARAM CumulateOrders = Falseback=30longhihgerlow2=0CurLow2 = lowest[back/2](low)IF low = CurLow2 THENCurMACD2 = MACD[12,26,9](close)PriorLow2 = lowest[back/2](low[back/2])//goes back twice and finds lowestFOR i = 0 TO (back/2 - 1)//i is how many extra bars beyond [back] it goes backIF low[i + back/2] = PriorLow2 THENPriorMACD2 = MACD[12,26,9](close)[i + back/2]PriorBAR = BarIndex[i + back]BreakENDIFNEXTENDIFosmaconf= 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 < PriorMACD2c1 = Curlow2 > PriorLow2c2 = Curlow2 = lowest[3](low)c3 = close > openc4 = close > ExponentialAverage[5](low)c5 = close < ExponentialAverage[5](high)c6 = macconf2 and osmaconf and stochconfCond = c1 and c2 and c3 and c4 and c5 and c6IF Cond THENlonghigherlow2=1endifif not onmarket and longhigherlow2=1 thensl=max(5,AverageTrueRange[14](close))tp= sl*2Set target profit tpSet stop loss slBUY 1 PERPOINT AT MARKETlonghigherlow2=0endif07/06/2021 at 11:06 PM #173264At 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.
07/06/2021 at 11:39 PM #173265Thanks 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 🙁
07/07/2021 at 8:58 AM #173272What were the TF and asset/instrument that you used in your pic above?
07/07/2021 at 10:27 AM #173277It’s EUR USD, 5 minute chart.
07/07/2021 at 11:57 AM #173288This works (after adding PIPSIZE conversion to the calculation of the SL):
12345678910111213141516c1 = Curlow2 > PriorLow2c2 = Curlow2 = lowest[3](low)c3 = close > openc4 = close > ExponentialAverage[5](low)c5 = close < ExponentialAverage[5](high)c6 = macconf2 and osmaconf and stochconflonghigherlow2 = c1 and c2 and c3 and c4 and c5 and c6if not onmarket and longhigherlow2=1 thensl=max(5*pipsize,AverageTrueRange[14](close))tp= sl*2Set target profit tpSet stop loss slBUY 1 PERPOINT AT MARKETlonghigherlow2=0endifI 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.
2 users thanked author for this post.
07/07/2021 at 12:49 PM #17329107/07/2021 at 2:52 PM #17329607/07/2021 at 4:08 PM #173301Yes, this now works.
Thank you very much Roberto! 🙂
-
AuthorPosts
