Three candles

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Three candles
ÿþ//+------------------------------------------------------------------+

//|                                                Three candles.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                      https://www.mql5.com/en/users/barabashkakvn |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/en/users/barabashkakvn"

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot ThreeUp

#property indicator_label1  "ThreeUp"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot ThreeDn

#property indicator_label2  "ThreeDn"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uchar                Inp_Arrow_Up_Code       = 200;            // Up: symbol code from the Wingdings font

input int                  Inp_Arrow_Up_Shift      = 10;             // Up: vertical shift of arrows in pixels

input uchar                Inp_Arrow_Dn_Code       = 202;            // Dn: symbol code from the Wingdings font

input int                  Inp_Arrow_Dn_Shift      = 10;             // Dn: vertical shift of arrows in pixels

//--- indicator buffers

double   ThreeUpBuffer[];

double   ThreeDnBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,ThreeUpBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ThreeDnBuffer,INDICATOR_DATA);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//--- define the symbol code for drawing in PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,Inp_Arrow_Up_Code);

   PlotIndexSetInteger(1,PLOT_ARROW,Inp_Arrow_Dn_Code);

//--- set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,Inp_Arrow_Up_Shift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-Inp_Arrow_Dn_Shift);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---

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

  {

//---

   if(rates_total<3)

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=2;

   for(int i=limit; i<rates_total; i++)

     {

      ThreeUpBuffer[i]=EMPTY_VALUE;

      if(open[i-2]<close[i-2] && open[i-1]<close[i-1] && open[i]<close[i])

         if(low[i-2]<low[i-1] && low[i-1]<low[i])

            if(high[i-2]<high[i-1] && high[i-1]<high[i])

               ThreeUpBuffer[i]=low[i];

      ThreeDnBuffer[i]=EMPTY_VALUE;

      if(open[i-2]>close[i-2] && open[i-1]>close[i-1] && open[i]>close[i])

         if(low[i-2]>low[i-1] && low[i-1]>low[i])

            if(high[i-2]>high[i-1] && high[i-1]>high[i])

               ThreeDnBuffer[i]=high[i];

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments