I made custom indicator only issue is the lines has some gap.

To add comments, please log in or register
Revazi Tchitanava
115
Revazi Tchitanava  
Hello. I made custom indicator. everything is working correct. but issue is that lines has gaps and I couldn't figure it out why.
//+------------------------------------------------------------------+
//|                                                        MTFSS.mq4 |
//|                              Copyright 2019, R.T. Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, R.T. Software Corp."
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 10
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrWhite
#property indicator_width1 1
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrWhite
#property indicator_width2 1
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrWhite
#property indicator_width3 1
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrWhite
#property indicator_width4 1
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrWhite
#property indicator_width5 1
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrWhite
#property indicator_width6 1
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrWhite
#property indicator_width7 1
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrWhite
#property indicator_width8 1
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrWhite
#property indicator_width9 1
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrWhite
#property indicator_width10 1

extern   string               S_1               =  "Stochastic 1 Settings";
extern   ENUM_TIMEFRAMES      Stoch1_timeframe  =  PERIOD_D1;
extern   int                  Stoch1_Kperiod    =  14;
extern   int                  Stoch1_Dperiod    =  3;
extern   int                  Stoch1_slowing    =  3;
//extern   double               Stoch1_Oversold   =  20;
//extern   double               Stoch1_Overbought =  80;

extern   string               S_2               =  "Stochastic 2 Settings";
extern   ENUM_TIMEFRAMES      Stoch2_timeframe  =  PERIOD_D1;
extern   int                  Stoch2_Kperiod    =  28;
extern   int                  Stoch2_Dperiod    =  3;
extern   int                  Stoch2_slowing    =  3;
//extern   double               Stoch2_Oversold   =  20;
//extern   double               Stoch2_Overbought =  80;

extern   string               S_3               =  "Stochastic 3 Settings";
extern   ENUM_TIMEFRAMES      Stoch3_timeframe  =  PERIOD_D1;
extern   int                  Stoch3_Kperiod    =  42;
extern   int                  Stoch3_Dperiod    =  3;
extern   int                  Stoch3_slowing    =  3;
//extern   double               Stoch3_Oversold   =  20;
//extern   double               Stoch3_Overbought =  80;

extern   string               S_4               =  "Stochastic 4 Settings";
extern   ENUM_TIMEFRAMES      Stoch4_timeframe  =  PERIOD_W1;
extern   int                  Stoch4_Kperiod    =  14;
extern   int                  Stoch4_Dperiod    =  3;
extern   int                  Stoch4_slowing    =  3;
//extern   double               Stoch4_Oversold   =  20;
//extern   double               Stoch4_Overbought =  80;

extern   string               S_5               =  "Stochastic 5 Settings";
extern   ENUM_TIMEFRAMES      Stoch5_timeframe  =  PERIOD_W1;
extern   int                  Stoch5_Kperiod    =  14;
extern   int                  Stoch5_Dperiod    =  3;
extern   int                  Stoch5_slowing    =  3;
//extern   double               Stoch5_Oversold   =  20;
//extern   double               Stoch5_Overbought =  80;

extern   string               S_6               =  "Stochastic 6 Settings";
extern   ENUM_TIMEFRAMES      Stoch6_timeframe  =  PERIOD_W1;
extern   int                  Stoch6_Kperiod    =  14;
extern   int                  Stoch6_Dperiod    =  3;
extern   int                  Stoch6_slowing    =  3;
//extern   double               Stoch6_Oversold   =  20;
//extern   double               Stoch6_Overbought =  80;

double arrUpTotalSumK1[];
double arrDnTotalSumK1[];
double arrUpTotalSumK23_0[];
double arrDnTotalSumK23_0[];
double arrUpTotalSumK23_1[];
double arrDnTotalSumK23_1[];
double arrUpTotalSumK23456_0[];
double arrDnTotalSumK23456_0[];
double arrUpTotalSumK23456_1[];
double arrDnTotalSumK23456_1[];


double TotalSumK123[2];
double TotalSumD123[2];

double TotalSumK456[2];
double TotalSumD456[2];

double TotalSumK[2];
double TotalSumD[2];

double TotalSumK1[2];
double TotalSumD1[2];

double TotalSumK23[2];
double TotalSumD23[2];

double TotalSumK23456[2];
double TotalSumD23456[2];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//---
   //ObjectCreate(ChartID(), "50 % line", OBJ_HLINE, ChartWindowFind(ChartID(), "MTFSS"), 0, 50);
//---
   ArrayResize(TotalSumK123, Bars);
   ArrayResize(TotalSumD123, Bars);
   ArrayResize(TotalSumK456, Bars);
   ArrayResize(TotalSumD456, Bars);
   ArrayResize(TotalSumK, Bars);
   ArrayResize(TotalSumD, Bars);
   ArrayResize(TotalSumK1, Bars);
   ArrayResize(TotalSumD1, Bars);
   ArrayResize(TotalSumK23, Bars);
   ArrayResize(TotalSumD23, Bars);
   ArrayResize(TotalSumK23456, Bars);
   ArrayResize(TotalSumD23456, Bars);
//--- indicator buffers mapping
   SetIndexBuffer(0, arrUpTotalSumK1);
   SetIndexBuffer(1, arrUpTotalSumK23_0);
   SetIndexBuffer(2, arrUpTotalSumK23456_0);
   SetIndexBuffer(3, arrDnTotalSumK1);
   SetIndexBuffer(4, arrDnTotalSumK23_0);
   SetIndexBuffer(5, arrDnTotalSumK23456_0);
   SetIndexBuffer(6, arrUpTotalSumK23_1);
   SetIndexBuffer(7, arrUpTotalSumK23456_1);
   SetIndexBuffer(8, arrDnTotalSumK23_1);
   SetIndexBuffer(9, arrDnTotalSumK23456_1);
//---
   SetIndexDrawBegin(0, 0);
   SetIndexDrawBegin(1, 0);
   SetIndexDrawBegin(2, 0);
   SetIndexDrawBegin(3, 0);
   SetIndexDrawBegin(4, 0);
   SetIndexDrawBegin(5, 0);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MTFSS");
   
   SetIndexLabel(0, "UpTotalSumK1");
   SetIndexLabel(1, "UpTotalSumK23");
   SetIndexLabel(2, "UpTotalSumK23456");
   SetIndexLabel(3, "DnTotalSumK1");
   SetIndexLabel(4, "DnTotalSumK23");
   SetIndexLabel(5, "DnTotalSumK23456");
//--- set levels
   IndicatorSetInteger(INDICATOR_LEVELS, 5);

   IndicatorSetDouble (INDICATOR_LEVELVALUE, 0, 20);
   IndicatorSetDouble (INDICATOR_LEVELVALUE, 1, 30);
   IndicatorSetDouble (INDICATOR_LEVELVALUE, 2, 50);
   IndicatorSetDouble (INDICATOR_LEVELVALUE, 3, 70);
   IndicatorSetDouble (INDICATOR_LEVELVALUE, 4, 80);
   
   IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_SOLID);
   IndicatorSetInteger(INDICATOR_LEVELCOLOR, clrWhite);
   IndicatorSetInteger(INDICATOR_LEVELWIDTH, 1);
//--- set maximum and minimum for subwindow
   IndicatorSetDouble(INDICATOR_MINIMUM, 0);
   IndicatorSetDouble(INDICATOR_MAXIMUM, 100);
//---
   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[])
{
//---
   for(int i = 0; i < Bars - 2; i++)
   {
      double SSK1 = iStochastic(_Symbol, Stoch1_timeframe, Stoch1_Kperiod, Stoch1_Dperiod, Stoch1_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD1 = iStochastic(_Symbol, Stoch1_timeframe, Stoch1_Kperiod, Stoch1_Dperiod, Stoch1_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
      
      double SSK2 = iStochastic(_Symbol, Stoch2_timeframe, Stoch2_Kperiod, Stoch2_Dperiod, Stoch2_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD2 = iStochastic(_Symbol, Stoch2_timeframe, Stoch2_Kperiod, Stoch2_Dperiod, Stoch2_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
      
      double SSK3 = iStochastic(_Symbol, Stoch3_timeframe, Stoch3_Kperiod, Stoch3_Dperiod, Stoch3_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD3 = iStochastic(_Symbol, Stoch3_timeframe, Stoch3_Kperiod, Stoch3_Dperiod, Stoch3_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
      
      double SSK4 = iStochastic(_Symbol, Stoch4_timeframe, Stoch4_Kperiod, Stoch4_Dperiod, Stoch4_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD4 = iStochastic(_Symbol, Stoch4_timeframe, Stoch4_Kperiod, Stoch4_Dperiod, Stoch4_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
      
      double SSK5 = iStochastic(_Symbol, Stoch5_timeframe, Stoch5_Kperiod, Stoch5_Dperiod, Stoch5_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD5 = iStochastic(_Symbol, Stoch5_timeframe, Stoch5_Kperiod, Stoch5_Dperiod, Stoch5_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
      
      double SSK6 = iStochastic(_Symbol, Stoch6_timeframe, Stoch6_Kperiod, Stoch6_Dperiod, Stoch6_slowing, MODE_SMA, 0, MODE_MAIN, i);
      double SSD6 = iStochastic(_Symbol, Stoch6_timeframe, Stoch6_Kperiod, Stoch6_Dperiod, Stoch6_slowing, MODE_SMA, 0, MODE_SIGNAL, i);
//=============================================================================================================================
// Calculate Avg's
//=============================================================================================================================
      TotalSumK123[i] = (SSK1 + SSK2 + SSK3) / 3;
      TotalSumD123[i] = (SSD1 + SSD2 + SSD3) / 3;
      
      TotalSumK456[i] = (SSK4 + SSK5 + SSK6) / 3;
      TotalSumD456[i] = (SSD4 + SSD5 + SSD6) / 3;
   
      TotalSumK[i] = (SSK1 + SSK2 + SSK3 + SSK4 + SSK5 + SSK6) / 6;
      TotalSumD[i] = (SSD1 + SSD2 + SSD3 + SSD4 + SSD5 + SSD6) / 6;
   
      TotalSumK1[i] = SSK1;
      TotalSumD1[i] = SSD1;
      
      TotalSumK23[i] = (SSK2 + SSK3) / 2;
      TotalSumD23[i] = (SSD2 + SSD3) / 2;
      
      TotalSumK23456[i] = (SSK2 + SSK3 + SSK4 + SSK5 + SSK6) / 5;
      TotalSumD23456[i] = (SSD2 + SSD3 + SSD4 + SSD5 + SSD6) / 5;

//=============================================================================================================================
// Stochastic Display
//=============================================================================================================================
      if  (TotalSumK1[i] > TotalSumD1[i])
      {
         arrUpTotalSumK1[i] = TotalSumK1[i];
         SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 1, clrGreen);
      }
      if  (TotalSumK1[i] < TotalSumD1[i])
      {
         arrDnTotalSumK1[i] = TotalSumK1[i];
         SetIndexStyle (3, DRAW_LINE, STYLE_SOLID, 1, clrRed);
      }

      if  (TotalSumK23[i] > 70)
      {
         arrUpTotalSumK23_1[i] = TotalSumK23[i];
         SetIndexStyle (6, DRAW_LINE, STYLE_SOLID, 1, clrCyan);
      }
      if  (TotalSumK23[i] < 30 && TotalSumK23[i] > 0)
      {
         arrDnTotalSumK23_1[i] = TotalSumK23[i];
         SetIndexStyle (8, DRAW_LINE, STYLE_SOLID, 1, clrDarkCyan);
      }

      if  (TotalSumK23[i] > TotalSumD23[i])
      {
         arrUpTotalSumK23_0[i] = TotalSumK23[i];
         SetIndexStyle (1, DRAW_LINE, STYLE_SOLID, 3, clrYellow);
      }
      if  (TotalSumK23[i] < TotalSumD23[i])
      {
         arrDnTotalSumK23_0[i] = TotalSumK23[i];
         SetIndexStyle (4, DRAW_LINE, STYLE_SOLID, 3, clrBrown);
      }

      if  (TotalSumK23456[i] > 70)
      {
         arrUpTotalSumK23456_1[i] = TotalSumK23456[i];
         SetIndexStyle (7, DRAW_LINE, STYLE_SOLID, 3, clrMagenta);
      }
      if  (TotalSumK23456[i] < 30 && TotalSumK23456[i] > 0)
      {
         arrDnTotalSumK23456_1[i] = TotalSumK23456[i];
         SetIndexStyle (9, DRAW_LINE, STYLE_SOLID, 3, clrDarkMagenta);
      }
      
      if(TotalSumK23456[i] >= TotalSumD23456[i])
      {
         arrUpTotalSumK23456_0[i] = TotalSumK23456[i];
         SetIndexStyle (2, DRAW_LINE, STYLE_SOLID, 5, clrWhite);
      }
      if(TotalSumK23456[i] <= TotalSumD23456[i])
      {
         arrDnTotalSumK23456_0[i] = TotalSumK23456[i];
         SetIndexStyle (5, DRAW_LINE, STYLE_SOLID, 5, clrDarkGray);
      }
//=============================================================================================================================
// Trend State
//=============================================================================================================================
//=============================================================================================================================
// Trend Trigger Alert
//=============================================================================================================================
      /*
      if(TotalSumK1[i]       > TotalSumD1[i]      &&
         TotalSumK23[i]      > TotalSumD23[i]     &&
         TotalSumK23456[i]   > TotalSumD23456[i]  )
      {
         ObjectSetInteger(ChartID(), "50 % line", OBJPROP_COLOR, clrGreen);
         ObjectSetInteger(ChartID(), "50 % line", OBJPROP_WIDTH, 3);
      }
      if(TotalSumK1[i]       < TotalSumD1[i]      &&
         TotalSumK23[i]      < TotalSumD23[i]     &&
         TotalSumK23456[i]   < TotalSumD23456[i]  )
      {
         ObjectSetInteger(ChartID(), "50 % line", OBJPROP_COLOR, clrRed);
         ObjectSetInteger(ChartID(), "50 % line", OBJPROP_WIDTH, 3);
      }*/
   }

      if((TotalSumK1[0]       > TotalSumD1[0])      &&
         (TotalSumK23[0]      > TotalSumD23[0])     &&
         (TotalSumK23456[0]   > TotalSumD23456[0])  )
      {
         if((TotalSumK1[0]       > TotalSumD1[0]      && TotalSumK1[1]       < TotalSumD1[1]       )  ||
            (TotalSumK23[0]      > TotalSumD23[0]     && TotalSumK23[1]      < TotalSumD23[1]      )  || 
            (TotalSumK23456[0]   > TotalSumD23456[0]  && TotalSumK23456[1]   < TotalSumD23456[1]   )  )
         {
            Alert("Bullish trigger");
         }
         
         //IndicatorSetInteger(INDICATOR_LEVELCOLOR, clrGreen);
         //IndicatorSetInteger(INDICATOR_LEVELWIDTH, 3);
      }
      else if ((TotalSumK1[0]       < TotalSumD1[0])      &&
               (TotalSumK23[0]      < TotalSumD23[0])     &&
               (TotalSumK23456[0]   < TotalSumD23456[0])  )
      {
         if((TotalSumK1[0]       < TotalSumD1[0]      && TotalSumK1[1]       > TotalSumD1[1]       )  ||
            (TotalSumK23[0]      < TotalSumD23[0]     && TotalSumK23[1]      > TotalSumD23[1]      )  || 
            (TotalSumK23456[0]   < TotalSumD23456[0]  && TotalSumK23456[1]   > TotalSumD23456[1]   )  )
         {
            Alert("Bearish trigger");
         }
         
         //IndicatorSetInteger(INDICATOR_LEVELCOLOR, clrRed);
         //IndicatorSetInteger(INDICATOR_LEVELWIDTH, 3);
      }

//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
William Roeder
20228
William Roeder  
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. If you assign to one color buffer, make the other color buffer empty.
              HOW CAN I hide CONNECTION lines of plots? (ttt) - MQL4 programming forum For MT4 I use:

    One buffer has the value, color set to CLR_NONE so not shown on chart, (but in data window and pop up.)

    Two buffers, one color each, with SetIndexLabel(i, NULL) so they don't show in data window.

    Then you need to connect the lines on color change. downBuffer[i]=value[i]; if(downBuffer[i+1]==EMPTY_VALUE) downBuffer[i+1]=value[i].

To add comments, please log in or register