the sum of bars length

 

hi

how can i find the sum

of bars length between tow dates using mql4

if i had a startdate {S} and enddate{E} and want the indicator to deduct the high from low of each bar between S and E

and sum the result.....which function can do that........ only i need the name of the function and then i will tray to do the rest

any help is appreciated and.......thanks in advance.

 

My approach would be (and maybe someone has a better/different one) ...

.. put H - L into a buffer

.. get BarS & BarE bar index (where BarS = start = oldest)

.. double SumHMinusL = iMAOnArray(buff, 0, BarS - BarE + 1, MODE_SMA, shift) * (BarS - BarE + 1);

 
brewmanz:

My approach would be (and maybe someone has a better/different one) ...

.. put H - L into a buffer

.. get BarS & BarE bar index (where BarS = start = oldest)

.. double SumHMinusL = iMAOnArray(buff, 0, BarS - BarE + 1, MODE_SMA, shift) * (BarS - BarE + 1);



hi

thanks for u brewmanz.......i will tray your idea

 
abdI:



hi

thanks for u brewmanz.......i will tray your idea



brewmanz:

My approach would be (and maybe someone has a better/different one) ...

.. put H - L into a buffer

.. get BarS & BarE bar index (where BarS = start = oldest)

.. double SumHMinusL = iMAOnArray(buff, 0, BarS - BarE + 1, MODE_SMA, shift) * (BarS - BarE + 1);

one more question my friend and forgive me am new to programming.... what do u mean by (shift)

in ur code in the red line

 

I am also searching for a similar one.

 
1007:

I am also searching for a similar one.



this is a part of code and not yet an indicator...am until now cannot get it in right way......hope for some help.....
 
abdI:
if i had a startdate {S} and enddate{E} and want the indicator to deduct the high from low of each bar between S and E
and sum the result.....
Wouldn't it me easier to use
datetime S=..., 
         E=...;
int      Sb=iBarShift(NULL, 0, S),
         Eb=iBarShift(NULL, 0, E),
         length = Eb - Sb + 1;
double   atr = iATR(NULL,0, length, Sb),
         sum = atr * length;
 
WHRoeder:
Wouldn't it me easier to use



thanks very much my friend for ur help......ur code work ok for me

thanks

 

My interpretation of the question is a bit different from WHRoeder's...

datetime S=...;
         E=...;

int      sum = 0;

for( int i = iBarShift( NULL, 0, S ); i <= iBarShift( NULL, 0, E ); i++ )
{
   sum += ( iHigh( NULL, 0, i ) - iLow( NULL, 0, i ));
}

I don't think the use of "atr * length" results in the sum of price ranges over the atr period.

I'm sure it is something close, but "true range" is defined as:

-Current High less the current Low,

-Current High less the previous Close (absolute value)

or

-Current Low less the previous Close (absolute value)

...whichever is the largest of the 3.

Atr is simply the average of true range for some number of bars. In most price sequences, I think "atr * length" will result in a value that is higher than the actual total height of bars.

 

What i am serching is also a bit different.

Information required is - if the chart TF is 4hrs i like to know the sum of total candles inside this 4hrs candle of 1minute candle or 5 minutes candles.

 
WHRoeder:
Wouldn't it me easier to use
Anomalous:

My interpretation of the question is a bit different from WHRoeder's...

I don't think the use of "atr * length" results in the sum of price ranges over the atr period.

I'm sure it is something close, but "true range" is defined as:

-Current High less the current Low,

-Current High less the previous Close (absolute value)

or

-Current Low less the previous Close (absolute value)

...whichever is the largest of the 3.

Atr is simply the average of true range for some number of bars. In most price sequences, I think "atr * length" will result in a value that is higher than the actual total height of bars.


hi.....

it seems that the use of ATR didnt help me and gave me a different calculation than what i want...... i was in hurry to solve my problem .....and now after discovering that the ATR is not what i want i will return to the first (square)

i must say thanks to all who helped me in this topic : brewmanz, WHRoeder and Anomalous

but want to aske Anomalous about this part of his code:

 sum += ( iHigh( NULL, 0, i ) - iLow( NULL, 0, i ));

how can i connect sum+ to ObjectCreate ?

i want to show the result on the screen i had tray many methods but didnt find the correct result;

i know this part of coding

ObjectCreate("Diff", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Diff",DoubleToStr(sum+,5),14, "Arial", Red);
      ObjectSet("Diff", OBJPROP_XDISTANCE,20);
      ObjectSet("Diff", OBJPROP_YDISTANCE, 42);
      ObjectSet("Diff", OBJPROP_CORNER, 3);
but in compiling it gave me error about sum +:

any one can help and thanks in advance

Reason: