Author: Copyright 2020, MetaQuotes Software Corp.
Indicators Used
Moving average indicator
1 Views
0 Downloads
0 Favorites
Trio Color
ÿþ//+------------------------------------------------------------------+

//|                                                   Trio Color.mq5 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright   "Copyright 2020, MetaQuotes Software Corp."

#property link        "https://mql5.com"

#property description "Copyright © Vladimir Karputov"

#property description "Copyright © fxborg"

#property description "Copyright © Scriptor "

#property version     "1.000"

//---

#include <MovingAverages.mqh>

//---

#property indicator_chart_window

#property indicator_buffers 25

#property indicator_plots   6

#property indicator_label1  "Sell"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrViolet

#property indicator_width1  2

#property indicator_label2  "Buy"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrAquamarine

#property indicator_width2  2

#property indicator_label3  "Middle"

#property indicator_type3   DRAW_COLOR_LINE

#property indicator_color3  clrAqua,clrDeepPink,clrDarkGray

#property indicator_style3  STYLE_SOLID

#property indicator_width3  2

#property indicator_label4  "Upper"

#property indicator_type4   DRAW_LINE

#property indicator_color4  clrDarkGray

#property indicator_width4  1

#property indicator_style4  STYLE_DOT

#property indicator_label5  "Lower"

#property indicator_type5   DRAW_LINE

#property indicator_color5  clrDarkGray

#property indicator_width5  1

#property indicator_style5  STYLE_DOT

#property indicator_label6  "Coral"

#property indicator_type6   DRAW_COLOR_LINE

#property indicator_color6  clrGreen,clrRed,clrDarkGray

#property indicator_style6  STYLE_SOLID

#property indicator_width6  2

//---

input group  "---- parameters ----"

input double InpScaleFactor              = 2.25;        // Scale factor

input int    InpMaPeriod                 = 3;           // Smooth Period

input int    InpVolatilityPeriod         = 70;          // Volatility Period

input double InpCoeffcop                 = 0.06349206;  // Coral Coefficient

input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price Coral

input group  "---- Signal ----"

input bool   Inpyna                      = true;        // 1 Volatility Signal

input bool   Inpdoy                      = false;       // 2 Coral Signal

input bool   Inptrei                     = false;       // 3 "Volatility < Coral" Signal

input bool   Inppatry                    = false;       // 4 "Coral < Volatility" Signal

input bool   Inpcinc                     = false;       // 5 Coral Signal Price

input bool   Inpshase                    = false;       // 6 Volatility Signal Price

input bool   Inpshapt                    = false;       // 7 Pivot Signal Price

input group  "---- Filter ----"

input bool   InpFiltryC                  = false;       // Filter Coral

input bool   InpFiltryM                  = false;       // Filter Volatility

input bool   InpFiltryP                  = false;       // Filter Pivot

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

//| Enum Pivot Point                                                 |

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

enum ENUM_PIVOT_POINT

  {

   yesterday      = 0,  // Yesterday's prices only

   yesterday_today= 1,  // Yesterday and today's prices

  };

//--- input parameters

ENUM_PIVOT_POINT  InpPivot    = yesterday;   // Pivot Point:

//---

datetime m_left_time    = 0,        m_right_time    = 0,     m_left_Ctime   = 0,     m_right_Ctime  = 0;

//---

double   m_r2_price     = 0.0,      m_r1_price      = 0.0,   m_s1_price     = 0.0,   m_s2_price     = 0.0,   m_p_price   = 0.0;

//---

double   m_Coral_price  = 0.0,      m_Middle_price  = 0.0,   m_Upper_price  = 0.0,   m_Lower_price  = 0.0;

//---

string   m_r2_name      = "R2";

string   m_r1_name      = "R1";

string   m_s1_name      = "S1";

string   m_s2_name      = "S2";

string   m_p_name       = "P";

//---

string   m_Coral_name   = "Coral";

string   m_Middle_name  = "Middle";

string   m_Upper_name   = "Upper";

string   m_Lower_name   = "Lower";

string   _name[]= {"R2","R1","S1","S2","P","Coral","Middle","Upper","Lower","VSCYesterday","VSCToday"};

//---

string   m_rec_yesterday_name             = "VSCYesterday";

datetime m_rec_yesterday_left_up_time     = 0;

datetime m_rec_yesterday_right_down_time  = 0;

double   m_rec_yesterday_left_up_price    = 0.0;

double   m_rec_yesterday_right_down_price = 0.0;

//---

string   m_rec_today_name                 = "VSCToday";

datetime m_rec_today_left_up_time         = 0;

datetime m_rec_today_right_down_time      = 0;

double   m_rec_today_left_up_price        = 0.0;

double   m_rec_today_right_down_price     = 0.0;

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

int InpFastPeriod=int(InpVolatilityPeriod/7); //  Fast Period

int InpMode=2; //  1:Simple Mode 2:hybrid Mode

ENUM_MA_METHOD InpMaMethod=MODE_SMMA; // Ma Method

//---- will be used as indicator buffers

double UpArrowiCustom[];

double DnArrowiCustom[];

double BufferC[];

double BufferColors[];

double BufferCcop[];

double BufferColorscop[];

double BufferB1cop[];

double BufferB2cop[];

double BufferB3cop[];

double BufferB4cop[];

double BufferB5cop[];

double BufferB6cop[];

double BufferMAcop[];

//---

double UpperBuffer[];

double MiddleBuffer[];

double LowerBuffer[];

//---

double UpperMaBuffer[];

double MiddleMaBuffer[];

double LowerMaBuffer[];

//---

double BaseBuffer[];

//---

double HighBuffer[];

double LowBuffer[];

double CloseBuffer[];

double StdDevBuffer[];

double StdDevCalcBuffer[];

//---- declaration of global variables

double coeff1cop;

double coeff2cop;

int    handle_iCustomcop,min_rates_total,z,Z_,OldTrend;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- create a timer with a 1 second period

   TrendCreate(0,m_r2_name,clrDeepSkyBlue,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_r1_name,clrDeepSkyBlue,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_s1_name,clrRed,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_s2_name,clrRed,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_p_name,clrOrange,STYLE_DOT,1);

   RectangleCreate(0,m_rec_yesterday_name,StringToColor("11,17,17"),STYLE_DOT,1,0,0,0,0,0,true);

   RectangleCreate(0,m_rec_today_name,StringToColor("11,17,17"),STYLE_DOT,1,0,0,0,0,0,true);

//---

   TrendCreate(0,m_Coral_name,clrSienna,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_Middle_name,clrDeepPink,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_Upper_name,clrDarkGray,STYLE_DASHDOTDOT,1);

   TrendCreate(0,m_Lower_name,clrDarkGray,STYLE_DASHDOTDOT,1);

//---

   coeff1cop=(InpCoeffcop<=0.0086 ? 0.0086 : InpCoeffcop>1 ? 1: InpCoeffcop);

   coeff2cop=1.0-coeff1cop;

//---- Initialization of variables of data calculation starting point

   min_rates_total=1+InpFastPeriod+InpVolatilityPeriod+InpMaPeriod+InpMaPeriod+1;

//--- indicator buffers mapping

   SetIndexBuffer(0,UpArrowiCustom,INDICATOR_DATA);

   PlotIndexSetInteger(0,PLOT_ARROW,159);

   ArraySetAsSeries(UpArrowiCustom,true);

   SetIndexBuffer(1,DnArrowiCustom,INDICATOR_DATA);

   PlotIndexSetInteger(1,PLOT_ARROW,159);

   ArraySetAsSeries(DnArrowiCustom,true);

//---

   SetIndexBuffer(2,MiddleMaBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,BufferColors,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4,UpperMaBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,LowerMaBuffer,INDICATOR_DATA);

   SetIndexBuffer(6,BufferCcop,INDICATOR_DATA);

   SetIndexBuffer(7,BufferColorscop,INDICATOR_COLOR_INDEX);

//---

   SetIndexBuffer(8,UpperBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(9,BaseBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(10,MiddleBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(11,LowerBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(12,HighBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(13,LowBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(14,CloseBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(15,StdDevBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(16,StdDevCalcBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(17,BufferC,INDICATOR_CALCULATIONS);

   SetIndexBuffer(18,BufferB1cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(19,BufferB2cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(20,BufferB3cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(21,BufferB4cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(22,BufferB5cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(23,BufferB6cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(24,BufferMAcop,INDICATOR_CALCULATIONS);

//---

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(8,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(9,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(10,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(11,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(12,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(13,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(14,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(15,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(16,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(17,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(18,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(19,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(20,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(21,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(22,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(23,PLOT_EMPTY_VALUE,0);

   PlotIndexSetDouble(24,PLOT_EMPTY_VALUE,0);

//---

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,min_rates_total);

   PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,min_rates_total);

//---

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);

   string short_name="Volatility StepChannel";

//---

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//--- create iCustom handlecop

   ResetLastError();

   handle_iCustomcop=iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,InpAppliedPrice);

   if(handle_iCustomcop==INVALID_HANDLE)

     {

      Print("The iCustom(2) object was not created: Error ",GetLastError());

      return INIT_FAILED;

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| Indicator deinitialization function                              |

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

void OnDeinit(const int reason)

  {

   for(int i=0; i<ArraySize(_name); i++)

     {

      ObjectDelete(0,_name[i]);

     };

//--- removes all objects of the specified type using prefix in object names

  }

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

//| 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 i,j,first,limit;

   bool CoralUp,CoralDn;

//--- check for bars count

   if(rates_total<=min_rates_total)

      return(0);

//---

   MathSrand(int(TimeLocal()));

//--- indicator buffers

   ArraySetAsSeries(UpperMaBuffer,false);

   ArraySetAsSeries(LowerMaBuffer,false);

   ArraySetAsSeries(MiddleMaBuffer,false);

   ArraySetAsSeries(UpperBuffer,false);

   ArraySetAsSeries(LowerBuffer,false);

   ArraySetAsSeries(MiddleBuffer,false);

   ArraySetAsSeries(HighBuffer,false);

   ArraySetAsSeries(LowBuffer,false);

   ArraySetAsSeries(CloseBuffer,false);

   ArraySetAsSeries(StdDevBuffer,false);

   ArraySetAsSeries(BaseBuffer,false);

//--- rate data

   ArraySetAsSeries(high,false);

   ArraySetAsSeries(low,false);

   ArraySetAsSeries(close,false);

   ArraySetAsSeries(time,false);

//---

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

//| Set Median Buffeer                                 |

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

   first=InpFastPeriod+InpVolatilityPeriod+InpMaPeriod+InpMaPeriod;

   if(first+1<prev_calculated)

      first=prev_calculated-2;

   else

     {

      for(i=0; i<first; i++)

        {

         MiddleBuffer[i]=close[i];

         HighBuffer[i]=high[i];

         LowBuffer[i]=low[i];

        }

     }

//---

   for(i=first; i<rates_total && !IsStopped(); i++)

     {

      StdDevBuffer[i]=calcStdDev(close,InpFastPeriod,i);

      //---

      double h,l,c,hsum=0.0,lsum=0.0,csum=0.0;

      //---

      for(j=0; j<InpMaPeriod; j++)

        {

         hsum += high[i-j];

         lsum += low[i-j];

         csum += close[i-j];

        }

      //---

      h=hsum/InpMaPeriod;

      l=lsum/InpMaPeriod;

      c=csum/InpMaPeriod;

      //--- Base Volatility

      double sd=0.0;

      for(j=(i-InpVolatilityPeriod+1); j<=i; j++)

         sd+=StdDevBuffer[j];

      //--- Ma Buffer

      double v=sd/InpVolatilityPeriod;

      BaseBuffer[i]=v;

      double base=v*InpScaleFactor;

      //--- Hybrid Mode

      if((h-base)>HighBuffer[i-1])

         HighBuffer[i]=h;

      else

         if(h+base<HighBuffer[i-1])

            HighBuffer[i]=h+base;

         else

            HighBuffer[i]=HighBuffer[i-1];

      //---

      if(l+base<LowBuffer[i-1])

         LowBuffer[i]=l;

      else

         if((l-base)>LowBuffer[i-1])

            LowBuffer[i]=l-base;

         else

            LowBuffer[i]=LowBuffer[i-1];

      //---

      if((c-base/2)>CloseBuffer[i-1])

         CloseBuffer[i]=c-base/2;

      else

         if(c+base/2<CloseBuffer[i-1])

            CloseBuffer[i]=c+base/2;

         else

            CloseBuffer[i]=CloseBuffer[i-1];

      //---

      MiddleBuffer[i]=(HighBuffer[i]+LowBuffer[i]+CloseBuffer[i]*2)/4;

      UpperBuffer[i]=HighBuffer[i] + base/2;

      LowerBuffer[i]=LowBuffer[i]  - base/2;

      //---

      hsum=0.0;

      lsum=0.0;

      csum=0.0;

      //---

      for(j=0; j<InpMaPeriod; j++)

        {

         hsum += UpperBuffer[i-j];

         lsum += LowerBuffer[i-j];

         csum += MiddleBuffer[i-j];

        }

      //---

      UpperMaBuffer[i]=hsum/InpMaPeriod;

      LowerMaBuffer[i]=lsum/InpMaPeriod;

      MiddleMaBuffer[i]=csum/InpMaPeriod;

      m_Middle_price = MiddleMaBuffer[i];

      m_Upper_price  = UpperMaBuffer[i];

      m_Lower_price  = LowerMaBuffer[i];

     }

//---

   limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-2;

      ArrayInitialize(BufferC,EMPTY_VALUE);

      ArrayInitialize(BufferColors,2);

     }

   ArraySetAsSeries(BufferC,true);

   ArraySetAsSeries(BufferColors,true);

   ArraySetAsSeries(UpperMaBuffer,true);

   ArraySetAsSeries(LowerMaBuffer,true);

   ArraySetAsSeries(MiddleMaBuffer,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   for(i=limit; i>=0 && !IsStopped(); i--)

     {

      if(i==rates_total-2)

         BufferC[i]=MiddleMaBuffer[i];

      else

        {

         BufferC[i]=MiddleMaBuffer[i];

         BufferColors[i]=(BufferC[i]>BufferC[i+1] ? 0 : BufferC[i]<BufferC[i+1] ? 1 : 2);

        }

     }

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   if(limit>1)

     {

      limit=rates_total-2;

      ArrayInitialize(BufferCcop,EMPTY_VALUE);

      ArrayInitialize(BufferColorscop,2);

      ArrayInitialize(BufferB1cop,0);

      ArrayInitialize(BufferB2cop,0);

      ArrayInitialize(BufferB3cop,0);

      ArrayInitialize(BufferB4cop,0);

      ArrayInitialize(BufferB5cop,0);

      ArrayInitialize(BufferB6cop,0);

      ArrayInitialize(BufferMAcop,0);

     }

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferCcop,true);

   ArraySetAsSeries(BufferColorscop,true);

   ArraySetAsSeries(BufferB1cop,true);

   ArraySetAsSeries(BufferB2cop,true);

   ArraySetAsSeries(BufferB3cop,true);

   ArraySetAsSeries(BufferB4cop,true);

   ArraySetAsSeries(BufferB5cop,true);

   ArraySetAsSeries(BufferB6cop,true);

   ArraySetAsSeries(BufferMAcop,true);

//---

//--- >43>B>2:0 40==KE

   int count=(limit>1 ? rates_total : 1);

   int copied=CopyBuffer(handle_iCustomcop,0,0,count,BufferMAcop);

   if(copied!=count)

      return 0;

//---  0AGQB 8=48:0B>@0

   for(i=limit; i>=0 && !IsStopped(); i--)

     {

      if(i==rates_total-2)

         BufferB1cop[i]=BufferB2cop[i]=BufferB3cop[i]=BufferB4cop[i]=BufferB5cop[i]=BufferB6cop[i]=BufferMAcop[i];

      else

        {

         BufferB1cop[i]=coeff1cop*BufferMAcop[i]+coeff2cop*BufferB1cop[i+1];

         BufferB2cop[i]=coeff1cop*BufferB1cop[i]+coeff2cop*BufferB2cop[i+1];

         BufferB3cop[i]=coeff1cop*BufferB2cop[i]+coeff2cop*BufferB3cop[i+1];

         BufferB4cop[i]=coeff1cop*BufferB3cop[i]+coeff2cop*BufferB4cop[i+1];

         BufferB5cop[i]=coeff1cop*BufferB4cop[i]+coeff2cop*BufferB5cop[i+1];

         BufferB6cop[i]=coeff1cop*BufferB5cop[i]+coeff2cop*BufferB6cop[i+1];

         BufferCcop[i]=(-0.064)*BufferB6cop[i]+0.672*BufferB5cop[i]-2.352*BufferB4cop[i]+2.744*BufferB3cop[i];

         BufferColorscop[i]=(BufferCcop[i]>BufferCcop[i+1] && BufferMAcop[i]>BufferCcop[i] ? 0 :

                             BufferCcop[i]<BufferCcop[i+1] && BufferMAcop[i]<BufferCcop[i] ? 1 : 2);

         m_Coral_price  = BufferCcop[i];

        }

     }

//---

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

//---

   z=Z_;

   for(i=limit; i>=0; i--)

     {

      if(!CalculatePivot())

         return(0);

      if(rates_total!=prev_calculated && i==0)

         Z_=z;

      //---

      DnArrowiCustom[i]=0.0;

      UpArrowiCustom[i]=0.0;

      CoralDn=((Inpyna && BufferC[i]<BufferC[i+1]) || (Inpdoy && BufferCcop[i]<BufferCcop[i+1]) ||

               (Inptrei && BufferC[i]<BufferCcop[i]) || (Inppatry && BufferCcop[i]<BufferC[i]) ||

               (Inpcinc && close[i]<m_Coral_price) || (Inpshase && close[i]<BufferC[i]) || (Inpshapt && close[i]<m_p_price));

      CoralUp=((Inpyna && BufferC[i]>BufferC[i+1]) || (Inpdoy && BufferCcop[i]>BufferCcop[i+1]) ||

               (Inptrei && BufferC[i]>BufferCcop[i]) || (Inppatry && BufferCcop[i]>BufferC[i]) ||

               (Inpcinc && close[i]>m_Coral_price) || (Inpshase && close[i]>BufferC[i]) || (Inpshapt && close[i]>m_p_price));

      if(CoralDn)

         z = 1;

      if(CoralUp)

         z = 2;

      if(CoralDn && (z==1 || z==0))

        {

         if(((InpFiltryP && close[i]<m_p_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||

            ((InpFiltryC && close[i]<m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||

            ((InpFiltryM && close[i]<m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)))

            if(OldTrend>0)

               UpArrowiCustom[i]=high[i];

         if(i!=0)

            OldTrend=-1;

        }

      if(CoralUp && (z==2 || z==0))

        {

         if(((InpFiltryP && close[i]>m_p_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||

            ((InpFiltryC && close[i]>m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)) ||

            ((InpFiltryM && close[i]>m_Coral_price) || (!InpFiltryP && !InpFiltryM && !InpFiltryC)))

            if(OldTrend<0)

               DnArrowiCustom[i]=low[i];

         if(i!=0)

            OldTrend=+1;

        }

     }

   m_left_Ctime=time[rates_total-2];

//---

   if(prev_calculated==0)

     {

      if(!CalculatePivot())

         return(0);

      //---

      TrendPointChange(0,m_r2_name,1,m_left_time,m_r2_price);

      TrendPointChange(0,m_r2_name,0,m_right_time,m_r2_price);

      //---

      TrendPointChange(0,m_r1_name,1,m_left_time,m_r1_price);

      TrendPointChange(0,m_r1_name,0,m_right_time,m_r1_price);

      //---

      TrendPointChange(0,m_s1_name,1,m_left_time,m_s1_price);

      TrendPointChange(0,m_s1_name,0,m_right_time,m_s1_price);

      //---

      TrendPointChange(0,m_s2_name,1,m_left_time,m_s2_price);

      TrendPointChange(0,m_s2_name,0,m_right_time,m_s2_price);

      //---

      TrendPointChange(0,m_p_name,1,m_left_time,m_p_price);

      TrendPointChange(0,m_p_name,0,m_right_time,m_p_price);

      //---

      RectanglePointChange(0,m_rec_yesterday_name,1,m_rec_yesterday_left_up_time,m_rec_yesterday_left_up_price);

      RectanglePointChange(0,m_rec_yesterday_name,0,m_rec_yesterday_right_down_time,m_rec_yesterday_right_down_price);

      //---

      RectanglePointChange(0,m_rec_today_name,1,m_rec_today_left_up_time,m_rec_today_left_up_price);

      RectanglePointChange(0,m_rec_today_name,0,m_rec_today_right_down_time,m_rec_today_right_down_price);

      //---

      TrendPointChange(0,m_Coral_name,1,m_left_Ctime,m_Coral_price);

      TrendPointChange(0,m_Coral_name,0,m_right_time,m_Coral_price);

      //---

      TrendPointChange(0,m_Middle_name,1,m_left_Ctime,m_Middle_price);

      TrendPointChange(0,m_Middle_name,0,m_right_time,m_Middle_price);

      //---

      TrendPointChange(0,m_Upper_name,1,m_left_Ctime,m_Upper_price);

      TrendPointChange(0,m_Upper_name,0,m_right_time,m_Upper_price);

      //---

      TrendPointChange(0,m_Lower_name,1,m_left_Ctime,m_Lower_price);

      TrendPointChange(0,m_Lower_name,0,m_right_time,m_Lower_price);

      //---

      return(rates_total);

     }

//---

   if(!CalculatePivot())

      return(0);

//---

   TrendPointChange(0,m_r2_name,0,m_left_time,m_r2_price);

   TrendPointChange(0,m_r2_name,1,m_right_time,m_r2_price);

//---

   TrendPointChange(0,m_r1_name,0,m_left_time,m_r1_price);

   TrendPointChange(0,m_r1_name,1,m_right_time,m_r1_price);

//---

   TrendPointChange(0,m_s1_name,0,m_left_time,m_s1_price);

   TrendPointChange(0,m_s1_name,1,m_right_time,m_s1_price);

//---

   TrendPointChange(0,m_s2_name,0,m_left_time,m_s2_price);

   TrendPointChange(0,m_s2_name,1,m_right_time,m_s2_price);

//---

   TrendPointChange(0,m_p_name,0,m_left_time,m_p_price);

   TrendPointChange(0,m_p_name,1,m_right_time,m_p_price);

//---

   RectanglePointChange(0,m_rec_yesterday_name,1,m_rec_yesterday_left_up_time,m_rec_yesterday_left_up_price);

   RectanglePointChange(0,m_rec_yesterday_name,0,m_rec_yesterday_right_down_time,m_rec_yesterday_right_down_price);

//---

   RectanglePointChange(0,m_rec_today_name,1,m_rec_today_left_up_time,m_rec_today_left_up_price);

   RectanglePointChange(0,m_rec_today_name,0,m_rec_today_right_down_time,m_rec_today_right_down_price);

//---

   TrendPointChange(0,m_Coral_name,0,m_left_Ctime,m_Coral_price);

   TrendPointChange(0,m_Coral_name,1,m_right_time,m_Coral_price);

//---

   TrendPointChange(0,m_Middle_name,0,m_left_Ctime,m_Middle_price);

   TrendPointChange(0,m_Middle_name,1,m_right_time,m_Middle_price);

//---

   TrendPointChange(0,m_Upper_name,0,m_left_Ctime,m_Upper_price);

   TrendPointChange(0,m_Upper_name,1,m_right_time,m_Upper_price);

//---

   TrendPointChange(0,m_Lower_name,0,m_left_Ctime,m_Lower_price);

   TrendPointChange(0,m_Lower_name,1,m_right_time,m_Lower_price);

//----

   return(rates_total);

  }

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

//|                                                                  |

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

double calcStdDev(const double  &close[],int span,int i)

  {

   if(i<span-1)

      return 0.0;

//---

   if(i==span-1)

      StdDevCalcBuffer[i]=SimpleMA(i,span,close);

   else

      StdDevCalcBuffer[i]=SmoothedMA(i,span,StdDevCalcBuffer[i-1],close);

//---

   double sum=0.0;

   for(int j=0; j<span; j++)

      sum+=MathPow(close[i-j]-StdDevCalcBuffer[i],2);

   return MathSqrt(sum/span);

  }

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

//| Calculate Pivot                                                  |

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

bool CalculatePivot(void)

  {

//---

   MqlRates rates_d1[],rates_h1[],rates_m1[];

   ArraySetAsSeries(rates_d1,true);

   ArraySetAsSeries(rates_h1,true);

   ArraySetAsSeries(rates_m1,true);

   int start_pos=0;

   int count=6;

   if(CopyRates(Symbol(),PERIOD_D1,start_pos,count,rates_d1)<count)

      return(false);

   /*

      R2=P+(H-L)=P+(R1-S1)

      R1=(P*2)-L

      S1=(P*2)-H

      S2=P-(H-L)=P-(R1-S1)

      P=(H+L+C)/3 OR P=(Today's O+Yesterday's (H+L+C))/4



      m_r2_price - 1.17233

      |

      m_r1_price - 1.16515

      |

      m_s1_price - 1.15460

      |

      m_s2_price - 1.15123

   */

   if(InpPivot==yesterday)

      m_p_price                        = (rates_d1[1].high+rates_d1[1].low+rates_d1[1].close)/3.0;

   else

      m_p_price=(rates_d1[0].open+(rates_d1[1].high+rates_d1[1].low+rates_d1[1].close))/4.0;

//---

   m_rec_yesterday_left_up_time     = rates_d1[1].time;

   m_rec_yesterday_right_down_time  = rates_d1[0].time;

   m_rec_yesterday_left_up_price    = rates_d1[1].high;

   m_rec_yesterday_right_down_price = rates_d1[1].low;

//---

   m_rec_today_left_up_time         = rates_d1[0].time;

   m_rec_today_right_down_time      = TimeCurrent();

   m_rec_today_left_up_price        = rates_d1[0].high;

   m_rec_today_right_down_price     = rates_d1[0].low;

//---

   m_s2_price  = m_p_price-(rates_d1[1].high-rates_d1[1].low);

   m_s1_price  = (m_p_price*2.0)-rates_d1[1].high;

   m_r1_price  = (m_p_price*2.0)-rates_d1[1].low;

   m_r2_price  = m_p_price+(rates_d1[1].high-rates_d1[1].low);

//---

   m_left_time=(InpPivot==yesterday)?rates_d1[0].time:rates_d1[1].time;

   m_right_time=TimeCurrent();

//---

   return(true);

  }

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

//| Create a trend line by the given coordinates                     |

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

bool TrendCreate(const long            chart_ID=0,        // chart's ID

                 const string          name="TrendLine",  // line name

                 const color           clr=clrRed,        // line color

                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style

                 const int             width=1,           // line width

                 const int             sub_window=0,      // subwindow index

                 datetime              time1=0,           // first point time

                 double                price1=0,          // first point price

                 datetime              time2=0,           // second point time

                 double                price2=0,          // second point price

                 const bool            back=false,        // in the background

                 const bool            selection=false,   // highlight to move

                 const bool            ray_left=false,    // line's continuation to the left

                 const bool            ray_right=true,    // line's continuation to the right

                 const bool            hidden=true,       // hidden in the object list

                 const long            z_order=0)         // priority for mouse click

  {

//--- set anchor points' coordinates if they are not set

   ChangeTrendEmptyPoints(time1,price1,time2,price2);

//--- reset the error value

   ResetLastError();

//--- create a trend line by the given coordinates

   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2))

     {

      Print(__FUNCTION__,

            ": failed to create a trend line! Error code = ",GetLastError());

      return(false);

     }

//--- set line color

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- set line display style

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- set line width

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- display in the foreground (false) or background (true)

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- enable (true) or disable (false) the mode of moving the line by mouse

//--- when creating a graphical object using ObjectCreate function, the object cannot be

//--- highlighted and moved by default. Inside this method, selection parameter

//--- is true by default making it possible to highlight and move the object

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- enable (true) or disable (false) the mode of continuation of the line's display to the left

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left);

//--- enable (true) or disable (false) the mode of continuation of the line's display to the right

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);

//--- hide (true) or display (false) graphical object name in the object list

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- set the text

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,name);

//--- successful execution

   return(true);

  }

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

//| Move trend line anchor point                                     |

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

bool TrendPointChange(const long   chart_ID=0,       // chart's ID

                      const string name="TrendLine", // line name

                      const int    point_index=0,    // anchor point index

                      datetime     time=0,           // anchor point time coordinate

                      double       price=0)          // anchor point price coordinate

  {

//--- if point position is not set, move it to the current bar having Bid price

   if(!time)

      time=TimeCurrent();

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- reset the error value

   ResetLastError();

//--- move trend line's anchor point

   if(!ObjectMove(chart_ID,name,point_index,time,price))

     {

      Print(__FUNCTION__,

            ": failed to move the anchor point! Error code = ",GetLastError());

      return(false);

     }

//--- successful execution

   return(true);

  }

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

//| Check the values of trend line's anchor points and set default   |

//| values for empty ones                                            |

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

void ChangeTrendEmptyPoints(datetime &time1,double &price1,

                            datetime &time2,double &price2)

  {

//--- if the first point's time is not set, it will be on the current bar

   if(!time1)

      time1=TimeCurrent();

//--- if the first point's price is not set, it will have Bid value

   if(!price1)

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- if the second point's time is not set, it is located 9 bars left from the second one

   if(!time2)

     {

      //--- array for receiving the open time of the last 10 bars

      datetime temp[10];

      CopyTime(Symbol(),Period(),time1,10,temp);

      //--- set the second point 9 bars left from the first one

      time2=temp[0];

     }

//--- if the second point's price is not set, it is equal to the first point's one

   if(!price2)

      price2=price1;

  }

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

//| Create rectangle by the given coordinates                        |

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

bool RectangleCreate(const long            chart_ID=0,        // chart's ID

                     const string          name="Rectangle",  // rectangle name

                     const color           clr=clrRed,        // rectangle color

                     const ENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines

                     const int             width=1,           // width of rectangle lines

                     const int             sub_window=0,      // subwindow index

                     datetime              time1=0,           // first point time

                     double                price1=0,          // first point price

                     datetime              time2=0,           // second point time

                     double                price2=0,          // second point price

                     const bool            fill=false,        // filling rectangle with color

                     const bool            back=false,        // in the background

                     const bool            selection=false,   // highlight to move

                     const bool            hidden=true,       // hidden in the object list

                     const long            z_order=0)         // priority for mouse click

  {

//--- set anchor points' coordinates if they are not set

   ChangeRectangleEmptyPoints(time1,price1,time2,price2);

//--- reset the error value

   ResetLastError();

//--- create a rectangle by the given coordinates

   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))

     {

      Print(__FUNCTION__,

            ": failed to create a rectangle! Error code = ",GetLastError());

      return(false);

     }

//--- set rectangle color

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- set the style of rectangle lines

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- set width of the rectangle lines

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- enable (true) or disable (false) the mode of filling the rectangle

   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);

//--- display in the foreground (false) or background (true)

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- enable (true) or disable (false) the mode of highlighting the rectangle for moving

//--- when creating a graphical object using ObjectCreate function, the object cannot be

//--- highlighted and moved by default. Inside this method, selection parameter

//--- is true by default making it possible to highlight and move the object

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- hide (true) or display (false) graphical object name in the object list

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- set the text

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,name);

//--- successful execution

   return(true);

  }

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

//| Move the rectangle anchor point                                  |

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

bool RectanglePointChange(const long   chart_ID=0,       // chart's ID

                          const string name="Rectangle", // rectangle name

                          const int    point_index=0,    // anchor point index

                          datetime     time=0,           // anchor point time coordinate

                          double       price=0)          // anchor point price coordinate

  {

//--- if point position is not set, move it to the current bar having Bid price

   if(!time)

      time=TimeCurrent();

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- reset the error value

   ResetLastError();

//--- move the anchor point

   if(!ObjectMove(chart_ID,name,point_index,time,price))

     {

      Print(__FUNCTION__,

            ": failed to move the anchor point! Error code = ",GetLastError());

      return(false);

     }

//--- successful execution

   return(true);

  }

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

//| Check the values of rectangle's anchor points and set default    |

//| values for empty ones                                            |

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

void ChangeRectangleEmptyPoints(datetime &time1,double &price1,

                                datetime &time2,double &price2)

  {

//--- if the first point's time is not set, it will be on the current bar

   if(!time1)

      time1=TimeCurrent();

//--- if the first point's price is not set, it will have Bid value

   if(!price1)

      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- if the second point's time is not set, it is located 9 bars left from the second one

   if(!time2)

     {

      //--- array for receiving the open time of the last 10 bars

      datetime temp[10];

      CopyTime(Symbol(),Period(),time1,10,temp);

      //--- set the second point 9 bars left from the first one

      time2=temp[0];

     }

//--- if the second point's price is not set, move it 300 points lower than the first one

   if(!price2)

      price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---