IPMSD indices

Author: Alexandr Sokolov
0 Views
0 Downloads
0 Favorites
IPMSD indices
ÿþ#property copyright    "Alexandr Sokolov"

#property link         "https://www.mql5.com/en/users/asokolov7"

#property version      "1.00"

#property description  "Imbalance index. Phase index. Movement index. Stability index. Density index"

#property strict

#property indicator_separate_window

#property indicator_buffers  15

#property indicator_plots    5



//--- @0D8G5A:>5 ?>AB@>5=85 II -------------------------------------

#property indicator_type1   DRAW_COLOR_HISTOGRAM  //"8? 3@0D8G5A:>3> ?>AB@>5=8O !1

#property indicator_style1  STYLE_SOLID           //!B8;L ;8=88 3@0D8G5A:>3> ?>AB@>5=8O !1

#property indicator_width1  2                     //">;I8=0 ;8=88 3@0D8G5A:>3> ?>AB@>5=8O !1

#property indicator_color1  clrBlue, clrNavy      //&25B0 ;8=88 3@0D8G5A:>3> ?>AB@>5=8O !1

#property indicator_label1  "Imbalance index"     //A?;K20NI55 >?8A0=85 3@0D8G5A:>3> ?>AB@>5=8O !1



//--- @0D8G5A:>5 ?>AB@>5=85 PI -------------------------------------

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

#property indicator_color2  clrOrangeRed, clrRed

#property indicator_label2  "Phase index"



//--- @0D8G5A:>5 ?>AB@>5=85 MI -------------------------------------

#property indicator_type3   DRAW_COLOR_LINE

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

#property indicator_color3  clrLimeGreen, clrGreen

#property indicator_label3  "Movement index"



//--- @0D8G5A:>5 ?>AB@>5=85 SI -------------------------------------

#property indicator_type4   DRAW_COLOR_LINE

#property indicator_style4  STYLE_SOLID

#property indicator_width4  1

#property indicator_color4  clrYellow, clrGold

#property indicator_label4  "Stability index"



//--- @0D8G5A:>5 ?>AB@>5=85 DI -------------------------------------

#property indicator_type5   DRAW_COLOR_LINE

#property indicator_style5  STYLE_SOLID

#property indicator_width5  1

#property indicator_color5  clrMaroon, clrBlack

#property indicator_label5  "Density index"



//--- CD5@K --------------------------------------------------------

double II[], ICI[],  //;O Imbalance index

       PI[], PCI[],  //;O Phase index

       MI[], MCI[],  //;O Movement index

       SI[], SCI[],  //;O Stability index

       DI[], DCI[],  //;O Density index

       Open[],       //;O F5= Open

       High[],       //;O F5= High

       Low[],        //;O F5= Low

       Close[],      //;O F5= Close

       Inhibitor[];  //;O 70<54;5=8O 8=45:A>2



//--- !B0B8G5A:85 ?5@5<5==K5 ----------------------------------------

static uint  min_count = 0; //'8A;> <8=8<0;L=> =5>1E>48<>3> :>;8G5AB20 10@>2 4;O @0AGQB>2 8=48:0B>@0



//--- E>4=K5 ?0@0<5B@K ---------------------------------------------

input uint            ii_period   = 5,        //II Period

                      ii_slowing  = 3;        //II Slowing

input ENUM_MA_METHOD  ii_method   = MODE_EMA; //II Method

input double          ii_norma    = 0.1;      //II Normalization

input int             ii_shift    = 0;        //II Shift

input uint            pi_period   = 5,        //PI Period

                      pi_slowing  = 3;        //PI Slowing

input ENUM_MA_METHOD  pi_method   = MODE_EMA; //PI Method

input double          pi_norma    = 1.0;      //PI Normalization

input int             pi_shift    = 0;        //PI Shift

input uint            mi_period   = 5,        //MI Period

                      mi_slowing  = 3;        //MI Slowing

input ENUM_MA_METHOD  mi_method   = MODE_EMA; //MI Method

input double          mi_norma    = 1.0;      //MI Normalization

input int             mi_shift    = 0;        //MI Shift

input uint            si_period   = 5,        //SI Period

                      si_slowing  = 3;        //SI Slowing

input ENUM_MA_METHOD  si_method   = MODE_EMA; //SI Method

input double          si_norma    = 0.2;      //SI Normalization

input int             si_shift    = 0;        //SI Shift

input uint            di_period   = 5,        //DI Period

                      di_slowing  = 3;        //DI Slowing

input ENUM_MA_METHOD  di_method   = MODE_EMA; //DI Method

input double          di_norma    = 1.0;      //DI Normalization

input int             di_shift    = 0;        //DI Shift



//-------------------------------------------------------------------------------------------------



int OnInit()

  {

   

  //--- N0=AK ------------------------------------------------------

   IndicatorSetInteger(INDICATOR_DIGITS,2);         //>;8G5AB2> 45AOB8G=KE 7=0:>2 ?>A;5 70?OB>9

   IndicatorSetString(INDICATOR_SHORTNAME,"IPMSD"); //8F52>5 8<O 2 >:=5 8=48:0B>@0

   

  //--- #:07K205< B8?K 1CD5@>2 --------------------------------------

   SetIndexBuffer(0,II,INDICATOR_DATA);                  SetIndexBuffer(1,ICI,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(2,PI,INDICATOR_DATA);                  SetIndexBuffer(3,PCI,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4,MI,INDICATOR_DATA);                  SetIndexBuffer(5,MCI,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(6,SI,INDICATOR_DATA);                  SetIndexBuffer(7,SCI,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(8,DI,INDICATOR_DATA);                  SetIndexBuffer(9,DCI,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(10,Open,INDICATOR_CALCULATIONS);       SetIndexBuffer(11,High,INDICATOR_CALCULATIONS);

   SetIndexBuffer(12,Low,INDICATOR_CALCULATIONS);        SetIndexBuffer(13,Close,INDICATOR_CALCULATIONS);

   SetIndexBuffer(14,Inhibitor,INDICATOR_CALCULATIONS);

   

  //--- #:07K205< ?>@O4>: 8=45:A0F88 1CD5@>2 ------------------------

   ArraySetAsSeries(II,true);         ArraySetAsSeries(ICI,true);

   ArraySetAsSeries(PI,true);         ArraySetAsSeries(PCI,true);

   ArraySetAsSeries(MI,true);         ArraySetAsSeries(MCI,true);

   ArraySetAsSeries(SI,true);         ArraySetAsSeries(SCI,true);

   ArraySetAsSeries(DI,true);         ArraySetAsSeries(DCI,true);

   ArraySetAsSeries(Open,true);       ArraySetAsSeries(High,true);

   ArraySetAsSeries(Low,true);        ArraySetAsSeries(Close,true);

   ArraySetAsSeries(Inhibitor,true);

   

  //--- #:07K205< A<5I5=85 3@0D8G5A:8E ?>AB@>5=89 -------------------

   PlotIndexSetInteger(0,PLOT_SHIFT,ii_shift);

   PlotIndexSetInteger(1,PLOT_SHIFT,pi_shift);

   PlotIndexSetInteger(2,PLOT_SHIFT,mi_shift);

   PlotIndexSetInteger(3,PLOT_SHIFT,si_shift);

   PlotIndexSetInteger(4,PLOT_SHIFT,di_shift);

   

  //--- #7=0Q< <8=8<0;L=> =5>1E>48<>5 :>;8G5AB2> 10@>2 4;O @0AGQB>2 8=48:0B>@0

   if( (ii_period <= 1 ? 1 : ii_period) + (ii_slowing <= 1 ? 1 : ii_slowing) - 1 > min_count )  min_count = (ii_period <= 1 ? 1 : ii_period) + (ii_slowing <= 1 ? 1 : ii_slowing) - 1;

   if( (pi_period <= 1 ? 1 : pi_period) + (pi_slowing <= 1 ? 1 : pi_slowing) > min_count )      min_count = (pi_period <= 1 ? 1 : pi_period) + (pi_slowing <= 1 ? 1 : pi_slowing);

   if( (mi_period <= 1 ? 1 : mi_period) + (mi_slowing <= 1 ? 1 : mi_slowing) - 1 > min_count )  min_count = (mi_period <= 1 ? 1 : mi_period) + (mi_slowing <= 1 ? 1 : mi_slowing) - 1;

   if( (si_period <= 1 ? 1 : si_period) + (si_slowing <= 1 ? 1 : si_slowing) - 1 > min_count )  min_count = (si_period <= 1 ? 1 : si_period) + (si_slowing <= 1 ? 1 : si_slowing) - 1;

   if( (di_period <= 1 ? 1 : di_period) + (di_slowing <= 1 ? 1 : di_slowing) > min_count )      min_count = (di_period <= 1 ? 1 : di_period) + (di_slowing <= 1 ? 1 : di_slowing);

   

  //-----------------------------------------------------------------

   return(INIT_SUCCEEDED);

  }



//-------------------------------------------------------------------------------------------------



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

  {

   

  //--- 1) =8F80;878@C5< 1CD5@K ------------------------------------

   if(prev_calculated == 0)

     {

      ArrayInitialize(II,EMPTY_VALUE);  ArrayInitialize(ICI,EMPTY_VALUE);

      ArrayInitialize(PI,EMPTY_VALUE);  ArrayInitialize(PCI,EMPTY_VALUE);

      ArrayInitialize(MI,EMPTY_VALUE);  ArrayInitialize(MCI,EMPTY_VALUE);

      ArrayInitialize(SI,EMPTY_VALUE);  ArrayInitialize(SCI,EMPTY_VALUE);

      ArrayInitialize(DI,EMPTY_VALUE);  ArrayInitialize(DCI,EMPTY_VALUE);

     };

   

  //--- 2) >?8@C5< F5=K --------------------------------------------

   int count = rates_total - prev_calculated, copied = 0; if(count < (int)min_count) count = (int)min_count;

   copied = CopyOpen(_Symbol,PERIOD_CURRENT,0,count,Open);    if(copied != count) return(0);

   copied = CopyHigh(_Symbol,PERIOD_CURRENT,0,count,High);    if(copied != count) return(0);

   copied = CopyLow(_Symbol,PERIOD_CURRENT,0,count,Low);      if(copied != count) return(0);

   copied = CopyClose(_Symbol,PERIOD_CURRENT,0,count,Close);  if(copied != count) return(0);

   

  //--- 3)  0AAG8BK205< Imbalance index -----------------------------

   II_Function(rates_total,prev_calculated);

   

  //--- 4)  0AAG8BK205< Phase index ---------------------------------

   PI_Function(rates_total,prev_calculated);

   

  //--- 5)  0AAG8BK205< Movement index ------------------------------

   MI_Function(rates_total,prev_calculated);

   

  //--- 6)  0AAG8BK205< Stability index -----------------------------

   SI_Function(rates_total,prev_calculated);

   

  //--- 7)  0AAG8BK205< Density index -------------------------------

   DI_Function(rates_total,prev_calculated);

   

  //-----------------------------------------------------------------

   return(rates_total);

  }





//-------------------------------------------------------------------------------------------------

//    Imbalance index                                                                             |

//-------------------------------------------------------------------------------------------------



void II_Function(const int rates_total,

                 const int prev_calculated)

  {

   

  //--- 3.1) 5@2K9 ;8<8B 4;O @0AGQB0 =5 70<54;5==KE 7=0G5=89 Imbalance index

   int limit_1 = rates_total - prev_calculated - (int)(ii_period <= 1 ? 1 : ii_period);

      if(limit_1 < (int)(ii_period <= 1 ? 1 : ii_period) + (int)(ii_slowing <= 1 ? 1 : ii_slowing) - 1) limit_1 = (int)(ii_period <= 1 ? 1 : ii_period) + (int)(ii_slowing <= 1 ? 1 : ii_slowing) - 1;

   

  //--- 3.2) B>@>9 ;8<8B 4;O 70<54;5=8O 7=0G5=89 Imbalance index

   int limit_2 = rates_total - prev_calculated - (int)(ii_period <= 1 ? 1 : ii_period) - (int)(ii_slowing <= 1 ? 1 : ii_slowing) + 1;

      if(limit_2 < 0) limit_2 = 0;

   

  //--- 3.3) 0?8AK205< =5 70<54;5==K5 7=0G5=8O Imbalance index 2 Inhibitor

   if(ii_slowing > 1)

     {

      ArrayInitialize(Inhibitor,EMPTY_VALUE);

      for(int i = limit_1; i >= 0; i--) {Inhibitor[i] = II_Value(i);};

     };

   

  //--- 3.4)  0AAG8BK205< 8B>3>2K5 7=0G5=8O Imbalance index

   for(int i = limit_2; i >= 0; i--)

     {

      

     //--- 3.4.1) A;8 =C6=> 70<54OBL 7=0G5=8O - 70<54;O5<

      if(ii_slowing > 1) {Slowing(i,(int)ii_slowing,ii_method,II);}

     //--- 3.4.2) ... 5A;8 =5B - 70?8AK205< 8E =5 70<54;OO

      else               {II[i] = II_Value(i);};

      

     //--- 3.4.3) #:07K205< F25B ;8=88 4;O :064>3> 10@0

      if(II[i] >= 0) {ICI[i] = (II[i] > II[i+1] ? 0 : 1);}

      else           {ICI[i] = (II[i] < II[i+1] ? 0 : 1);};

      

     };

   

  }



//---  0AGQB II -----------------------------------------------------



double II_Value(int index)

  {

   

   double up = 0, down = 0;

   int limit = index + (int)ii_period;

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

     {

      up   += High[i] - Open[i];

      down += Open[i] - Low[i];

     };

   

   up   = (up == 0 ? 1 * _Point : up);

   down = (down == 0 ? 1 * _Point : down);

   

  //-----------------------------------------------------------------

   return((up >= down ? up / down - 1 : (down / up) * (-1) + 1) * ii_norma);

  }





//-------------------------------------------------------------------------------------------------

//   Phase index                                                                                  |

//-------------------------------------------------------------------------------------------------



void PI_Function(const int rates_total,

                 const int prev_calculated)

  {

   

  //--- 4.1) 5@2K9 ;8<8B 4;O @0AGQB0 =5 70<54;5==KE 7=0G5=89 Phase index

   int limit_1 = rates_total - prev_calculated - (int)(pi_period <= 1 ? 1 : pi_period) - 1;

      if(limit_1 < (int)(pi_period <= 1 ? 1 : pi_period) + (int)(pi_slowing <= 1 ? 1 : pi_slowing) - 1) limit_1 = (int)(pi_period <= 1 ? 1 : pi_period) + (int)(pi_slowing <= 1 ? 1 : pi_slowing) - 1;

   

  //--- 4.2) B>@>9 ;8<8B 4;O 70<54;5=8O 7=0G5=89 Phase index

   int limit_2 = rates_total - prev_calculated - (int)(pi_period <= 1 ? 1 : pi_period) - (int)(pi_slowing <= 1 ? 1 : pi_slowing) + 1;

      if(limit_2 < 0) limit_2 = 0;

   

  //--- 4.3) 0?8AK205< =5 70<54;5==K5 7=0G5=8O Phase index 2 Inhibitor

   if(pi_slowing > 1)

     {

      ArrayInitialize(Inhibitor,EMPTY_VALUE);

      for(int i = limit_1; i >= 0; i--) {Inhibitor[i] = PI_Value(i);};

     };

   

  //--- 4.4)  0AAG8BK205< 8B>3>2K5 7=0G5=8O Phase index

   for(int i = limit_2; i >= 0; i--)

     {

      

     //--- 4.4.1) A;8 =C6=> 70<54OBL 7=0G5=8O - 70<54;O5<

      if(pi_slowing > 1) {Slowing(i,(int)pi_slowing,pi_method,PI);}

     //--- 4.4.2) ... 5A;8 =5B - 70?8AK205< 8E =5 70<54;OO

      else               {PI[i] = PI_Value(i);};

      

     //--- 4.4.3) #:07K205< F25B ;8=88 4;O :064>3> 10@0

      PCI[i] = (PI[i] > PI[i+1] ? 0 : 1);

      

     };

   

  }



//---  0AGQB PI -----------------------------------------------------



double PI_Value(int index)

  {

   double up = 0, down = 0, sum = 0, minus = 0;

   int limit = index + (int)pi_period;

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

     {

      if(High[i] < High[i+1] && Low[i] > Low[i+1])

        {

         sum += High[i+1] - Low[i+1];

         up  += High[i+1] - Low[i+1];

        }

      else

        {

         up   += (High[i] > High[i+1] ? High[i] - High[i+1] : 0);

         down += (Low[i] < Low[i+1] ? Low[i+1] - Low[i] : 0);

         sum  += MathMax(MathMax(High[i]-Low[i+1],High[i+1]-Low[i]),High[i]-Low[i]);

        };

      minus += (MathMax(High[i],High[i+1]) - MathMin(Low[i],Low[i+1]) <= High[i] - Low[i] + High[i+1] - Low[i+1] ? 0 : MathMax(High[i],High[i+1]) - MathMin(Low[i],Low[i+1]) - High[i] - Low[i] + High[i+1] - Low[i+1]);

     };

  //-----------------------------------------------------------------

   return((up + down == 0 ? 1 * _Point : up + down) / (sum - minus == 0 ? 1 * _Point : sum - minus) * pi_norma);

  }





//-------------------------------------------------------------------------------------------------

//   Movement index                                                                               |

//-------------------------------------------------------------------------------------------------



void MI_Function(const int rates_total,

                 const int prev_calculated)

  {

   

  //--- 5.1) 5@2K9 ;8<8B 4;O @0AGQB0 =5 70<54;5==KE 7=0G5=89 Movement index

   int limit_1 = rates_total - prev_calculated - (int)(mi_period <= 1 ? 1 : mi_period);

      if(limit_1 < (int)(mi_period <= 1 ? 1 : mi_period) + (int)(mi_slowing <= 1 ? 1 : mi_slowing) - 1) limit_1 = (int)(mi_period <= 1 ? 1 : mi_period) + (int)(mi_slowing <= 1 ? 1 : mi_slowing) - 1;

   

  //--- 5.2) B>@>9 ;8<8B 4;O 70<54;5=8O 7=0G5=89 Movement index

   int limit_2 = rates_total - prev_calculated - (int)(mi_period <= 1 ? 1 : mi_period) - (int)(mi_slowing <= 1 ? 1 : mi_slowing) + 1;

      if(limit_2 < 0) limit_2 = 0;

   

  //--- 5.3) 0?8AK205< =5 70<54;5==K5 7=0G5=8O Movement index 2 Inhibitor

   if(mi_slowing > 1)

     {

      ArrayInitialize(Inhibitor,EMPTY_VALUE);

      for(int i = limit_1; i >= 0; i--) {Inhibitor[i] = MI_Value(i);};

     };

   

  //--- 5.4)  0AAG8BK205< 8B>3>2K5 7=0G5=8O Movement index

   for(int i = limit_2; i >= 0; i--)

     {

      

     //--- 5.4.1) A;8 =C6=> 70<54OBL 7=0G5=8O - 70<54;O5<

      if(mi_slowing > 1) {Slowing(i,(int)mi_slowing,mi_method,MI);}

     //--- 5.4.2) ... 5A;8 =5B - 70?8AK205< 8E =5 70<54;OO

      else               {MI[i] = MI_Value(i);};

      

     //--- 5.4.3) #:07K205< F25B ;8=88 4;O :064>3> 10@0

      MCI[i] = (MI[i] > MI[i+1] ? 0 : 1);

      

     };

   

  }



//---  0AGQB MI -----------------------------------------------------



double MI_Value(int index)

  {

   double sum = 0, max = 0, min = High[index] * 2;

   int limit = index + (int)mi_period;

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

     {

      sum += High[i] - Low[i];

      max = (High[i] > max ? High[i] : max);

      min = (Low[i] < min ? Low[i] : min);

     };

  //-----------------------------------------------------------------

   return((max - min == 0 ? 1 * _Point : max - min) / (sum == 0 ? 1 * _Point : sum) * mi_norma);

  }





//-------------------------------------------------------------------------------------------------

//   Stability index                                                                              |

//-------------------------------------------------------------------------------------------------\



void SI_Function(const int rates_total,

                 const int prev_calculated)

  {

   

  //--- 6.1) 5@2K9 ;8<8B 4;O @0AGQB0 =5 70<54;5==KE 7=0G5=89 Stability index

   int limit_1 = rates_total - prev_calculated - (int)(si_period <= 1 ? 1 : si_period);

      if(limit_1 < (int)(si_period <= 1 ? 1 : si_period) + (int)(si_slowing <= 1 ? 1 : si_slowing) - 1) limit_1 = (int)(si_period <= 1 ? 1 : si_period) + (int)(si_slowing <= 1 ? 1 : si_slowing) - 1;

   

  //--- 6.2) B>@>9 ;8<8B 4;O 70<54;5=8O 7=0G5=89 Stability index

   int limit_2 = rates_total - prev_calculated - (int)(si_period <= 1 ? 1 : si_period) - (int)(si_slowing <= 1 ? 1 : si_slowing) + 1;

      if(limit_2 < 0) limit_2 = 0;

   

  //--- 6.3) 0?8AK205< =5 70<54;5==K5 7=0G5=8O Stability index 2 Inhibitor

   if(si_slowing > 1)

     {

      ArrayInitialize(Inhibitor,EMPTY_VALUE);

      for(int i = limit_1; i >= 0; i--) {Inhibitor[i] = SI_Value(i);};

     };

   

  //--- 6.4)  0AAG8BK205< 8B>3>2K5 7=0G5=8O Stability index

   for(int i = limit_2; i >= 0; i--)

     {

      

     //--- 6.4.1) A;8 =C6=> 70<54OBL 7=0G5=8O - 70<54;O5<

      if(si_slowing > 1) {Slowing(i,(int)si_slowing,si_method,SI);}

     //--- 6.4.2) ... 5A;8 =5B - 70?8AK205< 8E =5 70<54;OO

      else               {SI[i] = SI_Value(i);};

      

     //--- 6.4.3) #:07K205< F25B ;8=88 4;O :064>3> 10@0

      SCI[i] = (SI[i] > SI[i+1] ? 0 : 1);

      

     };

   

  }



//---  0AGQB SI -----------------------------------------------------



double SI_Value(int index)

  {

   double telo = 0, hvost = 0;

   int limit = index + (int)si_period;

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

     {

      telo += MathAbs(Open[i] - Close[i]);

      hvost += High[i] - Low[i] - MathAbs(Open[i] - Close[i]);

     };

   

   telo  = (telo == 0 ? 1 * _Point : telo);

   hvost = (hvost == 0 ? 1 * _Point : hvost);

   

  //-----------------------------------------------------------------

   return((telo >= hvost ? telo / hvost - 1 : (hvost / telo * (-1)) + 1) * si_norma);

  }





//-------------------------------------------------------------------------------------------------

//   Density index                                                                                |

//-------------------------------------------------------------------------------------------------



void DI_Function(const int rates_total,

                 const int prev_calculated)

  {

   

  //--- 7.1) 5@2K9 ;8<8B 4;O @0AGQB0 =5 70<54;5==KE 7=0G5=89 Density index

   int limit_1 = rates_total - prev_calculated - (int)(di_period <= 1 ? 1 : di_period) - 1;

      if(limit_1 < (int)(di_period <= 1 ? 1 : di_period) + (int)(di_slowing <= 1 ? 1 : di_slowing) - 1) limit_1 = (int)(di_period <= 1 ? 1 : di_period) + (int)(di_slowing <= 1 ? 1 : di_slowing) - 1;

   

  //--- 7.2) B>@>9 ;8<8B 4;O 70<54;5=8O 7=0G5=89 Density index

   int limit_2 = rates_total - prev_calculated - (int)(di_period <= 1 ? 1 : di_period) - (int)(di_slowing <= 1 ? 1 : di_slowing) + 1;

      if(limit_2 < 0) limit_2 = 0;

   

  //--- 7.3) 0?8AK205< =5 70<54;5==K5 7=0G5=8O Density index 2 Inhibitor

   if(di_slowing > 1)

     {

      ArrayInitialize(Inhibitor,EMPTY_VALUE);

      for(int i = limit_1; i >= 0; i--) {Inhibitor[i] = DI_Value(i);};

     };

   

  //--- 7.4)  0AAG8BK205< 8B>3>2K5 7=0G5=8O Density index

   for(int i = limit_2; i >= 0; i--)

     {

      

     //--- 7.4.1) A;8 =C6=> 70<54OBL 7=0G5=8O - 70<54;O5<

      if(di_slowing > 1) {Slowing(i,(int)di_slowing,di_method,DI);}

     //--- 7.4.2) ... 5A;8 =5B - 70?8AK205< 8E =5 70<54;OO

      else               {DI[i] = DI_Value(i);};

      

     //--- 7.4.3) #:07K205< F25B ;8=88 4;O :064>3> 10@0

      DCI[i] = (DI[i] > DI[i+1] ? 0 : 1);

      

     };

   

  }



//---  0AGQB DI -----------------------------------------------------



double DI_Value(int index)

  {

   double difference = 0, bars = 0;

   int limit = index + (int)di_period;

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

     {

      difference += MathMax(High[i],High[i+1]) - MathMin(Low[i],Low[i+1]);

      bars += (High[i] - Low[i]) + (High[i+1] - Low[i+1]);

     };

   

   difference = (difference == 0 ? 1 * _Point : difference);

   bars       = (bars == 0 ? 1 * _Point : bars);

   

  //-----------------------------------------------------------------

   return((bars / difference >= 1 ? bars / difference - 1 : (difference / bars * (-1)) + 1) * di_norma);

  }





//-------------------------------------------------------------------------------------------------

//   Inhibitor / 0<54;8B5;L                                                                      |

//-------------------------------------------------------------------------------------------------



void Slowing(int index, int slowing, ENUM_MA_METHOD method, double &Bufer[])

  {

   

   double value = 0, c = 2 / (double)(slowing + 1); int period = slowing, sum_p = 0;

   

  //--- @>AB>5 CA@54=5=85

   if(method == MODE_SMA)

     {

      

      for(int i = index; i < index + slowing; i++) {value += Inhibitor[i];};

      Bufer[index] = value / (double)slowing;

      

     }

   

  //--- -:A?>=5=F80;L=>5 CA@54=5=85

   else if(method == MODE_EMA)

     {

      

      if(Bufer[index+1] == EMPTY_VALUE)

        {

         for(int i = index; i < index + slowing; i++) {value += Inhibitor[i];};

         Bufer[index] = value / (double)slowing; return;

        };

      

      Bufer[index] = c * Inhibitor[index] + (1 - c) * Bufer[index+1];

      

     }

   

  //--- !3;065==>5 CA@54=5=85

   else if(method == MODE_SMMA)

     {

      

      if(Bufer[index+1] == EMPTY_VALUE)

        {

         for(int i = index; i < index + slowing; i++) {value += Inhibitor[i];};

         Bufer[index] = value / (double)slowing; return;

        };

      

      if(Bufer[index+1] != EMPTY_VALUE && Bufer[index+2] == EMPTY_VALUE)

        {

         for(int i = index; i < index + slowing; i++) {value += Inhibitor[i];};

         Bufer[index] = (value - Bufer[index+1] + Inhibitor[index]) / (double)slowing; return;

        };

      

      value = Bufer[index+1] * (double)slowing;

      Bufer[index] = (value - Bufer[index+1] + Inhibitor[index]) / (double)slowing;

      

     }

   

  //--- 8=59=>-2725H5==>5 CA@54=5=85

   else

     {

      

      for(int i = index; i < index + slowing; i++)

        {

         value += Inhibitor[i] * (double)period;

         sum_p += period;

         period--;

        };

      Bufer[index] = value / (double)sum_p;

      

     };

   

  }

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