Hi,
I'm just wondering how you would calculate the moving average high for each candle.
I'm wondering if this is correct :
for(i=0; i <= Bars; i++)
{
hi = High;
}
where p is the number of periodsOn straight reading, your code is the same as the following:
for(i=0; i <= Bars; i++) {
hi = v;
}
[/PHP]
which I wouldn't call a Moving Average of any description. Rather, it picks the highest high within the most recent period of size p, and then plots that value for all bars.
Rather, a Simple Moving Average over the highs of bars would be coded like the following:
for ( i = Bars-1; i >= Bars-1-p; i-- ) {
v += High;
}
hi[ Bars-1-p ] = v / p;
for( i = Bars-1-p-1; i >= 0; i--) {
hi = hi + ( High - High ) / p;
}And a Smoothed Simple Moving Average, which is a simpler method, over the highs of bars would be coded like the following:
[PHP]
hi[ Bars-1 ] = High[ Bars-1 ];
for(i=Bars - 2; i >= 0; i--) {
hi = ( hi * ( p - 1 ) + High[ i ] ) / p;
}
hi ralph,
thank you very much for explaining the code to me !
What i actually need is to plot the highest value in size p, for each bar movement. So for the current bar(i) it finds the high of the last 15(p) bars, and then plots it on the chart.
Does this make sense.. my first post wasn't very clear...
thanks, anthony
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm just wondering how you would calculate the moving average high for each candle.
I'm wondering if this is correct :
for(i=0; i <= Bars; i++)
{
hi = High;
}
where p is the number of periods