Returns the number of the bar currently being evaluated.
Each bar on a chart (after the number of bars specified by the Maximum number of bars referenced by a study, known as MaxBarsBack) is assigned a number, which is incremented by 1 with each successive bar. For example, if your MaxBarsBack is set to 10, the 11th bar is CurrentBar number 1, the 12th bar is CurrentBar number 2, and so on.
CurrentBar can only be used to return the number of the current bar, for example, you cannot use:
CurrentBar[n]
... to obtain the bar number of the bar n bars ago. However, you can obtain the number of the bar n bars ago (for example, 5) by using:
CurrentBar - 5
Also, the CurrentBar reserved word is the same as the user function BarNumber. The only difference is that you can use the BarNumber function to reference past bars:
BarNumber[5]
You can use CurrentBar to determine how long ago a particular condition occurred:
If Condition1 then
Value1 = CurrentBar;
If CurrentBar > Value1 then
Value2 = CurrentBar - Value1;
Value2 would hold the number of bars ago Condition1 occurred.
看3樓的回復,你試試函數(shù)barpos效果