All studies can be cut and paste out to a new study form and compiled clean for use.
Here is a very good test to study.
I left intrabarstatus off for a few items.
it is run on 10 second bars of the e-mini ES
There are three print statements in the study.
The first is a spacer to make it easier to read.
The 2nd and 3rd print statements are exactly the same.
the "BN = BarNumber;" is stuck right in between the 2nd and 3rd prints.
This test tells you several things.
1/ As of 2009/Nov you can not test barstatus = 0 to detect the start of a bar because there is a bug. Instead you have to use time_s compared to its previous value.
2/ When you run it study the BN variables and how the variable during the first tick of a new bar has the old barnumber value until the move command "BN = BarNumber;" takes place. This explains what they mean in the help for the IntraBarPersist command.
3/ It shows that BN and BN[0] are exactly the same thing in memory because the move command "BN = BarNumber;" is only used on BN yet BN[0] gets its value immediately.
4/ Getting back to observation #2 above, notice how the BN is different between the print statements because of the move which is between them. this difference stays the same for every single tick within the bar. However if you put IntraBarPersist on BN it changes and the BN value is only different between the pair of printouts for the first tick. Give it a try (redo it with intrabarpersist and keep both printouts to compare them). This explains what IntraBarPersist does with an actual example.
One more note. Before this test I was thinking that variables without IntraBarPersist get their current bar table value reset to their initial value at the start of the study with each new tick. This test shows their current bar table value gets set to the previous bar's value at the start of the study.
Code: Select all
{A_TestBarNUmber}
var: marker("");
{used in the first study to mark the last tick of the bar in the printout - make it easier to analyse}
var: IntraBarPersist TimePrev(0);
{needed to be sure we have a new bar since BarStatus = 0 is not trustable}
var: BN(0);
{BarNumber, a variable to store bar number across ticks}
{study it in the print out carefully to fully understand how inclusion and exclusion of IntraBarPersist effects your run.}
{In other words run this study once with BN not having IntrabarPersist then run it again with BN having Intrabarpersist and study the differences between the printouts very carefully}
If LastBarOnChart_s then
Begin
marker = "";
If Barstatus = 2 then
marker = "LastTick";
if Time_s > TimePrev then
marker = "FirstTick";
TimePrev = Time_s;
Print( File("C:\ALog_A_BobTestNoIntraBarPersist.txt"),
" ");
Print( File("C:\ALog_A_BobTestNoIntraBarPersist.txt"),
" Barstatus", " " ,
Barstatus , " " ,
" BarNumber", " " ,
BarNumber , " " ,
" BN", " " ,
BN, " " ,
" BN[0]", " " ,
BN[0], " " ,
" BN[1]", " " ,
BN[1], " " ,
" BN[2]", " " ,
BN[2], " " ,
Marker, " " ,
" ");
BN = BarNumber;
Print( File("C:\ALog_A_BobTestNoIntraBarPersist.txt"),
" Barstatus", " " ,
Barstatus , " " ,
" BarNumber", " " ,
BarNumber , " " ,
" BN", " " ,
BN, " " ,
" BN[0]", " " ,
BN[0], " " ,
" BN[1]", " " ,
BN[1], " " ,
" BN[2]", " " ,
BN[2], " " ,
Marker, " " ,
" ");
End; {If LastBarOnChart_s then }