maColLen = maColLen * (maCol = maCol[1]) + 1 is working differently PRT 11/10

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #159781 quote
    Daniele Maddaluno
    Participant
    Master

    I was just writing this simple code, and I noticed that it’s working differently in PRT v10 and v11 (“LMAX v10.3 – 1.8._202” and “IG v11.1 – 1.8._202”).
    On v11 I am getting the expected behaviour, on v10 it’s odd…

    // Settings
    once maLen = 20
    once maType = 1
    
    // Indicators
    ma = Average[maLen, maType](close)
    
    // Color of ma line
    if(ma > ma[1]) then
       maCol = +1
    elsif(ma < ma[1]) then
       maCol = -1
    else
       maCol = maCol[1]
    endif
    
    // this variable should give me the distance from the last changement of color
    maColLen = maColLen * (maCol = maCol[1]) + 1
    
    return maColLen, maCol

    The problem is with the “maColLen”, on v10 is always undefined, on v11 it works as I expected…

    At first I thought that it was “(maCol = maCol[1])” considered as a boolean and not as a 0/1 as it normally should and could not work as it should.
    But I tried this other small piece of code and I understood that it’s not the case, because this is working good on both v10 and v11:

    barCol = +1 * (close > open) -1 * (close < open) + barCol * (close = open)

    So I think that the problem is linked to the “maCol[1]” inside of the “(maCol = maCol[1])”.
    Or maybe it’s me that I have misunderstood something…
    I would like to have a clearer understanding of this at a low level.
    Thank you in advance.

    #159785 quote
    robertogozzi
    Moderator
    Master

    Try initialising it:

    ONCE maColLen = 0 //or any other value
    #159788 quote
    Daniele Maddaluno
    Participant
    Master

    Yeah, I tried that too (just above the maColLen = maColLen * (maCol = maCol[1]) + 1), but it’s always undefined.

    #159810 quote
    robertogozzi
    Moderator
    Master

    Add:

    if BarIndex > maLen then

    at line 4, then ENDIF at line 19.

    #159834 quote
    Daniele Maddaluno
    Participant
    Master

    Thank you for the correction proposal to make it works.
    Ok it works now… And I can understand the correction.

    // Settings
    once maLen = 20
    once maType = 1
    
    if barindex > maLen then
       // Indicators
       ma = Average[maLen, maType](close)
     
       // Color of ma line
       if(ma > ma[1]) then
          maCol = +1
       elsif(ma < ma[1]) then
          maCol = -1
       else
          maCol = 0
       endif
     
       // this variable should give me the distance from the last changement of color
       maColLen = maColLen * (maCol = maCol[1]) + 1
    endif
    return maColLen, maCol

    But I still don’t completely get why they reacted differently.
    So I have done some research on that and now I think i’m getting closer at why at low level it’s working differently.

    Fact 1:

    PRT 10 and 11 behaves completely differently when it comes to compare a value with the undefined.

    myvar = undefined
    return myvar = 4

    This is returning undefined on PRT v10 and zero on PRT v11

     

    Fact 2:

    A simple variable as maColLen by default (if not used with a function like average on the right of assignement) is 0, and you can prove that with that indicator (which returns 0 both on PRT 10 and 11):

    myVar = myVar
    return myVar

     

    Fact 3:

    A simple variable as maCol if it’s set equals to maCol[1] on first bars will give you undefined (both on 10 an 11):

    myVar = myVar[1]
    return myVar

     

    So now that I have those fact in mind we have three cases:

    • bars < 20
      • ma is undefined
      • maCol is undefined (for fact 3, for the else line of ma color)
      • so maColLen = maColLen * (maCol = maCol[1]) + 1 —> maColLen = 0 * (undefined) + 1   on PRT 10 and    maColLen = 0 * (0) + 1  on PRT 11
    • bars = 20
      • ma is a value but ma[1] is not a value
      • maCol is undefined (for fact 3, for the else line of ma color)
      • so maColLen = maColLen * (maCol = maCol[1]) + 1 —> maColLen = 0 * (undefined) + 1   on PRT 10 and    maColLen = 0 * (0) + 1  on PRT 11
    • bars > 20
      • ma and ma[1] is a value
      • maCol is a value +1, -1 (i’ll not consider the ema to be flat between bar 20 and 21)
      • so maColLen = maColLen * (maCol = maCol[1]) + 1 —> maColLen = 0 * (a value) + 1   —> why at this point PRT 10 should not work? I don’t get this…

    Is this all correct? Or I’m wrong at a certain step?
    I’m not getting why PRT 10 is not giving values… i.e. why on the bulleted list above “bars > 20”, point third is still not working on v10.
    I just wish I had a better understanding of what’s going on.
    Thanks again for your patience.

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

maColLen = maColLen * (maCol = maCol[1]) + 1 is working differently PRT 11/10


ProBuilder support

New Reply
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Daniele Maddaluno
5 years ago.

Topic Details
Forum: ProBuilder support
Language: English
Started: 01/29/2021
Status: Active
Attachments: No files
Logo Logo
Loading...