Todays Channel

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Todays Channel
ÿþ//+------------------------------------------------------------------+

//|                                               Todays Channel.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

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

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot Upper

#property indicator_label1  "Upper"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrYellowGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Bottom

#property indicator_label2  "Bottom"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrYellowGreen

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uint        InpChannel     = 150;   // Channel, in Points (1.00055-1.00045=10 points)

input ushort      InpUpperCode   = 176;   // Upper Arrow code (font Wingdings)

input ushort      InpBottomCode  = 176;   // Bottom Arrow code (font Wingdings)

//--- indicator buffers

double   UpperBuffer[];

double   BottomBuffer[];

//---

double   m_channel                  = 0.0;      // Channel                    -> double

bool     m_init_error               = false;    // error on InInit

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- forced initialization of variables

   m_channel                  = 0.0;      // Channel                    -> double

   m_init_error               = false;    // error on InInit

//---

   if(Period()>=PERIOD_D1)

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      ""09<D@59< 8=48:0B>@0 =5 <>65B 1KBL >= 'D1'!":

                      "The indicator timeframe cannot be >= 'D1'!";

      if(MQLInfoInteger(MQL_TESTER)) // when testing, we will only output to the log about incorrect input parameters

         Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      else // if the Indicator is run on the chart, tell the user about the error

         Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      //---

      m_init_error=true;

      return(INIT_SUCCEEDED);

     }

//--- indicator buffers mapping

   SetIndexBuffer(0,UpperBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BottomBuffer,INDICATOR_DATA);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpUpperCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpBottomCode);

//--- set as an empty value 0.0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   m_channel=InpChannel*Point();

//---

   datetime time=iTime(Symbol(),PERIOD_D1,0);

//---

   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(m_init_error)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

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

     {

      //--- D1

      int i_bar_shift=iBarShift(Symbol(),PERIOD_D1,time[i],false);

      if(i_bar_shift<0)

         return(0);

      MqlRates rates_d1[];

      ArraySetAsSeries(rates_d1,true);

      if(CopyRates(Symbol(),PERIOD_D1,i_bar_shift,1,rates_d1)!=1)

         return(0);

      //--- Arrow

      UpperBuffer[i]=rates_d1[0].open+m_channel;

      BottomBuffer[i]=rates_d1[0].open-m_channel;

     }

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

   return(rates_total);

  }

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

Comments