It means you have read all historical data (-ve bar indexes) and are now at the most recent.
2 where should it be used
Anytime you need to know if all historical bars have been iterated, or anytime you need to know if you are at the most recent bar.
As new bars complete, the latest bar is always 0, and the last bar that was 0 is now -1. etc...
3 when & how should it be used
In many scripts it will never have to be used. For certain scripts you really want to know that you have processed all historical data, or maybe you want to make sure you ignore all data until the most recent bar.
So:
if (getCurrentBarIndex == 0)
return;
at the start of an efs will make sure your script doesn't do anything until all the historic bars have been processed.
shogun,
With all due respect to Garth, who obviously knows much more about programming than I do, I think there is an error in that last reply to your question.
I think he meant to say != 0. For example,
var vIndex = getCurrentBarIndex();
if(vIndex != 0) return;
This should cause the efs to wait until all bars are loaded.
{
1/ if (getCurrentBarIndex()==0)
2/ {
3/ if ((close()>Fast_MA)&&(close(-1)<=prevFast))
but when i remove line 1/ it runs perfect ,
your comments have clarified that i don't need line 1/ but i dont see why it will stop the program from running, if i had changed the ()==0) to ()!=0) would that have worked.
used in the following context it works,
{
4/ if (getCurrentBarIndex()==0)
5/ {
6/ if ((Fast_MA>Slow_MA)&&(prevFast<=prevSlow))
1/ if (getCurrentBarIndex()==0)
2/ {
3/ if ((close()>Fast_MA)&&(close(-1)<prevFast))
With the first line in place the 3rd line will only be evaluated for bar 0. Therefore unless 1 & 3 are both true at the same time you will never execute the code under #3. Whereas if line 1 is commented out, line 3 will run for each historical bar and at anytime in history that #3 is true you will execute the under #3.
debugPrintln() works really well for debug on this kind of logic.
debugPrintln(" Index = " + getCurrentBarIndex() + " close = " + close());
I use this command to determine if we are at the MOST RECENT BAR on the chart. Thus, for your RTDO code, we don't want it to execute trades on PAST BARS - so I use this command to enclose the routines for your entry orders.
here is a little help
getCurrentBarIndex() will NOT equal 0 (zero) when the EFS is running on PAST BARS (those where we DON'T want any trading action for RTDO).
getCurrentBarIndex() WILL equal 0 (zero) when the EFS is running on the CURRENT BAR (where we DO want trading action for RTDO).
that explains a side effect i get when i remove "getcurrentbarindex()" . when i load a efs with "DO" attached it throws loads or buy/sell mkt orders through, so it is obviously reading the past bars,
edit - already put together this response, then noticed you had put up new post, I will post anyways, maybe this will help
There is a simple explanation. A boolean is either a 1 or a zero. this This cooresponds directly to true or false. If you test a boolean in an if statement.
this test with tmp = 0 or tmp = false would write boolean false
if tmp = 1 or tmp = true would write boolean true
using either 0 or 1 or false and true are synonymous
Regarding "why does 1/ need a period & 2/ does not "
IMHO 2/ is a bad selection of variable name, because of this confusion. It is a variable, just as tmp is a variable above. you could assign 2/ a value of 365.
e.g.
var tmp = 100;
var = StrategyisLong = 365;
debugPrintln (StrategyisLong);
debugPrintln (StrategyisLong+tmp);
the first output would be 365, the second output would be 465
The problem is that it is so close in format to the function used in 1/
The function in 1/ returns a boolean value based on trade status associated with the strategy analyzer. If you are using this set of functions and you are in a long trade
var = StrategyisLong = 365;
debugPrintln (Strategy.isLong());
debugPrintln (StrategyisLong);
the first output would be true, the second output would be 365
Comment