Missing data2 error

Questions about MultiCharts and user contributed studies.
RadioactiveToy
Posts: 6
Joined: Jul 03 2020

Jul 26 2024

Hi everyone,

I just I came across a behavior that I had never noticed before using if-then statements.

The scenario is:
Chart with only data1, i add the signal below, and as long as the type is set to 1 it works fine since the line "if type = 2 then value1 = c of data2 ;" is ignored.
Setting type = 2 of course triggers the missing data 2 error, which is the behaviour i would expect.

Then why if i simply uncomment the last line "if type = 3 then value1 = AverageFC(c of data2,20)" , keeping the type = 1, i get the error ?
Isn't this line supposed to be considered and therefore trigger the error message only if type = 3 ?

Code: Select all

input: Type(1); if type = 1 then value1 = c; if type = 2 then value1 = c of data2 ; //if type = 3 then value1 = AverageFC(c of data2,20) ;

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jul 26 2024

Please change AverageFC to regular Average.

Please do not use AverageFC in the future.
AverageFC is a function, not a keyword. It was designed in the early days when CPU computing power was low and this is a shortcut to make calculations faster. It is a shortcut, ie it has limitations.

RadioactiveToy
Posts: 6
Joined: Jul 03 2020

Jul 27 2024

Thanks for the suggestion :wink:

The mov. avg was just an example, the same happens also with other functions (RSI, ADX, MACD... just to name a few), while with others it does not happen, which seems to me a pretty inconsistent behaviour.

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jul 28 2024

Please post your code.

RadioactiveToy
Posts: 6
Joined: Jul 03 2020

Jul 29 2024

It's basically the same as above with a few more attempts with other indicators/functions.
The commented ones trigger the error message, all those uncommented works fine.

Code: Select all

var: Type(1); //NO ERROR if type = 1 then value1 = c; if type = 2 then value1 = c of data2 ; if type = 10 then value1 = Average(c of data2,20) ; if type = 11 then value1 = BollingerBand(c of data2,20,1) ; if type = 12 then value1 = Momentum(c of data2,20) ; if type = 13 then value1 = RateOfChange(c of data2,20) ; //ERROR //if type = 3 then value1 = AverageFC(c of data2,20) ; //if type = 4 then value1 = RSI(c of data2,14) ; //if type = 5 then value1 = MACD(c of data2,10,20) ; //if type = 6 then value1 = ADX(20) of data2; //if type = 7 then value1 = HighS(1) of data2 ; //if type = 8 then value1 = averagetruerange(20) of data2 ; //if type = 9 then value1 = CCI(20) of data2;

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jul 29 2024

See Post #5
Data2
viewtopic.php?t=6929

RadioactiveToy
Posts: 6
Joined: Jul 03 2020

Aug 01 2024

Let's overlook my limited programming skills, which don't affect the outcome of the test anyway.

I'll rephrase my question:
If a specific line is disabled via input, why does MC sometimes attempt to calculate its values? I would assume this was by design if it always happened, but since it seems pretty random, it looks very strange and suspicious.

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Aug 06 2024

OK, I got your question now.
You want to use an indicator written for 2 data streams and apply it to a single data stream.
No, that will generate an error message.

RadioactiveToy
Posts: 6
Joined: Jul 03 2020

Aug 07 2024

No, my question is different.

Why does the first code below generate an error when applied to a single data stream chart, while the second one does not? Besides the different function, both call for a second data stream with a condition set to false.

Either MC should give an error in both cases or in neither, and I would expect the latter being the condition set to false.

Code: Select all

condition1 = false; if condition1 = true then value1 = averagetruerange(20) of data2 ;

Code: Select all

condition1 = false; if condition1 = true then value1 = Average(c of data2,20) ;

PeterSt
Posts: 31
Joined: Jun 18 2024
Has thanked: 5 times
Been thanked: 11 times

Aug 07 2024

Did you sort out whether (regular) MC evaluates from left to right ? ... this is regarding your last post. It may not be relevant.
For your original post, I'd say this looks like a parser error (PowerLanguage would be a by MC home-made interpreter which under the hood will translate to some real programming language - just guessing).

"Parser error" could just be protective behavior. I mean, the parser could pre-scan all of your code and detects the Data streams you refer to, but it won't be able to really execute. It thus would not know about the state/content of your Condition1 or Type variable, but it may protect you from running into the situation that Type etc. gets the value that will refer to Data2 while Data2 is not present.
If I am right to begin with, the situation will be solved by means of putting "Data2" itself in a variable. But looking at your examples, it seems that PL can not do this ? (in the .Net version the Data stream is just a number and it can be put in a variable - now any parser would not be able to detect it)

Of course this is for MC to judge ... including how to possibly work around it (which would not be "take out that code").