Optuma Forums › Optuma Scripting › HIGHESTHIGH function reference a variable for look back period
- This topic has 4 replies, 2 voices, and was last updated 10 months ago by
Tommy.
-
AuthorPosts
-
September 27, 2021 at 8:31 pm #66157
Tommy
- Topics: 1
- Replies: 2
- Posts: 3
Hello,
I’m trying to find the highest high since a new 13 week low was created. The date of the 13 week low will only change when the low of the current bar is less then the previous 12 weeks. I want to use the date of the 13 week low bar as a variable and use the HIGHESTHIGH function to find the highest high since the date of the 13 week low.
Is it possible to reference a variable in the HIGHESTHIGH function? Below is what I have done so far but script is not valid for H1.
1234567891011121314151617181920212223//Lowest low for the last 13 weeksL1 = LOWESTLOW(Week(PERIODAMOUNT=1), BARS=12, INCBAR=False);//Low of current bar is not lower then the previous 12 weeksL2 = LOW() < L1;//Date since there was a new 13 week lowB1 = BARDATE(L2);//Number of weeks since new 13 week lowB2 = (BARDATE() - B1)/7;//Highest high since new 13 week lowH1 = HIGHESTHIGH(RANGE=Look Back Period, BARS = B2);H1September 28, 2021 at 1:27 pm #66162Matthew
- Topics: 5
- Replies: 625
- Posts: 630
Hi,
The following script could work, but it’s only valid for current data (ie you can’t scan for historical instances).
12345V1 = LOW() CrossesBelow LOWESTLOW(BACKTYPE=Weeks, BARS=13);$a = TIMESINCESIGNAL(V1);HIGHESTHIGH(BACKTYPE=Bars, BARS=$a)In this example, V1 looks for the new 13 Week Low being set. $a looks for the number of bars since the new low was set, and the Highest High function references this count and sets the back bars accordingly.
In the image below you can see on ASX the last 13 week low was 144 bars ago. The Highest High (blue) line is using a lookback period of 144 bars.
If you enabled training mode and started hiding bars, the Highest High line would adjust based on the $a variable count.1 user thanked author for this post.
September 29, 2021 at 6:16 am #66167Tommy
- Topics: 1
- Replies: 2
- Posts: 3
Hi Matthew,
Thank you for your reply. That works fine. I see what you mean, it’s only valid for current data. Is it possible to view historical instances from current data instead of using training mode?
Using the show plot like you have done above, when there is a new a new 13 week low the HighestHigh would reset to the high of the bar that created a new 13 week low. It would gradually step up when there are new highs until a there is new 13 week low where it would reset again.
Thank again
Tom-
This reply was modified 10 months ago by
Tommy Hurse.
September 29, 2021 at 2:10 pm #66172Matthew
- Topics: 5
- Replies: 625
- Posts: 630
Hi,
The following alternative script should work on a historical basis as well (no need for Training Mode)…
12345Signal = LOW() CrossesBelow LOWESTLOW(BACKTYPE=Weeks, BARS=13);HHSinceLL = HIGHESTSINCE(Signal, INCBAR=True);IF(HHSinceLL <= 0, If(High() > Previous(), High(), Previous()), HHSinceLL)1 user thanked author for this post.
September 29, 2021 at 8:54 pm #66173Tommy
- Topics: 1
- Replies: 2
- Posts: 3
Hi Matthew.
Thanks for that. That seems to works fine.
Kind regards
Tom -
AuthorPosts
- You must be logged in to reply to this topic.