Consecutive ‘and’ statements

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #173245 quote
    Mike BoormanMike Boorman
    Participant
    Average

    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
    
    Screen-Shot-2021-07-06-at-19.43.06.png Screen-Shot-2021-07-06-at-19.43.06.png
    #173253 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    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.

    Mike Boorman thanked this post
    #173263 quote
    Mike BoormanMike Boorman
    Participant
    Average

    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
    #173264 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    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.

    #173265 quote
    Mike BoormanMike Boorman
    Participant
    Average

    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 🙁

    #173272 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    What were the TF and asset/instrument that you used in your pic above?

    #173277 quote
    Mike BoormanMike Boorman
    Participant
    Average

    It’s EUR USD, 5 minute chart.

    #173288 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    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.

    Mike Boorman and Midlanddave thanked this post
    #173291 quote
    murre87murre87
    Participant
    Senior

    Someone got a working itf and backtest?

    #173296 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    MySystem.itf
    #173301 quote
    Mike BoormanMike Boorman
    Participant
    Average

    Yes, this now works.

    Thank you very much Roberto! 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Consecutive ‘and’ statements


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by Mike BoormanMike Boorman
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/06/2021
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...