Rank: Member
Groups: Registered Users, Subscribers, Unverified Users Joined: 3/7/2017(UTC) Posts: 10
|
Hello,
Below I want to access the strat4 value which changes after I change it. Is there a way to initialize the variable once. pvtval:= If(C>Ref(SA,-25) AND (C>Ref(SB,-25)),1,0) and (Ref(strat4,-1)),1,0);
strat4=close;
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
|
|
|
|
Rank: Member
Groups: Registered Users, Subscribers, Unverified Users Joined: 3/7/2017(UTC) Posts: 10
|
Hello,
I have something like the following:
pvtval:= If(C>Ref(SA,-25) AND (C>Ref(SB,-25)),1,0) and (Ref(strat4,-1)),1,0);
strat4=close;
Pvtval references the variable strat4 which is declared afterwards. As a result, it gives an error. Normally, if you initialize it on startup only, this would not happen.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
I still don't understand the issue: if you need to reference some variable "strat4" then it must be declared beforehand; you can re-use the variable later in the code. Remember though that MSFL scripts are fully evaluated for every bar (and lots has already been written about that).
Code:
SA:={something};
SB:={something}
strat4:={something}
pvtval:= If(C>Ref(SA,-25) AND (C>Ref(SB,-25)),1,0) and (Ref(strat4,-1)),1,0);
strat4=close; {re-use the variable}
{ do something else with the variable, strat4 (close) }
Check your ptval logic too... if all your conditions have to be TRUE for ptval to equal 1 (TRUE) then:
Code:
pvtval:= C>Ref(SA,-25) AND C>Ref(SB,-25) and Ref(strat4,-1);
|
|
|
|
Rank: Member
Groups: Registered Users, Subscribers, Unverified Users Joined: 3/7/2017(UTC) Posts: 10
|
ok...in the example you showed....
for the first bar...it initialize strat4.
In the second bar....does it execute strat4:=(something) again? if not...I am good then
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
To understand how MS interprets your code: For each bar, read the code from the top of the script to the bottom. If you said x=1 at the top of the script, and later in the script said x=2; on the next bar, as the script is being processed from top to bottom, x would equal 1 as there is no memory that x was 2 on the previous bar.
Each line of script is executed for each bar on the chart.
This is why there is a PREV function, it handles the situation when a (self) value has to be passed from bar to bar; and why PREV is so slow.
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.