"Once" reserved word

Questions about MultiCharts and user contributed studies.
BD.
Posts: 19
Joined: 02 Feb 2024
Has thanked: 2 times
Been thanked: 2 times

"Once" reserved word

Postby BD. » 10 Feb 2024

Why is this behavior happening? "once" setting condition to true then changes reversed back to false by itself, same with numeric variable. It looks like it only happens when "once" condition evaluates to true on the last bar no matter which way - by reserved word or function or bar number.

Code: Select all

vars: cond1(false),cond2(false),cond3(true), val1(0),val2(0); once (LastBarOnChart) begin cond1=true; cond2=true; val2=realBarNumber; end; once (cond1) begin print("I work"); print("cond1: ",cond1," cond2: ",cond2," Bar Num: ",val2); end; if cond1 then print("I still work"); if d=1230323 and t>1415 then print(realBarNumber);

Code: Select all

I work cond1: TRUE cond2: TRUE Bar Num: 15895.00 I still work 15895.00 value: 15895.00 15895.00 value: 0.00 15895.00 value: 0.00 15895.00 value: 0.00 15895.00 value: 0.00 15896.00 value: 0.00

User avatar
Kate MultiCharts
Posts: 597
Joined: 21 Oct 2020
Has thanked: 9 times
Been thanked: 148 times

Re: "Once" reserved word

Postby Kate MultiCharts » 12 Feb 2024

Hello,

Where do you see cond1 change back to false?
The behaviour is not reproduced on our end with the example you posted. The issue might be with your realBarNumber function.

Code: Select all

vars: cond1(false), cond2(false), val2(0); once (LastBarOnChart) begin cond1 = true; cond2 = true; val2 = Symbol_CurrentBar; print(" 1 once ", "cond1: ", cond1, " cond2: ", cond2, " Bar Num: ", val2); end; once (cond1) begin print("I work"); print(" 2 once ", "cond1: ", cond1, " cond2: ", cond2, " Bar Num: ", val2); end; if cond1 then print("I still work"); print(Symbol_CurrentBar);

Code: Select all

1012.00 1013.00 1014.00 1015.00 1 once cond1: TRUE cond2: TRUE Bar Num: 1016.00 I work 2 once cond1: TRUE cond2: TRUE Bar Num: 1016.00 I still work 1016.00 1016.00 1016.00 1016.00

BD.
Posts: 19
Joined: 02 Feb 2024
Has thanked: 2 times
Been thanked: 2 times

Re: "Once" reserved word

Postby BD. » 14 Feb 2024

this happened in SIM trading. I've sent an email with details.

Code: Select all

realBarNumber=BarNumber+MaxBarsBack;


Return to “MultiCharts”