Displaying Price Difference on chart above/below each bar

 

I am having difficulty trying to display the difference in price between the High and Close (for an up bar) and the Close - Low (for a down bar).

I can do the calculation of price difference but how do I display that difference at 1 pip above the upbar and 1 pip below the downbar for every bar?

Thank you,

MiamiTom

 

Hi MT,

extern int offset = 2;
double Hi_Clos[], Clos_Low[]; // assuming you already fill these with values
int start()
{ // standard counted_bars optimization here
  for(i=limit; i>=0; i--) 
  { string name1 = "Hi_Clos" + Time[i], name2 = "Clos_Low" + Time[i];
  ObjectCreate(name1, OBJ_TEXT, 0, Time[i], High[i] + offset*Point);
  ObjectCreate(name2, OBJ_TEXT, 0, Time[i], Low[i]  - offset*Point);
  ObjectSetText(name1, DoubleToStr(Hi_Clos[i], Digits), 10, "Times New Roman", Green);
  ObjectSetText(name2, DoubleToStr(Clos_Low[i],Digits), 10, "Times New Roman", Red); 
  } 
} // Text labels will be drawn at top & bottom of bars

int deinit()
{ clear("Hi_Clos"); clear("Clos_Low"); }

void clear(string prefix)
{ 
  int prefix_len = StringLen(prefix); 
  for(int i = ObjectsTotal(); i>=0; i--)
  { String name = ObjectName(i);
    if ( StringSubstr(name,0,prefix_len) == prefix )
      ObjectDelete(name);
  }
}

Good luck.
cameo

 
cameofx:

Hi MT,

Good luck.
cameo


Cameo,

Thank you very much for this. I do have a few questions as I get a few errors when compiling:

I don't see an initial value set for i or limit.

I am getting errors with the clear function. I am not sure where to place the clear(string prefix) function. I get an error saying the "string" is not defined.

Thank you,

MT

 
for(int i = ObjectsTotal(); i>=0; i--)
ObjectsTotal() - 1
 
WHRoeder:
ObjectsTotal() - 1

I am getting a "wrong dimension" compile error on the following line at the right hand brace

Hi_Clos[] = (High[0] - Close[0]);

Thank you.

 
WHRoeder:
ObjectsTotal() - 1

Good eye WH I missed that. 

Cameo,
Thank you very much for this. I do have a few questions as I get a few errors when compiling:
I don't see an initial value set for i or limit.
I am getting errors with the clear function. I am not sure where to place the clear(string prefix) function. I get an error saying the "string" is not defined.

 function goes outside of start(), init() & deinit(). You can put it all the way down after last brace.  Look in other working indies to do a proper initialization and loops. I have to leave you with that. Need to crash for a while. 
Good luck.

Reason: