How to calculate the Highest High / Lowest Low for "N' sessions

Questions about MultiCharts and user contributed studies.
tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

How to calculate the Highest High / Lowest Low for "N' sessions

Postby tonyt » 31 Aug 2022

How do I search 'n' number of session for the highest high / lowest low?

Attached is a screen shot with an example. I need to optimize an input, call it Nsessions, that looks at the highest Session High and Lowest Session Low for a given period, IE up to the maximum allowed by the native OHLC / HighS LowS array, which is 50 sessions if I am not mistaken. I need this for Data2 as a filter for a Data1 entry. I'll start with the basics of how to accomplish this and figure out the Data2 issue later.

Here is what I have come up with so far, using a 'for' statement, HH,LL are numeric variables, nsess is an input to test up to 20 sessions:

Code: Select all

inputs: nsess ( 15 ); var: hh ( 0 ), ll ( 0 ); hh = -99999999999; ll = 99999999999; if nSess>1 then begin for value90 = 1 to nSess begin hh = maxlist(hh,HighS(value90)); ll = minlist(ll,LowS(value90)); end; end else if nSess=1 then begin hh = highS(1); ll = LowS(1); end; buy("LE") next bar hh stop; sellshort("SE") next bar ll stop;
This is a condensed version of the code. It compiles but does not work of course. I suspect it is in the definition of High / Low S(Value90). Can the 'for' statement go through each input (1 - nsess) and find the highest / lowest Session for 'n' periods, say 15, while using the MultiCharts native session array HighS / LowS? Any help is appreciated. Thank you!
Attachments
Highest HighS Lowest LowS for N sessions example.png
(252.26 KiB) Not downloaded yet
Last edited by tonyt on 01 Sep 2022, edited 3 times in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby TJ » 31 Aug 2022

See posts #1 & #2

viewtopic.php?t=11713

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby tonyt » 31 Aug 2022

See posts #1 & #2

viewtopic.php?t=11713
thank you. the post is corrected. Can you please provide some insight?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby TJ » 01 Sep 2022

I am not sure what you mean by this one-liner. It can be interpreted in multiple ways.
How do I search 'n' number of session for the highest high / lowest low?
You need to give a real-life example in step-by-step narration.
You need to draw some diagrams/charts, with notes on the picture to point out your vision of how the chart show look like.

viewtopic.php?t=11713#p117614

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby tonyt » 01 Sep 2022

I am not sure what you mean by this one-liner. It can be interpreted in multiple ways.
How do I search 'n' number of session for the highest high / lowest low?
You need to give a real-life example in step-by-step narration.
You need to draw some diagrams/charts, with notes on the picture to point out your vision of how the chart show look like.

viewtopic.php?t=11713#p117614
Attached is a screen shot with an example. I need to optimize an input, call it Nsessions, that looks at the highest Session High and Lowest Session Low for a given period, IE up to the maximum allowed by the native OHLC / HighS LowS array, which is 50 sessions if I am not mistaken. I need this for Data2 as a filter for a Data1 entry. I'll start with the basics of how to accomplish this and figure out the Data2 issue later.
Attachments
Highest HighS Lowest LowS for N sessions example.png
(252.26 KiB) Not downloaded yet

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby rrams » 06 Sep 2022

tonyt, it is better to plot out what you are attempting in an indicator before you write a signal. That way you can make small changes to the code and see the results.

Which one is closer to what you want or neither?

Code: Select all

inputs: nSess(5); var: hh(0), ll(0); // Not enough bar data for requested lookback // of HighS/LowS will return -1. hh=IFF(HighS(nSess)=-1, HighS(0), HighS(nSess)); ll=IFF(LowS(nSess)=-1, LowS(0), LowS(nSess)); plot1(hh, "", yellow); plot2(ll, "", red); if sessionlastbar then print(barnumber+MAXBARSBACK:0:0, " ", nSess:0:0, " ", hh:0:3, " ", ll:0:3);

Code: Select all

inputs: nSess(5); var: hh(0), ll(0); hh=H; ll=L; for value90=0 to nSess begin hh=maxlist(hh, IFF(HighS(value90)=-1, HighS(0), HighS(value90))); ll=minlist(ll, IFF(LowS(value90)=-1, Lows(0), LowS(value90))); end; plot3(hh, "", yellow); plot4(ll, "", red); if sessionlastbar then print(barnumber+MAXBARSBACK:0:0, " ", value90:0:0, " ", hh:0:3, " ", ll:0:3);

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How to calculate the Highest High / Lowest Low for "N' sessions

Postby tonyt » 06 Sep 2022

tonyt, it is better to plot out what you are attempting in an indicator before you write a signal. That way you can make small changes to the code and see the results.
Thank you RRams, that's a good point. I didn't anticipate this to be such a challenge. I normally just 'count bars' not sessions when looking for a high / low, using the array it seems is more challenging. The second code snipet is closer to what I want:

Code: Select all

inputs: nSess(5); var: hh(0), ll(0); hh=H; ll=L; for value90=0 to nSess begin hh=maxlist(hh, IFF(HighS(value90)=-1, HighS(0), HighS(value90))); ll=minlist(ll, IFF(LowS(value90)=-1, Lows(0), LowS(value90))); end; plot3(hh, "", yellow); plot4(ll, "", red); if sessionlastbar then print(barnumber+MAXBARSBACK:0:0, " ", value90:0:0, " ", hh:0:3, " ", ll:0:3);
any help / advice is greatly appreciated.

Thank you


Return to “MultiCharts”