Days since last 5% swing low

Hi,

I have tried to write a script that counts the days since the last e.g. 5% swing low. A 5% swing low is a correction of at least 5%.

// Set the swing percentage; 
Var1 = PERCENTSWING(PERCENT=5.0); 

// Get the swingend values; 
Var2 = SWINGEND(Var1); 

// Count trading days since last swing low; 
Var3 = TIMESINCESIGNAL(Var2); 
Var3

Unfortunately the script doesn’t works. I have tried a lot of other variations but no one does what is should. Any help is appreciated.

Thanks
Thomas

Hi Thomas,

SwingEnd() gives the value of the swing, not the date.

The difficulty with swings is that you have to wait X days until the swing turn has been confirmed (ie until price has moved at least 5%) so using something like TIMESINCESIGNAL(Var1 TurnsUp) won’t work as that counts from when the swing was confirmed, not from the low bar.

The only way I can think of is to count since the low price was equal to the swing end: TIMESINCESIGNAL(LOW()==Var2)

Note that this doesn’t take in to account the current swing direction, so if using a watchlist add SWINGUP(Var1)==1 to a column and sort.

Out of the Dow 30, it’s been 66 days since MSFT had a swing low, followed by 8 others on 40 days. At 9 days ago INTC had the most recent swing low.

Capture

Hi Darren,

Thank you very much for all your work. The script works perfectly with TIMESINCESIGNAL(LOW()==Var2).

Here is the complete script for calculating with High/Low:

// Set the swing percentage using High/Low; 
Var1 = PERCENTSWING(PERCENT=5.0, CALCUSINGTOOL=High/Low); 

// Get the swingend values; 
Var2 = SWINGEND(Var1);

// Count trading days since last swing low; 
Var3 = TIMESINCESIGNAL(LOW()==Var2); 
Var3

But there is a special issue if I change the property “Calculate Using” from “High/Low” to “Close”. The results of the script are completely wrong.

Here is the script for calculating with the Close:

// Set the swing percentage using CLOSE; 
Var1 = PERCENTSWING(PERCENT=5.0, CALCUSINGTOOL=Close); 

// Get the swingend values; 
Var2 = SWINGEND(Var1); 

// Count trading days since last swing low; 
Var3 = TIMESINCESIGNAL(LOW()==Var2); 
Var3

Is there something I have missed?

When I use the tool “Percent Swing Chart Overlay (PCSC)” and change the property “Calculate Using” from “High/Low” to “Close” the tool works as it should and changes the calculation from High/Low to Close.

Thanks again a lot,
Thomas

Hi Thomas,

Var2 is now using the closing price rather than the low, so Var3 needs to be changed to CLOSE()==Var2.