Swing Retracement Scan

The following script will search for 50% retracements (+/- 2%) up from the previous downswing, often seen as an important resistance level. The swings have been based on daily 3 bar Gann Swings, but all the settings (eg retracement levels, tolerance, swing parameters) can be adjusted as needed. The timeframe can be set in the Scanning Manager window.

//Set Swing properties and get swing start/end values
GS1 = GANNSWING(SWINGCOUNT=3,METHOD=USE NEXT BAR);
SS1 = SWINGSTART(GS1);
SE1 = SWINGEND(GS1);

//Calculate previous swing range
V1=SS1[1] - SE1[1];

//Set 2% tolerance either side
V2 = SS1 + (V1 * 0.48);
V3 = SS1 + (V1 * 0.52);

//Is current SwingEnd within the tolerance?
SE1 > V2 and
SE1 < V3 and CLOSE() > 0

In this example, BXP has retraced 48.41% of the previous swing, so might be worth keeping an eye on to see if it breaks through or bounces off:

Capture

Of course, downward retracements are just as important. He’s an example of a retracement from a high of 36 - 40% - ie close to the Fibonacci 38.2% level. Note the changes to variables V2 and V3:

//Set Swing properties
GS1 = GANNSWING(SWINGCOUNT=3,METHOD=USE NEXT BAR);
SS1 = SWINGSTART(GS1);
SE1 = SWINGEND(GS1);

//Calculate previous swing range
V1=SE1[1] - SS1[1];

//Set 2% tolerance either side
V2 = SS1 - (V1 * 0.36);
V3 = SS1 - (V1 * 0.4);

//Is current SwingEnd within the tolerance?
SE1 < V2 and
SE1 > V3 and CLOSE() > 0

 

Hello Darren,

Please, help!. What’s the code for the watchlist to show Retracement% in a numeric form?

Thank you,

Miguel

Hi Miguel,

To calculate the ratio of the current swing to the previous use this for a 3 bar swing (NOTE: this is slightly different from the script above in that inside bars are included in the swing counts).

//Set Swing properties and get swing start/end values - USING INSIDE BARS
GS1 = GANNSWING(SWINGCOUNT=3,METHOD=USE NEXT BAR, USEINSIDE=True);
SS1 = SWINGSTART(GS1);
SE1 = SWINGEND(GS1);

//Calculate previous swing $ range
V1=SS1[1] - SE1[1];
 //Calulate current swing $ value
V2 = SE1-SS1;
//Calculate current swing as % of previous
V2/V1

Note however that it calculates the last confirmed swing end value, which will be different from the current close. For example AAPL’s most recent swing end value of $212.14 occurred 3 bars ago, which is 67.94% of the previous swing. The next swing hasn’t been confirmed yet, so the last close of $206.50 is only 48.35% of the previous swing.

To calculate the retracement to the most recent close instead change variable V2 above (line 10) to the following:

V2 = CLOSE()-SS1;

Save the workbook attached.

RetracePercent.owb (43 KB)