Intrabarpersist variables and intrabar order generation  [SOLVED]

Questions about MultiCharts and user contributed studies.
tozwp
Posts: 145
Joined: 15 Apr 2011
Has thanked: 16 times
Been thanked: 8 times

Intrabarpersist variables and intrabar order generation

Postby tozwp » 05 Jun 2014

On a strategy that uses two time frames, data1 is 5 minute and data2 is 60 minute. Trade entry rules are based on indicator on data1, let's say rsi and two moving averages on data2. Entry price is based on the high of the stick in data2 when all the conditions are met. To check the conditions do I write:

Code: Select all

If Barstatus(1) = 2 and Marketposition <= 0 then VariableRSI = RSI(length)data1;
If Barstatus(2) = 2 and MP <= 0 then begin
ShortMA = Average(c, shortlength) data2;
LongMA = Average(c,longlength) data2;
end;
Do the variables VariableRSI, ShortMA and LongMA need to be declared as intrabarpersist?
For the entry order, would it need to be written like this?

Code: Select all

If Barstatus(1) = 2 and MP <=0 and VariableRSI > Threshold and ShortMA > LongMA and (some price logic for bar price) then begin;
Buy next bar at market;
end;
Confused about intrabarpersist variables. Not sure if when Intrabar Order Generation is turned on whether or not these variable will keep there value from bar to bar without it.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Intrabarpersist variables and intrabar order generation  [SOLVED]

Postby Henry MultiСharts » 05 Jun 2014

Hello tozwp,

Intrabarpersist never resets itself during the script calculation. 
Every "regular" variable will keep its value throughout the whole script calculation on all data series (if the value was assigned on the bar's close) until you assign a different value to it. 
 
The difference between regular variable and IntraBarPersist variable is that regular variable's value is fixed on bar close and IntraBarPersist variable's value is fixed even inside bar. 
 
For example: 
If you assign a value for regular variable inside bar (barstatus=1) - the variable value will not be kept on bar open/close (barstatus=0 and 2). 
If you do the same with intrabarpersist variable-the value will be kept on all barstatus values (0,1,2).


Return to “MultiCharts”