Two Coral Pivot

Author: Copyright 2020, MetaQuotes Software Corp.
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
Two Coral Pivot
ÿþ//+------------------------------------------------------------------+

//|                                              Two Coral Pivot.mq5 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

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

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

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

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

#property version   "1.001"

#property description "Two Coral Pivot indicator"

#property indicator_chart_window

#property indicator_buffers 39

#property indicator_plots   5

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrMagenta

#property indicator_width1  2

#property indicator_label1  "Two Coral Pivot Sell"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrLime

#property indicator_width2  2

#property indicator_label2  "Two Coral Pivot Buy"

//--- plot Pivot

#property indicator_label3  "Coral Pivot"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrDarkOrange

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- plot C

#property indicator_label4  "Coral"

#property indicator_type4   DRAW_COLOR_LINE

#property indicator_color4  clrGreen,clrRed,clrDarkGray

#property indicator_style4  STYLE_SOLID

#property indicator_width4  2

//--- plot Ccop

#property indicator_label5  "Coralcop"

#property indicator_type5   DRAW_COLOR_LINE

#property indicator_color5  clrLightSeaGreen,clrWheat,clrDarkGray

#property indicator_style5  STYLE_SOLID

#property indicator_width5  2

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

input bool               Inpyna             = false;          // 1 Coral>Coralcop Signal

input bool               Inpdoy             = true;           // 2 Coralcop Signal

input bool               Inptrei            = false;          // 3 Coral Signal Price

input bool               Inppatry           = false;          // 4 Pivot Signal Price

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

input bool               InpFiltryC         = false;          // Filter Coral

input bool               InpFiltryP         = false;          // Filter Pivot

input group             "---- Coral ----"

input double             InpCoeff           = 0.06349206;     // Coefficient

input ENUM_APPLIED_PRICE InpAppliedPrice    = PRICE_CLOSE;    // Applied price

input string             InpCoralHline       = "Coral";       // "Color Line": name

input color              InpCoralColor       = clrNONE;       // "Color Line": color

input group             "---- Coralcop ----"

input double             InpCoeffcop        = 0.31;           // Coefficient

input ENUM_APPLIED_PRICE InpAppliedPricecop = PRICE_CLOSE;    // Applied price

input string             InpCoralcopHline   = "Coralcop";     // "Color Line": name

input color              InpCoralcopColor   = clrNONE;        // "Color Line": color

input group             "---- Pivot Line ----"

input int                DayStartHour       = 0;              // Hour of day start

input int                DayStartMinute     = 0;              // Minute of day start

input bool               PivotsBufers       = false;          // Show the Pivot levels as the indicator bufers

input bool               AttachSundToMond   = true;           // Attach the sunday bars to monday

input string             InpS2Hline         = "S2 Line";      // "S2 Line": name

input string             InpR2Hline         = "R2 Line";      // "R2 Line": name

input string             InpPivotHline      = "Pivot Line";   // "Pivot Line": name

input color              InpS2Color         = clrRed;         // "S2 Line": color

input color              InpR2Color         = clrDeepSkyBlue; // "R2 Line": color

input color              InpPivotColor      = clrOrange;      // "Pivot Line": color

//--- indicator buffers

double SellBuffer[];

double BuyBuffer[];

double BufferC[];

double BufferColors[];

double BufferB1[];

double BufferB2[];

double BufferB3[];

double BufferB4[];

double BufferB5[];

double BufferB6[];

double BufferMA[];

double BufferCcop[];

double BufferColorscop[];

double BufferB1cop[];

double BufferB2cop[];

double BufferB3cop[];

double BufferB4cop[];

double BufferB5cop[];

double BufferB6cop[];

double BufferMAcop[];

double PivotBuffer[];

double S1Buffer[];

double R1Buffer[];

double S2Buffer[];

double R2Buffer[];

double S3Buffer[];

double R3Buffer[];

double M0Buffer[];

double M1Buffer[];

double M2Buffer[];

double M3Buffer[];

double M4Buffer[];

double M5Buffer[];

double H3Buffer[];

double L3Buffer[];

double H4Buffer[];

double L4Buffer[];

double BufHigh[];

double BufLow[];

//--- global variables

int      handle_ma,handle_macop,min_rates_total,z,Z_,OldTrend;

bool     Redr;

datetime TimeShift;

double   coeff1,coeff2,coeff1cop,coeff2cop;

double   P,R1,S1,R2,S2,R3,S3,Q,H4,H3,L3,L4,M5,M4,M3,M2,M1,M0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//---

   CreateHline(0,0,InpCoralHline,0,InpCoralColor,1,STYLE_DOT,0,true,false,false,OBJ_ALL_PERIODS);

   CreateHline(0,0,InpCoralcopHline,0,InpCoralcopColor,1,STYLE_DOT,0,true,false,false,OBJ_ALL_PERIODS);

   CreateHline(0,0,InpS2Hline,0,InpS2Color,1,STYLE_DOT,0,true,false,false,OBJ_ALL_PERIODS);

   CreateHline(0,0,InpR2Hline,0,InpR2Color,1,STYLE_DOT,0,true,false,false,OBJ_ALL_PERIODS);

   CreateHline(0,0,InpPivotHline,0,InpPivotColor,1,STYLE_DOT,0,true,false,false,OBJ_ALL_PERIODS);

   TimeShift=DayStartHour*3600+DayStartMinute*60;

//---- 8=8F80;870F8O 3;>10;L=KE ?5@5<5==KE

   min_rates_total=MathMax(4,1)+2;

//--- set global variables

   coeff1=(InpCoeff<=0.0086 ? 0.0086 : InpCoeff>1 ? 1: InpCoeff);

   coeff2=1.0-coeff1;

//--- set global variables

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

   coeff2cop=1.0-coeff1cop;

//--- indicator buffers mapping

   SetIndexBuffer(2,PivotBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,BufferC,INDICATOR_DATA);

   SetIndexBuffer(4,BufferColors,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(5,BufferCcop,INDICATOR_DATA);

   SetIndexBuffer(6,BufferColorscop,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(7,BufferB1,INDICATOR_CALCULATIONS);

   SetIndexBuffer(8,BufferB2,INDICATOR_CALCULATIONS);

   SetIndexBuffer(9,BufferB3,INDICATOR_CALCULATIONS);

   SetIndexBuffer(10,BufferB4,INDICATOR_CALCULATIONS);

   SetIndexBuffer(11,BufferB5,INDICATOR_CALCULATIONS);

   SetIndexBuffer(12,BufferB6,INDICATOR_CALCULATIONS);

   SetIndexBuffer(13,BufferMA,INDICATOR_CALCULATIONS);

//--- indicator buffers mapping

   SetIndexBuffer(14,BufferB1cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(15,BufferB2cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(16,BufferB3cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(17,BufferB4cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(18,BufferB5cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(19,BufferB6cop,INDICATOR_CALCULATIONS);

   SetIndexBuffer(20,BufferMAcop,INDICATOR_CALCULATIONS);

//--- indicator buffers mapping

   SetIndexBuffer(21,S1Buffer,INDICATOR_DATA);

   SetIndexBuffer(22,R1Buffer,INDICATOR_DATA);

   SetIndexBuffer(23,S2Buffer,INDICATOR_DATA);

   SetIndexBuffer(24,R2Buffer,INDICATOR_DATA);

   SetIndexBuffer(25,S3Buffer,INDICATOR_DATA);

   SetIndexBuffer(26,R3Buffer,INDICATOR_DATA);

   SetIndexBuffer(27,M0Buffer,INDICATOR_DATA);

   SetIndexBuffer(28,M1Buffer,INDICATOR_DATA);

   SetIndexBuffer(29,M2Buffer,INDICATOR_DATA);

   SetIndexBuffer(30,M3Buffer,INDICATOR_DATA);

   SetIndexBuffer(31,M4Buffer,INDICATOR_DATA);

   SetIndexBuffer(32,M5Buffer,INDICATOR_DATA);

   SetIndexBuffer(33,L3Buffer,INDICATOR_DATA);

   SetIndexBuffer(34,H3Buffer,INDICATOR_DATA);

   SetIndexBuffer(35,L4Buffer,INDICATOR_DATA);

   SetIndexBuffer(36,H4Buffer,INDICATOR_DATA);

   SetIndexBuffer(37,BufHigh,INDICATOR_CALCULATIONS);

   SetIndexBuffer(38,BufLow,INDICATOR_CALCULATIONS);

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferC,true);

   ArraySetAsSeries(BufferColors,true);

   ArraySetAsSeries(BufferB1,true);

   ArraySetAsSeries(BufferB2,true);

   ArraySetAsSeries(BufferB3,true);

   ArraySetAsSeries(BufferB4,true);

   ArraySetAsSeries(BufferB5,true);

   ArraySetAsSeries(BufferB6,true);

   ArraySetAsSeries(BufferMA,true);

//--- 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);

//--- create MA handle

   ResetLastError();

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

   if(handle_ma==INVALID_HANDLE)

     {

      Print("The iMA(1) object was not created: Error ",GetLastError());

      return INIT_FAILED;

     }

//--- create MA handlecop

   ResetLastError();

   handle_macop=iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,InpAppliedPricecop);

   if(handle_macop==INVALID_HANDLE)

     {

      Print("The iMA(1) object was not created: Error ",GetLastError());

      return INIT_FAILED;

     }

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 SellBuffer[] 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,SellBuffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 1

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- A8<2>; 4;O 8=48:0B>@0

   PlotIndexSetInteger(0,PLOT_ARROW,119);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5, :0: 2 B09<A5@88

   ArraySetAsSeries(SellBuffer,true);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 BuyBuffer[] 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(1,BuyBuffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 2

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//---- A8<2>; 4;O 8=48:0B>@0

   PlotIndexSetInteger(1,PLOT_ARROW,119);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5, :0: 2 B09<A5@88

   ArraySetAsSeries(BuyBuffer,true);

//---- CAB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 8<O 4;O >:>= 40==KE 8 <5B:0 4;O ?>4>:>=

   string short_name="Two Coral Pivot";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//---

   return(INIT_SUCCEEDED);

  }

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

//| deinitialization function                                        |

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

void OnDeinit(const int Rason)

  {

   ObjectDelete(0,InpCoralHline);

   ObjectDelete(0,InpCoralcopHline);

   ObjectDelete(0,InpS2Hline);

   ObjectDelete(0,InpR2Hline);

   ObjectDelete(0,InpPivotHline);

   if(Redr)

      ChartRedraw();

  }

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

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

  {

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

   if(rates_total<min_rates_total)

      return 0;

   int  i,limit;

   bool CoralUp,CoralDn;

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

   limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-2;

      ArrayInitialize(BufferC,EMPTY_VALUE);

      ArrayInitialize(BufferColors,2);

      ArrayInitialize(BufferB1,0);

      ArrayInitialize(BufferB2,0);

      ArrayInitialize(BufferB3,0);

      ArrayInitialize(BufferB4,0);

      ArrayInitialize(BufferB5,0);

      ArrayInitialize(BufferB6,0);

      ArrayInitialize(BufferMA,0);

     }

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

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

   int copied=CopyBuffer(handle_ma,0,0,count,BufferMA);

   if(copied!=count)

      return 0;

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

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

     {

      if(i==rates_total-2)

         BufferB1[i]=BufferB2[i]=BufferB3[i]=BufferB4[i]=BufferB5[i]=BufferB6[i]=BufferMA[i];

      else

        {

         BufferB1[i]=coeff1*BufferMA[i]+coeff2*BufferB1[i+1];

         BufferB2[i]=coeff1*BufferB1[i]+coeff2*BufferB2[i+1];

         BufferB3[i]=coeff1*BufferB2[i]+coeff2*BufferB3[i+1];

         BufferB4[i]=coeff1*BufferB3[i]+coeff2*BufferB4[i+1];

         BufferB5[i]=coeff1*BufferB4[i]+coeff2*BufferB5[i+1];

         BufferB6[i]=coeff1*BufferB5[i]+coeff2*BufferB6[i+1];

         BufferC[i]=(-0.064)*BufferB6[i]+0.672*BufferB5[i]-2.352*BufferB4[i]+2.744*BufferB3[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);

     }

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

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

   copied=CopyBuffer(handle_macop,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] ? 0 : BufferCcop[i]<BufferCcop[i+1] ? 1 : 2);

        }

     }

//---

   static bool error=true;

   int start;

   if(prev_calculated==0)

     {

      error=true;

     }

   if(error)

     {

      start=1;

      error=false;

     }

   else

     {

      start=prev_calculated-1;

     }

   for(i=start; i<rates_total; i++)

     {

      BufHigh[i]=BufHigh[i-1];

      BufLow[i]=BufLow[i-1];

      PivotBuffer[i]=PivotBuffer[i-1];

      S1Buffer[i]=S1Buffer[i-1];

      R1Buffer[i]=R1Buffer[i-1];

      S2Buffer[i]=S2Buffer[i-1];

      R2Buffer[i]=R2Buffer[i-1];

      S3Buffer[i]=S3Buffer[i-1];

      R3Buffer[i]=R3Buffer[i-1];

      M0Buffer[i]=M0Buffer[i-1];

      M1Buffer[i]=M1Buffer[i-1];

      M2Buffer[i]=M2Buffer[i-1];

      M3Buffer[i]=M3Buffer[i-1];

      M4Buffer[i]=M4Buffer[i-1];

      M5Buffer[i]=M5Buffer[i-1];

      L3Buffer[i]=L3Buffer[i-1];

      H3Buffer[i]=H3Buffer[i-1];

      L4Buffer[i]=L4Buffer[i-1];

      H4Buffer[i]=H4Buffer[i-1];

      datetime NowTime=time[i]-TimeShift;

      datetime PreTime=time[i-1]-TimeShift;

      if(NewDay(NowTime,PreTime))

        {

         if(BufHigh[i]!=0)

           {

            P=(BufHigh[i]+BufLow[i]+close[i-1])/3;

            R1=(2.0*P)-BufLow[i];

            S1=(2.0*P)-BufHigh[i];

            R2=P+(BufHigh[i]-BufLow[i]);

            S2=P-(BufHigh[i]-BufLow[i]);

            R3=2.0*P+(BufHigh[i]-2.0*BufLow[i]);

            S3=2.0*P-(2.0*BufHigh[i]-BufLow[i]);

            if(PivotsBufers)

              {

               PivotBuffer[i]=P;

               S1Buffer[i]=S1;

               R1Buffer[i]=R1;

               S2Buffer[i]=S2;

               R2Buffer[i]=R2;

               S3Buffer[i]=S3;

               R3Buffer[i]=R3;

              }

            Q=(BufHigh[i]-BufLow[i]);

            H4=(Q*0.55)+close[i-1];

            H3=(Q*0.27)+close[i-1];

            L3=close[i-1]-(Q*0.27);

            L4=close[i-1]-(Q*0.55);

            M5=(R2+R3)/2;

            M4=(R1+R2)/2;

            M3=(P+R1)/2;

            M2=(P+S1)/2;

            M1=(S1+S2)/2;

            M0=(S2+S3)/2;

           }

         BufHigh[i]=high[i];

         BufLow[i]=low[i];

        }

      else

        {

         BufHigh[i]=MathMax(BufHigh[i],high[i]);

         BufLow[i]=MathMin(BufLow[i],low[i]);

        }

     }

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

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

//---- 2>AAB0=02;8205< 7=0G5=8O ?5@5<5==KE

   z=Z_;

//---- >A=>2=>9 F8:; @0AG5B0 8=48:0B>@0

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

     {

      //---- 70?><8=05< 7=0G5=8O ?5@5<5==KE ?5@54 ?@>3>=0<8 =0 B5:CI5< 10@5

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

         Z_=z;

      SellBuffer[i]=0.0;

      BuyBuffer[i]=0.0;

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

               (Inptrei && close[i]<BufferC[i]) || (Inppatry && close[i]<P));

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

               (Inptrei && close[i]>BufferC[i]) || (Inppatry && close[i]>P));

      if(CoralDn)

         z = 1;

      if(CoralUp)

         z = 2;

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

        {

         if(((InpFiltryP && close[i]<P) || (!InpFiltryP && !InpFiltryC)) || ((InpFiltryC && close[i]<BufferC[i]) || (!InpFiltryP && !InpFiltryC)))

            if(OldTrend>0)

               SellBuffer[i]=high[i];;

         if(i!=0)

            OldTrend=-1;

        }

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

        {

         if(((InpFiltryP && close[i]>P) || (!InpFiltryP && !InpFiltryC)) || ((InpFiltryC && close[i]>BufferC[i]) || (!InpFiltryP && !InpFiltryC)))

            if(OldTrend<0)

               BuyBuffer[i]=low[i];

         if(i!=0)

            OldTrend=+1;

        }

     }

   datetime tm=time[rates_total-20];

   TrendPointChange(0,InpCoralHline,0,tm,BufferC[0]);

   TrendPointChange(0,InpCoralcopHline,0,tm,BufferCcop[0]);

   TrendPointChange(0,InpPivotHline,0,tm,P);

   TrendPointChange(0,InpS2Hline,0,tm,S2);

   TrendPointChange(0,InpR2Hline,0,tm,R2);

   if(Redr)

      ChartRedraw();

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

   return(rates_total);

  }

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

//| 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);

  }

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

//|  !>740=85 3>@87>=B0;L=>3>, F5=>2>3> C@>2=O                       |

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

bool CreateHline(long ch_id,int sub_window,

                 string name,double price,

                 color clr,ENUM_LINE_STYLE style,

                 int width,bool back,

                 bool selectable,bool selected,

                 bool hidden,long z_order)

  {

   ObjectCreate(ch_id,name,OBJ_HLINE,sub_window,0,price);

   ObjectSetInteger(ch_id,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(ch_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(ch_id,name,OBJPROP_WIDTH,width);

   ObjectSetInteger(ch_id,name,OBJPROP_BACK,back);

   ObjectSetInteger(ch_id,name,OBJPROP_SELECTABLE,selectable);

   ObjectSetInteger(ch_id,name,OBJPROP_SELECTED,selected);

   ObjectSetInteger(ch_id,name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(ch_id,name,OBJPROP_ZORDER,z_order);

   return(true);

  }

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

//|                                                                  |

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

bool NewDay(datetime aNowTime,datetime aPreTime)

  {

   long NowDay=aNowTime/86400;

   long PreDay=aPreTime/86400;

   if(AttachSundToMond)

     {

      if(NowDay!=PreDay)

        {

         MqlDateTime nts,pts;

         TimeToStruct(aNowTime,nts);

         TimeToStruct(aPreTime,pts);

         if(nts.day_of_week==1 && pts.day_of_week==0)

           {

            return(false);

           }

         return(true);

        }

     }

   else

     {

      return(NowDay!=PreDay);

     }

   return(false);

  }

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

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 ---