Jojojo, here's a small Tradestation program that calculates the bar number for a swing high or low and prints the number above/below the swing.
It first determines how many bars ago the swing occured, then subtracts that from the current bar number to determine the bar number of the swing. The bottom of the program simply prints the number on the chart.
Inputs:
SwingStrength(5);
Variables:
SwingHiBarsAgo(0),
SwingLoBarsAgo(0),
SwingHiBarNum(0),
SwingLoBarNum(0);
SwingHiBarsAgo = SwingHighBar(1, high, SwingStrength, SwingStrength+1) ;
if SwingHiBarsAgo <> -1 then begin
SwingHiBarNum = CurrentBar - SwingHiBarsAgo ;
//You can add code here to store the bar number in an array, or do whatever other calculations you need
end ;
SwingLoBarsAgo = SwingLowBar(1, Low, SwingStrength, SwingStrength+1) ;
if SwingLoBarsAgo <> -1 then begin
SwingLoBarNum = CurrentBar - SwingLoBarsAgo ;
//You can add code here to store the bar number in an array, or do whatever other calculations you need
end ;
Variables:
TextSwingHi(0),
TextSwingLo(0);
if SwingHiBarsAgo <> -1 then begin
TextSwingHi = Text_New(date[swingHiBarsAgo], time[swingHiBarsAgo], High[swingHiBarsAgo], NumToStr(SwingHiBarNum,0)) ;
Text_SetStyle(TextSwingHi, 2, 1) ;
end ;
if SwingLoBarsAgo <> -1 then begin
TextSwingLo = Text_New(date[swingLoBarsAgo], time[swingLoBarsAgo], Low[swingLoBarsAgo], NumToStr(SwingLoBarNum, 0)) ;
Text_SetStyle(TextSwingLo, 2, 0) ;
end ;