Optuma Forums › Optuma Scripting › Average number of bars in swing while in up trends
Tagged: SWINGSTATS
- This topic has 1 reply, 1 voice, and was last updated 2 weeks ago by
David.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
January 10, 2023 at 8:56 pm #70135
David
- Topics: 15
- Replies: 24
- Posts: 39
Hi all,
I’m trying to work out the average number of bars in up swings while the (Gann) trend is up.
What I’ve got so far is
1234gs1 = GANNSWING();SWINGSTAT(gs1, DEFAULT=AvgBars)That seems to give me the average number of bars in up swings, but ignores the direction of the trend.
123SWINGTRENDUP(gs1)gives me a way to work out the direction of the trend, but I can’t work out how to use it to filter the results of SWINGSTAT() in the above script.
Any thoughts?
Thanks in advance
-
This topic was modified 3 weeks ago by
David.
January 21, 2023 at 2:52 pm #70211David
- Topics: 15
- Replies: 24
- Posts: 39
I managed to figure out a solution in Python. This code works on the last 100 days’ data, which is fine for my purposes:
12345678910111213141516171819202122232425262728import Toolfrom statistics import mean#Init function gets called once when tool is applied/loadeddef Init():Tool.Props.Name = "AvgDaysUp"Tool.Props.Hint = "Average number of days spent in up moves while trend is up"#Process function gets called when applied/loaded or when new data is received#start, end are the start and end+1 indexes of the source data list.def Process(start, end):TrendIsUp = Tool.RunScript('gs1=GANNSWING(SWINGCOUNT=1);SWINGTRENDUP(gs1) and CLOSE()>0', Tool.Source)HigherLow = Tool.RunScript('LOW(OFFSET=1)<=LOW()', Tool.Source)DayRunCount = 0RunCounts = []for i in range(end-101, end):if TrendIsUp.Row(i).Close != 0 and HigherLow.Row(i).close != 0:DayRunCount += 1else:if DayRunCount > 0:RunCounts.append(DayRunCount)DayRunCount = 0print(mean(RunCounts))for i in range(end-101, end):Tool.DataOut.Row(i).Close = mean(RunCounts) -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.