counting bars

Estrend

Junior member
Messages
26
Likes
0
hi how to code an indicator which count the number of bars onwards when a pivot low is made and reset when a new pivot low is made?
 
If you already have an indicator that plots pivot points, that indicator is keeping track of the bar number at which the pivot occurred. Subtracting that number from the current bar number will get you the "bars since" number. Because you are using the last occurance of the pivot, when a new pivot is identified the count will reset by itself.
 
Hi Pivotas,

do u have any idea how to determine whether the last pivot on chart is a high or low pivot?
 
Assuming you are using Tradestation, there are 2 ShowMe studies called PivotHigh, PivotLow. Open them up and look at the language they use to define their different plots. They call upon the functions PivotHighVSBar and PivotLowVSBar. These functions return the bar number of the High or Low pivot respectively.
 
Pivot

Hi,

Yes TS has pivothighbarvs and pivotlowbarvs.

If pivothighbarvs then value1 = 1 else value1 = 0;
if pivotlowbarvs then value2 = -1 else value2 = 0;

value3 = value1 + value2;

plot1(value3);

The indicator plots a if there is pivot high and -1 if there is a pivot low. However how to determine the last pivot is 1 or -1?
 
pivothighbarvs and pivotlowbarvs returns the number of bars ago that the pivothigh and pivotlow occurred. The value of -1 or 1 are only returned if a pivot did not occur within the length you specified. The barvs with the lowest count of bars ago will be the last one plotted. There are several ways you can do this. Here is one: Variable:pivothighcount(0), pivothighlast(false),Pivotlowcount(0),pivotlowlast(false);

pivothighcount=PivotHighVSBar(Instance, Price, LeftStrength, RightStrength, Length);
pivotlowcount=PivotLowVSBar(Instance, Price, LeftStrength, RightStrength, Length);

If pivothighbars<pivotlowbars then pivothighlast=true else pivothighlast=false;
If pivotlowbarsvs<pivothighbarsvs then pivotlowlast=true else pivotlowlast=false;

Then depending on what you want to do with this:

If pivothighlast=true then begin......

If pivotlowlast=true then begin.....


Just make sure you have a Length that will be more than necessary to include the last several pivots.
 
Last edited:
Top