Weighted Average array

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Weighted Average array

Postby evdl » 05 Jul 2013

HighestArray or AverageArray are in Multicharts.

I would like to calculate the weighted average over an array.

Something like WAverageArray. But that does not exist.

Code: Select all


Arrays:// Position profit array
Intrabarpersist Openposition_exit_array[](0);

If close <> close[1] then begin
Profit_count_exit = Profit_count_exit + 1;
end;

// expand the array by one
array_setmaxindex(Openposition_exit_array, profit_count_exit);

// post data to array
Openposition_exit_array[Profit_count_exit] = openpositionprofit;

// calculate the profit values
Profit_amt = Openposition_exit_array[profit_count_exit];
Highest_Profit_amt = Highestarray(Openposition_exit_array, profit_count_exit);
Average_profit_amt = AverageArray(Openposition_exit_array, profit_count_exit);
W_Average_profit_amt = WAverage(Profit_amt,profit_count_exit);
I tried to use the Waverage function. But the calculating of W_Average_profit_amt is not working because of the max bar restricting. And I am not sure it will generated the right values anyway.

Is there someone who has the method for calculating the Weighted Average of an array?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Weighted Average array

Postby Henry MultiСharts » 25 Jul 2013

Hello evdl,

It does not look like your code will do what you expect it to do.
You just need to write a function for WAverageArray calculation. It will be similar to WAverage.
Open the WAverage source code and replace a series variable with an array.


Return to “MultiCharts”