What I then do is to make all the outcome an positive number. So if the openinggap was -0,40. I multiple this with -1 to get 0,40. I got this to work.
But now I want to calculate the average of all the opening gaps. This to determine the risk involved when I have a strategy that will go overnight.
I tried to use AverageArray, but it is not working.
Code: Select all
variables: Openingsgap(0),
Count(0),
Averagegap(0);
array: open_gap[](0),
close_gap[](0),
avg_gap[] (0);
Count = count;
if date <> date[1] then begin
Array_setmaxindex(open_gap, count);
open_gap[count] = opend(0);
Array_setmaxindex(close_gap, count);
close_gap[count] = closed(1);
Openingsgap = open_gap[count] - close_gap[count];
if openingsgap < 0 then
openingsgap = (open_gap[count] - close_gap[count])*-1;
Array_setmaxindex(avg_gap, count);
avg_gap[count] = (opend(0) - closed(1));
averagegap = averagearray(avg_gap, count);
Print("Date: ",formatdate("dd-MM-yyyy ",eldatetodatetime(date))," open ", open_gap[count]," Close Yesterday ", close_gap[count]," openingsgap ", Openingsgap," average", Averagegap);