maColLen = maColLen * (maCol = maCol[1]) + 1 is working differently PRT 11/10
Forums › ProRealTime English forum › ProBuilder support › maColLen = maColLen * (maCol = maCol[1]) + 1 is working differently PRT 11/10
- This topic has 4 replies, 2 voices, and was last updated 3 years ago by Daniele Maddaluno.
-
-
01/29/2021 at 11:08 AM #159781
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…maColLen update1234567891011121314151617181920// Settingsonce maLen = 20once maType = 1// Indicatorsma = Average[maLen, maType](close)// Color of ma lineif(ma > ma[1]) thenmaCol = +1elsif(ma < ma[1]) thenmaCol = -1elsemaCol = maCol[1]endif// this variable should give me the distance from the last changement of colormaColLen = maColLen * (maCol = maCol[1]) + 1return maColLen, maColThe 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:BarColor1barCol = +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.01/29/2021 at 11:17 AM #159785Try initialising it:
1ONCE maColLen = 0 //or any other value01/29/2021 at 11:27 AM #159788Yeah, I tried that too (just above the maColLen = maColLen * (maCol = maCol[1]) + 1), but it’s always undefined.
01/29/2021 at 12:27 PM #159810Add:
1if BarIndex > maLen thenat line 4, then ENDIF at line 19.
01/29/2021 at 1:47 PM #159834Thank you for the correction proposal to make it works.
Ok it works now… And I can understand the correction.123456789101112131415161718192021// Settingsonce maLen = 20once maType = 1if barindex > maLen then// Indicatorsma = Average[maLen, maType](close)// Color of ma lineif(ma > ma[1]) thenmaCol = +1elsif(ma < ma[1]) thenmaCol = -1elsemaCol = 0endif// this variable should give me the distance from the last changement of colormaColLen = maColLen * (maCol = maCol[1]) + 1endifreturn maColLen, maColBut 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.
12myvar = undefinedreturn myvar = 4This 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):
12myVar = myVarreturn myVarFact 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):
12myVar = myVar[1]return myVarSo 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. - bars < 20
-
AuthorPosts
Find exclusive trading pro-tools on