Using List and Map to sort highs and Lows  [SOLVED]

Questions about MultiCharts and user contributed studies.
rtrader
Posts: 9
Joined: 21 Aug 2013

Using List and Map to sort highs and Lows

Postby rtrader » 02 Jul 2014

On a 1 min chart/ No IOG
We would like to:
find if the highest high occurred on the 1st or 10th bar (i.e. in the first or tenth minute).

if the highest high occurred on bar 1, use the second highest high (providing it does not occur on the 10th bar). If the second highest high occurred on the 10th bar, use the 3rd highest high.

if the highest high occurred on bar 10, use the second highest high (providing it does not occur on 1st bar). If the second highest high occurred on the 1st bar, use the 3rd highest high.

if the highest high occur in bar 2 to 9 then use that as the highest high.

repeat above for finding lowest low.

what is the best way to do the above: arrays or elc list/maps?
And if using ELC what is the best approach to use for this?
Using ELC list and maps:

Code: Select all

variables:
min_low(0),
min_high(0),
min_bar_count(0);

//create bar counter that increments on date change from 1 to 10
if date <> date[1] then begin
min_bar_count = 1;
end;
if date = date[1] and min_bar_count >= 1 and min_bar_count <= 9 then begin
min_bar_count = min_bar_count[1] + 1;
//min_bar_count += 1;
end;

//reset counter to zero after bar10
if date = date[1] and min_bar_count[1] = 10 then begin
min_bar_count = 0;
end;

Code: Select all

vars: min_bar_high(MapNN.New), min_bar_low(MapNN.New);
vars: list_high(ListN.New), list_Low(ListN.New);;

value1 =ListN.PushBack(list_high, high);
value1 =ListN.PushBack(list_low, low);

value1 =ListN.Sort(list_high, false);
value1 =ListN.Sort(list_low, true);
Would you now use a List sort by map? If so how?

many thanks for advice/help with this.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Using List and Map to sort highs and Lows  [SOLVED]

Postby JoshM » 06 Jul 2014

We would like to:
find if the highest high occurred on the 1st or 10th bar (i.e. in the first or tenth minute).
If you want to achieve this (which might be something else than your code suggests), there is no need to use a list or array.

For example:

Code: Select all

Variables:
highOfDay(0),
barNumOfHigh(0),
startingBarNum(0);

once cleardebug;

// Reset variables
if (Date <> Date[1]) then begin

highOfDay = 0;
barNumOfHigh = 0;
startingBarNum = CurrentBar;

end;

if (BarStatus(1) = 2) then begin

// Calculcate variables
if (High > highOfDay) then
barNumOfHigh = CurrentBar - startingBarNum + 1;

highOfDay = MaxList(highOfDay, High);

// Verify
Print(FormatTime("HH:mm", eltimetodatetime(time)),
" High of day: " + NumToStr(highOfDay, 5) + ", bar of day: " +
NumtoStr(barNumOfHigh, 0));

end;

rtrader
Posts: 9
Joined: 21 Aug 2013

Re: Using List and Map to sort highs and Lows

Postby rtrader » 07 Jul 2014

many thanks for reply JoshM. You're right, no need for lists or arrays to achieve this.
much appreciated.


Return to “MultiCharts”