Optuma Forums › Optuma Scripting › Days since last 5% swing low
- This topic has 3 replies, 2 voices, and was last updated 2 years ago by
Darren.
-
AuthorPosts
-
August 17, 2021 at 6:10 am #65575
Thomas
- Topics: 151
- Replies: 204
- Posts: 355
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%.
1234567891011// 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);Var3Unfortunately 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-
This topic was modified 2 years ago by
Thomas.
August 17, 2021 at 8:18 pm #65579Darren
- Topics: 76
- Replies: 1,038
- Posts: 1,114
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.
1 user thanked author for this post.
August 17, 2021 at 10:15 pm #65581Thomas
- Topics: 151
- Replies: 204
- Posts: 355
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:
1234567891011// 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);Var3But 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:
1234567891011// 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);Var3Is 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-
This reply was modified 2 years ago by
Thomas.
August 18, 2021 at 1:54 am #65589 -
AuthorPosts
- You must be logged in to reply to this topic.