MTF_Candle_MT5

Author: Clickaider 2021
1 Views
1 Downloads
0 Favorites
MTF_Candle_MT5
ÿþ//+------------------------------------------------------------------+

//| 40?B0F8O 8=48:0B>@0 MTF-Candle,                  MTF-Candle.mq5 |

//| 27OB>3> A MetaTrader4 8 ?5@52545=0O =0           Clickaider 2023 |

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

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

#property copyright "Clickaider 2021"

#property link      "https://www.mql5.com/ru/code/27125"

#property description "version from 18.12.2021"

#property indicator_chart_window

#property indicator_plots 1

#property indicator_buffers 1

//--- input parameters

input ENUM_TIMEFRAMES   TF_Bar                          = PERIOD_H1;

input int               Number_of_bars                  = 100;

input color             Color_Up                        = clrLime;

input color             Color_Down                      = clrRed;

input int               Widht_lines                     = 2;

input bool              Fill_Candle                     = false;

input bool              Display_Shadow                  = true;

input bool              Boxedwick                       = true;

input int               Widht_lines_boxedwick           = 1;

input bool              Color_boxedwick_is_Color_candle = true;

input color             Color_Up_boxedwick              = clrLime;

input color             Color_Down_boxedwick            = clrRed;

input bool              Back_Mode                       = true;

input bool              GBC                             = true;

input bool              Bar_Force_VSA                   = false;

enum Volume

  {

   Real,

   Tick

  };

input Volume           Type_Volume                      = Real;



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   int i;



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

     {

      ObjectDelete(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(i));

      ObjectDelete(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i));

      ObjectDelete(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i));

      ObjectDelete(0,"BoxedwickTF1"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i));

     }

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

     {

      ObjectCreate(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i), OBJ_RECTANGLE, 0, 0,0, 0,0);

      ObjectCreate(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i), OBJ_TREND, 0, 0,0, 0,0);

      ObjectCreate(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i), OBJ_TREND, 0, 0,0, 0,0);

      ObjectCreate(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i), OBJ_RECTANGLE, 0, 0,0, 0,0);

     }

   Comment("");

   return(INIT_SUCCEEDED);

  }





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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

// #40;5=85 >1J5:B>2

   for(int i=0; i<Number_of_bars; i++)

     {

      ObjectDelete(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(i));

      ObjectDelete(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i));

      ObjectDelete(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar" + DoubleToString(i));

      ObjectDelete(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(i));

     }

   Comment("");

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,       // @07<5@ 2E>4=KE B09<A5@89

                const int prev_calculated,  // >1@01>B0=> 10@>2 =0 ?@54K4CI5< 2K7>25

                const datetime& time[],     // Time

                const double& open[],       // Open

                const double& high[],       // High

                const double& low[],        // Low

                const double& close[],      // Close

                const long& tick_volume[],  // Tick Volume

                const long& volume[],       // Real Volume

                const int& spread[])         // Spread



  {



   int shb=0;

   int sh1=1;

   long tv0, tv1, tv2, rv0, rv1, rv2;

   double   po, pc;           // &5=K >B:@KB8O 8 70:@KB8O AB0@H8E A25G5:

   double   ph=0, pl=0;       // &5=K E09 8 ;>C AB0@H8E A25G5:

   datetime to, tc, ts; // @5<O >B:@KB8O, 70:@KB8O 8 B5=59 AB0@H8E A25G5:

   int gap_candle = 0;        // 07>@ <564C A25G0<8







   bool OK_Period=false;

   switch(TF_Bar)

     {

      case PERIOD_M1:

         OK_Period=true;

         break;

      case PERIOD_M2:

         OK_Period=true;

         break;

      case PERIOD_M3:

         OK_Period=true;

         break;

      case PERIOD_M4:

         OK_Period=true;

         break;

      case PERIOD_M5:

         OK_Period=true;

         break;

      case PERIOD_M6:

         OK_Period=true;

         break;

      case PERIOD_M10:

         OK_Period=true;

         break;

      case PERIOD_M12:

         OK_Period=true;

         break;

      case PERIOD_M15:

         OK_Period=true;

         break;

      case PERIOD_M20:

         OK_Period=true;

         break;

      case PERIOD_M30:

         OK_Period=true;

         break;

      case PERIOD_H1:

         OK_Period=true;

         break;

      case PERIOD_H2:

         OK_Period=true;

         break;

      case PERIOD_H3:

         OK_Period=true;

         break;

      case PERIOD_H4:

         OK_Period=true;

         break;

      case PERIOD_H6:

         OK_Period=true;

         break;

      case PERIOD_H8:

         OK_Period=true;

         break;

      case PERIOD_H12:

         OK_Period=true;

         break;

      case PERIOD_D1:

         OK_Period=true;

         break;

      case PERIOD_W1:

         OK_Period=true;

         break;

      case PERIOD_MN1:

         OK_Period=true;

         break;

     }

   if(OK_Period==false)

     {

      Comment("K 2K1@0;8 =5AB0=40@B=K9 ?5@8>4 B09<D@59<0 TF_Bar!");

      return(0);

     }

   if(Period()>TF_Bar)

     {

      Comment("040205<K9 AB0=40@B=K9 ?5@8>4 4>;65= 1KBL 1>;LH5 B5:CI53>! ("5:CI89 @025= " + DoubleToString(Period()) + ")");

      return(0);

     }

   int bar_minutes = PeriodSeconds(TF_Bar);



// 568< ?> AB0@H8< A25G:0<

   while(shb<Number_of_bars)

     {

      to = iTime(Symbol(), TF_Bar, shb);                    // @5<O >B:@KB8O

      tc = iTime(Symbol(), TF_Bar, shb) + bar_minutes;      // @5<O 70:@KB8O

      po = iOpen(Symbol(), TF_Bar, shb);                    // &5=0 >B:@KB8O

      pc = iClose(Symbol(), TF_Bar, shb);                   // &5=0 70:@KB8O

      ph = iHigh(Symbol(), TF_Bar, shb);                    // &5=0 <0:A8<0;L=0O

      pl = iLow(Symbol(), TF_Bar, shb);                     // &5=0 <8=8<0;L=0O

      tv0  = iVolume(Symbol(), TF_Bar, shb);                 // "8:>2K9 >1J5< AB0@H59 A25G8

      tv1  = iVolume(Symbol(), TF_Bar, shb+1);               // "8:>2K9 >1J5< AB0@H59 A25G8

      tv2  = iVolume(Symbol(), TF_Bar, shb+2);               // "8:>2K9 >1J5< AB0@H59 A25G8

      rv0  = iRealVolume(Symbol(), TF_Bar, shb);             //  50;L=K9 >1J5< AB0@H59 A25G8

      rv1  = iRealVolume(Symbol(), TF_Bar, shb+1);           //  50;L=K9 >1J5< AB0@H59 A25G8

      rv2  = iRealVolume(Symbol(), TF_Bar, shb+2);           //  50;L=K9 >1J5< AB0@H59 A25G8

     

      if(GBC == true)

        {

         gap_candle = 1;

        }

      else

        {

         gap_candle = 0;

        }

      //CAB0=02;8205<  @5:B0=35;K(?@O<>C3>;L=8:8)

      ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,0, to);           // 2@5<O >B:@KB8O (;52>)

      ObjectSetDouble(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,0, po);           // F5=0 >B:@KB8O  (25@E)

      ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,1, tc-gap_candle);// 2@5<O 70:@KB8O (?@02>)

      ObjectSetDouble(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,1, pc);           // F5=0 70:@KB8O (=87)

      ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_STYLE, STYLE_SOLID);   // B8? ;8=88

      ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_WIDTH, Widht_lines);   // B>;I8=0 ;8=88

      ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_BACK, Back_Mode);      // >1J5:B =0 704=5< ?;0=5

      if(Boxedwick == true)

        {

         //CAB0=02;8205<  @5:B0=35;K(?@O<>C3>;L=8:8) @0<:8 (Boxedwick)

         ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,0, to);           // 2@5<O >B:@KB8O

         ObjectSetDouble(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,0, ph);           // F5=0 >B:@KB8O

         ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,1, tc-gap_candle);// 2@5<O 70:@KB8O

         ObjectSetDouble(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,1, pl);           // F5=0 70:@KB8O

         ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_STYLE, STYLE_SOLID);

         ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_WIDTH, Widht_lines_boxedwick);

         ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_BACK, Back_Mode);      // >1J5:B =0 704=5< ?;0=5



        }

      if(Fill_Candle == true)    // 70;82:0 AB0@H8E A25G59

        {

         ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_FILL, true);

        }

      else

         if(Bar_Force_VSA == true && Fill_Candle != true)

           {

            if(Type_Volume == Tick)

              {

               if(tv0 > tv1 && tv0 > tv2)

                 {

                  ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_FILL, true);

                 }

               else

                 {

                  ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_FILL, false);

                 }

              }

            else;

            if(Type_Volume == Real && Fill_Candle != true)

              {

               if(rv0 > rv1 && rv0 > rv2)

                 {

                  ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_FILL, true);

                 }

               else

                 {

                  ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_FILL, false);

                 }

              }

            else;

           }

      //CAB0=02;8205< B5=8

      if(Display_Shadow == true)

        {

         ts = int(to) + int(MathRound((bar_minutes)/2));

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,0, ts);         // 2@5<O

         ObjectSetDouble(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,0, ph);         // F5=0 <0:A8<0;L=0O

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,1, ts);         // F5=0 <8=8<0;L=0O

         if(po>pc)

            ObjectSetDouble(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,1, po);         // 2@5<O

         else

            ObjectSetDouble(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,1, pc);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,0, ts);         // F5=0 <8=8<0;L=0O

         if(po<pc)

            ObjectSetDouble(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,0, po);         // 2@5<O

         else

            ObjectSetDouble(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,0, pc);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_TIME,1, ts);         // F5=0 <8=8<0;L=0O

         ObjectSetDouble(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_PRICE,1, pl);         // 2@5<O

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_STYLE, STYLE_SOLID);

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_WIDTH, Widht_lines);

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_BACK, Back_Mode);

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_RAY, false);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_STYLE, STYLE_SOLID);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_WIDTH, Widht_lines);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_BACK, Back_Mode);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_RAY, false);

        }

      //CAB0=02;8205< F25B0 4;O 2A5E >1J5:B>2

      if(po<pc)

        {

         ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Up);

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Up);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Up);

         if(Color_boxedwick_is_Color_candle == true)

           {

            ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Up);

           }

         else

           {

            ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Up_boxedwick);

           }

        }

      else

        {

         ObjectSetInteger(0,"BodyTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Down);

         ObjectSetInteger(0,"ShadowTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR,Color_Down);

         ObjectSetInteger(0,"ShadowTF1"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR,Color_Down);

         if(Color_boxedwick_is_Color_candle == true)

           {

            ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Down);

           }

         else

           {

            ObjectSetInteger(0,"BoxedwickTF"+DoubleToString(TF_Bar)+"Bar"+DoubleToString(shb), OBJPROP_COLOR, Color_Down_boxedwick);

           }

        }

      shb++;

     }

   return(rates_total);

  }



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

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



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

Comments