Custom Indicator (Please help)

 

Hello Everyone,

I'm what you would probably consider new to Forex. I've been studying this market for about 5 months now and I'm currently trying to find/create and indicator that I haven't been able to find. I'm interested in finding the average range of (x) number of bars for the open to close only, not the entire range. I know exactly what I'm looking for but I have no idea how to incorporate it into MQL4 code. This is essentially what I'm looking to do:

extern int TotalBars = (25) ///this is the only variable i want to be inputed by the user.

If open>close

then open-close=x1, x2, x3, etc.

If open<close

then close-open=x1, x2, x3, etc.

Sum (x1+x2+x3...)/TotalBars = Avg_Open-Close_Range

I want it to calculate the difference between open and close for each bar (returning a positive number in each case), add it all up, then divide by the number of bars to give me the average.

Then I would like that number to be displayed, either in its own indicator window or right on the chart.

Would it be possible for someone to help me create this indicator or maybe one already exists and I'm not aware of it. I am looking for an actual number here, not a moving average line or anything of that nature.

Any help would be greatly appreciated and many thanks in advance for your time and efforts!

 

Here's what I think you want:

for (k = 25; k <=0; k--)

sum += MathAbs(Open[k] - Close[k]);

Avg = sum / 25;

That's the basic method; just be sure to use MathAbs() to make all subtractions result in positive numbers.

Reason: