Intraday help: store in an array the last 5 daily High  [SOLVED]

Questions about MultiCharts and user contributed studies.
nuno-online
Posts: 174
Joined: 31 Jan 2006
Has thanked: 74 times
Been thanked: 5 times

Intraday help: store in an array the last 5 daily High

Postby nuno-online » 17 Aug 2014

Hello

In an intraday chart, i 'm trying to store in an array the last 5 daily High in order to have the average

the array is ok but the average isn't
The average does not take into account the last value

can someone tell me why?
here is the script:

Code: Select all

Inputs: Length(5);

Variables: Data2Avg(0);

Arrays: Data2Array[5](0);


If Date > Date[1] then
begin
For Value1 = 0 to 4
begin
Data2Array[5 - Value1] = Data2Array[4-Value1];
Print("Data2Array[5 - Value1] ", Data2Array[5 - Value1], newline);
end;
Data2Array[0] = ((HighD(1) - LowD(1)) / LowD(1)) * 100;
Data2Avg = averagearray(Data2Array, Length );
Print("DATE: ", formatdate("dd-MM-yyyy ", eldatetodatetime(date)),
newline, " Data2Array[0] ",Data2Array[0], " HighD(1) ", HighD(1),
newline, " Data2Array[1] ",Data2Array[1], " HighD(2) ", HighD(2),
newline, " Data2Array[2] ",Data2Array[2], " HighD(3) ", HighD(3),
newline, " Data2Array[3] ",Data2Array[3], " HighD(4) ", HighD(4),
newline, " Data2Array[4] ",Data2Array[4], " HighD(5) ", HighD(5),
newline, " Data2Avg ", Data2Avg);
end;

Plot1(Data2Avg, "Data2Avg");
SetPlotColor(1, Red);
SetPlotWidth(1, 2);

thank you
Nuno

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Intraday help: store in an array the last 5 daily High  [SOLVED]

Postby evdl » 18 Aug 2014

I think it is because you reference to highd(1). Which is the highd of yesterday. Also the highd(0) is not available until the day is ended. So if you want to have the highd on the current day you have to use something like this:

Code: Select all

// calculate todayhigh and todaylow every bar
If Date <> Date[1] then
begin
PriorDayClose = Close[1];
PriorDayHigh = TodayHigh;
PriorDayLow = TodayLow;
PriorDayOpen = TodayOpen;

TodayHigh = High;
TodayLow = Low;
TodayOpen = Open;
end
else
begin
TodayHigh = MaxList( High, TodayHigh ) ;
TodayLow = MinList( Low, TodayLow ) ;
end;
And put the todayhigh and todaylow in an array. In this way you have the high and low of the day at every new bar on the current day.

nuno-online
Posts: 174
Joined: 31 Jan 2006
Has thanked: 74 times
Been thanked: 5 times

Re: Intraday help: store in an array the last 5 daily High

Postby nuno-online » 22 Aug 2014

Hello Evdl

thank you for your help
your script is very good ;)

Nuno


Return to “MultiCharts”