//+------------------------------------------------------------------+
//|                                          RangeBarCloseMarker.mq4 |
//|                                                       JMFLUKEIII |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "JMFLUKEIII"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern double RangeBarSize = 30; 
extern int corner= 3;
extern string font_name = "Arial";
extern int    font_size = 14;
extern color    font_color_up = DodgerBlue;
extern color    font_color_down = Red;
extern int x_pos = 40;
extern int y_pos = 20;
double Up[];
double Down[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  IndicatorBuffers(2);
  IndicatorDigits(4);
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_ARROW,EMPTY,2,font_color_up);
   SetIndexBuffer(0,Up);
   SetIndexArrow(0,158);
   SetIndexLabel(0,"Up Close");
   SetIndexLabel(1,"Close Down");
   SetIndexStyle(1,DRAW_ARROW,EMPTY,2,font_color_down);
   SetIndexBuffer(1,Down);
   SetIndexArrow(1,158);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
                
  {
//---
   
   ArrayInitialize(Up,EMPTY_VALUE);
   ArrayInitialize(Down,EMPTY_VALUE);
   double highclose = Low[0]+RangeBarSize*Point; 
   double lowclose = High[0]-RangeBarSize*Point;
   Up[0] = highclose;
   Down[0] = lowclose;
   ObjectCreate("chartname"+"1",OBJ_LABEL,0,0,0);
   ObjectSet("chartname"+"1",OBJPROP_XDISTANCE,x_pos);
   ObjectSet("chartname"+"1",OBJPROP_YDISTANCE,y_pos);
   ObjectSet("chartname"+"1",OBJPROP_CORNER,corner);
   ObjectSetText("chartname"+"1",DoubleToStr(highclose,5),font_size,font_name,font_color_up);
   ObjectCreate("chartname"+"2",OBJ_LABEL,0,0,0);
   ObjectSet("chartname"+"2",OBJPROP_XDISTANCE,x_pos);
   ObjectSet("chartname"+"2",OBJPROP_YDISTANCE,y_pos-20);
   ObjectSet("chartname"+"2",OBJPROP_CORNER,corner);
   ObjectSetText("chartname"+"2",DoubleToStr(lowclose,5),font_size,font_name,font_color_down);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
