Find out Highest High and Lowest Low value from a specific date Range

Hi All,

I want to find out the Highest high and Lowest Low values from a Specific Date Range.
For Eg i need to find out Highest high and Lowest Low from 1 July 2019 to 14 July 2019.

I have tried below code but it's not giving result: -

_SECTION_BEGIN( "Find High Low" );
dn = DateNum();
StartDate = 1190701;
EndDate = 1190714;
StartBar = dn == StartDate;
EndBar = dn == EndDate;
myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
Title = " Highest High - " + myH + " Lowest Low - " + myL;
_SECTION_END();

I am new in programming So kindly help me in this.

Thanks in advance.

Have you read this thread completely before posting? Have you noticed the code tags animation in first post? If so then why not applying it in your post? It is mandatory rule to apply code tags if inserting code to a post.


As for the code...

you do equality check (via == operator). So if a date does not exists then it will fail.
So you may use LookUp function to search for nearest predecessor/successor in such cases.

_SECTION_BEGIN( "Find High Low" );
/// @link https://forum.amibroker.com/t/find-out-highest-high-and-lowest-low-value-from-a-specific-date-range/14356
dt = DateTime();
//
StartDate = _DT("2019-07-01");
EndDate = _DT("2019-07-14");
StartBar = dt == Lookup( dt, StartDate, 1);
EndBar = dt == Lookup( dt, EndDate, -1);
//
myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
//
Plot( C, "Price", colorDefault, styleBar );
Plot( myH, "myH", colorGreen );
Plot( myL, "myL", colorRed );
//
Title = " Highest High - " + myH + " Lowest Low - " + myL;
_SECTION_END();

Note also: "your" code will start output at looked up EndBar (since that's what is told to AB by the program).

8

4 Likes

myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );

Hi, How to exclude the highest value of the StartBar?
Thanks!!


myH = ValueWhen( EndBar, HighestSince( Ref(StartBar,-1), High ) );

1 Like

Thanks a lot!!!!

With your several times of Help, I finally make the wanted Data Analysis Report !!!

Thanks a lot!!!!