Identifing the 49th Bar after a Primary Signal

Hi Guys,

I have a script that identifies a particular Primary Signal Pattern, such as a Pivot High, after which I wish to use a SHOWBAR highlight for a subsequent Bar after a fixed period, say the 49th Bar after the Primary Signal. I have the following scripts:


// Primary Signal Pivot High

PivotHi = PIVOT(MIN=22, TYPE=High);


// Pivot High Plus TD49

PivotHi = Script(SCRIPTNAME=Pivot High Primary Signal);

PivotHi49 = If(TIMESINCESIGNAL(PivotHi, UNIT=Bars)==49,1,0);



Applied to SHOWBARs this produces the following result:

20180701 Identifying the 49th Bar after a Primary Signal

The Primary Signal is highlighted by the SHOWBARs as dashed vertical lines and the 49th Bar thereafter by the SHOWBAR Arrows, EXCEPT, and this is my issue, when a Primary Signal occurs before the 49th Bar that 49th Bar is ignored. Note the example of the 49th Bar from the second Primary Signal on the above chart, it is not highlighted. Obviously the TIMESINCESIGNAL Bar count is restarted at the new (3rd) Primary Signal, thereby negating the 49th Bar count from the previous Primary Signal.

How can I make my script highlight the 49th Bar after every Primary Signal?

Any suggestions will be appreciated.



Hi Trevor,

If you are wanting to show an arrow 49 bars after every primary criteria is passed, i would use an Offset() function rather than time since signal.

V1 = SCRIPT(SCRIPTNAME=Pivot High Primary SIgnal) ;
V2 = IF(V1 > 0,1,0) ;
V3 = OFFSET(V2, OFFSET=49) ;

Hi Matthew,

Thanks for the solution.

However, I cannot see the need for V2. Surely it is simply repeating the result of the V1 imported signal. Certainly when I remove it and replace the replace V2 with V1 in V3 to results appear to be identical.

I note that this script will only display the periods as per the underlying Chart. Thus if the Bars "Filter" is set to "Calendar Days" the Bar count, ie 49, is actually Calendar Days. Is there a way within the Script to set the "period" count to Bars, Calendar Days or maybe even Weeks or Months?



Hi Trevor,

V2 is needed to convert the script into a True / False result as V1 can produce values between 0 and 3400 (add V1 to a Show view by itself to confirm). To work properly on a Show Bar the script must return a Boolean result of 1 or 0.

Offset will use the charts default settings, there’s no way to override the interval at this time so you will need to take the underlying charts setup into consideration when setting the offset value.