int pos=Bars-counted_bars;
double dMedian ,dMedian1, dResult;
//----main calculation loop
while(pos>=0)
{
dMedian = (High[pos] + Low[pos]) / 2; //medianPrice
dMedian1 = (High[pos+3] + Low[pos+3]) / 2;
dResult = dMedian*100/dMedian1; //Momentum of medianprice
ExtMapBuffer1[pos] = dResult; //fill buffer with results
pos--; //calc next bar
}In the beginning, you will find two bars for which dMedian1 would be zero, and I suspect MT4 gets quite uppity with division by 0. Thus, make sure that pos < Bars - 2.
Thank you very much, that was it!
I have coded this now:
while(pos>=0)
{
dMedian = (High[pos] + Low[pos]) / 2;
dMedian1 = (High[pos+3] + Low[pos+3]) / 2;
if (dMedian1 == 0) dMedian1 = 1;
dResult = dMedian*100/dMedian1;
ExtMapBuffer1[pos] = dResult;
pos--;
}
Now it seems to work.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use