//+------------------------------------------------------------------+
//|                                                  PriceAction.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

extern bool option_1=1;    // option 1
extern bool option_2=1;    // option 2
extern int barre=10;       // n° de bougie
extern int mvupdn=50;      // décalage prix
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
     {
//--- indicator buffers mapping

if (option_1) DrawArrowUp("Arr_up",High[barre]+(mvupdn*3)*Point,DeepSkyBlue);
if (option_2) DrawArrowDn("Arr_dn",Low[barre]-mvupdn*Point,DeepPink);

DrawArrow("Arrow_1",Low[barre+11]-mvupdn*Point,barre+11,DeepSkyBlue,1);
DrawArrow("Arrow_2",Low[barre+13]-mvupdn*Point,barre+13,DeepSkyBlue,2);
DrawArrow("Arrow_3",Low[barre+15]-mvupdn*Point,barre+15,DeepSkyBlue,3);
DrawArrow("Arrow_4",Low[barre+17]-mvupdn*Point,barre+17,DeepSkyBlue,4);
DrawArrow("Arrow_5",Low[barre+19]-mvupdn*Point,barre+19,DeepSkyBlue,5);
DrawArrow("Arrow_6",Low[barre+21]-mvupdn*Point,barre+21,DeepSkyBlue,6);

//---
      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[])
     {
//---

//int limit, i;
//if(prev_calculated==0){
//      limit = rates_total-1;
//}else{
//      limit = rates_total - prev_calculated;
//}
//bool isCandleBullish;
//for(i=limit; i>0; i--){
//      isCandleBullish = Close[i]>Open[i];//think of doji candles also
//      DrawArrow(Close[i]+10*Point*(isCandleBullish?1:-1),time[i],isCandleBullish);
//}

//--- return value of prev_calculated for next call
      return(rates_total);
    }
//+------------------------------------------------------------------+

void DrawArrowUp(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[barre], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, 233);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

void DrawArrowDn(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[barre], LinePrice); //draw a down arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, 234);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

void DrawArrow(string ArrowName,double LinePrice,int BarNum,color LineColor,int Code)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[BarNum], LinePrice);
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

//const string PREFIX = "ALL_BARS_ARROWS";//to easily delete all objects in OnDeinit()
//    void DrawArrow(double linePrice,datetime time,bool bullish){
//       string name = PREFIX+"arrow"+(bullish?"up":"down")+IntegerToString(time);
//       ObjectCreate(name,OBJ_ARROW,0,time,linePrice);
//       ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
//       ObjectSet(name, OBJPROP_ARROWCODE, bullish?SYMBOL_ARROWUP:SYMBOL_ARROWDOWN);
//       ObjectSet(name, OBJPROP_COLOR, bullish? clrLime : clrRed);
//}
