# Can't get consistent results in Show Bar

Hi Guys,

I’m trying to identify a potential turn in a downtrend using a Show Bar, but it’s only working on the last bar of the chart.

In the attached chart, the circle on the left should have a Show Bar, but doesn’t. The circle on the right has the Show Bar.

What am I doing wrong?

Cheers

Kim

The script is:

GS1 = GANNSWING(WEEK(), USECLUSTERS=False, USEINSIDE=True, METHOD=Use Outside Bar, SWINGCOUNT=1) ;

// Make sure it’s a current established uptrend
GSStart = BARDATE(SWINGSTART(GS1)) ;
GSEnd = BARDATE(SWINGEND(GS1)) ;
GSLength = (GSEnd - GSStart) / 7 > 2 ;
GSEstab = GSLength and GS1 IsUp ;

// Find WW downtrend
Peak1 = SWINGSTART(GS1)[5] ;
Peak2 = SWINGSTART(GS1)[3] ;
Peak3 = SWINGSTART(GS1)[1] ;
PeakLower = Peak1 > Peak2 and Peak2 > Peak3 ;
Trough1 = SWINGSTART(GS1)[4] ;
Trough2 = SWINGSTART(GS1)[2] ;
TroughLower = Trough1 > Trough2 ;
DownTrend = PeakLower and TroughLower ;

// Find a higher trough following established downtrend
Trough3 = SWINGSTART(GS1) ;
TroughHigher = Trough3 > Trough2 ;

// Make sure Trend is longer than 12 weeks
Length1 = BARDATE(SWINGSTART(GS1))[5] ;
Length2 = BARDATE(SWINGSTART(GS1))[1] ;
Length3 = (Length2 - Length1) / 7 ;
TrendLength = Length3 >= 12 ;

// Make Sure Current price is above last peak
Tradeable = HIGH(WEEK()) > Peak3 ;

GSEstab and DownTrend and TroughHigher and TrendLength and Tradeable

Hi Kim,

I suspect you problem starts with your use of SWINGSTART to find Peaks and Troughs.

Every trend change producing a Top and Bottom on the chart will be a SWINGSTART, except the last bar on the chart. Similarly, every Top and Bottom will be a SWINGEND, except for the first top/bottom turn on the left of the chart. You can easily prove this by applying SWINGSTART(GS1) to a SHOWBAR.

Because of this, to define a Peak you need to show that the previous and succeeding SWINGSTARTs are lower in price that the SWINGSTART at the Peak, thus to identify Peaks you need something like this:

Peak = (SWINGSTART(GS1)[1] < SWINGSTART(GS1)[0]) and (SWINGSTART(GS1)[0] > SWINGSTART(GS1)[-1]);

and for Troughs you could use:

Trough = (SWINGSTART(GS1)[1] > SWINGSTART(GS1)[0]) and (SWINGSTART(GS1)[0] < SWINGSTART(GS1)[-1]);

That’s the starting point for making your script work. I haven’t gone any further, that I’ll leave to you to it for the moment.

I would also note that there are a number of other foibles in using the GANNSWING, especially that a SWINGSTART/SWINGEND can only be confirmed and highlighted once the change in trend is confirmed and this can take a number of bars, especially if there are outside and/or inside bars around the turn. Been burned by that many times.

I would also suggest that every time you add a new variable to your scripts you test it with a SHOWBAR or SHOWVIEW for Boolean values and if you are calculating a value, use SHOWPLOT/SHOWVIEW or a CHART ELEMENT.

Cheers

Trevor

The Auld Tyma at

Thanks Trevor, I knew it had to be something to do with the SWINGSTART but would never have thought of the solution you’ve provided!!! Very much appreciated.

The best advice was to build it slowly using a Show Bar to check - I do tend to rush in a bit!

I’ll keep playing with the rest of it and hopefully get there.

Cheers

Kim

Hi Kim,

Mathew just posted a blog on swing scripting, and talks about SwingStart and SwingEnd functionality:

https://www.optuma.com/swing-scripting-1/