ivgf_SultonovPrediction_2

Author: Copyright © 2011, Юсуфходжа Султонов
Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
ivgf_SultonovPrediction_2
ÿþ//+------------------------------------------------------------------+

//|                                           SultonovPrediction.mq5 |

//|                             Copyright © 2011, .ACDE>460 !C;B>=>2 |

//| Realisation :             Goshkov Vladyslav 2011. 4vg AT mail.ru |

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

#property copyright "Copyright © 2011, .ACDE>460 !C;B>=>2"

#property link      ""



#property indicator_chart_window

#property indicator_plots 2

#property indicator_buffers 2

#property indicator_color1  clrBlue

#property indicator_width1  1

#property indicator_color2  clrRed

#property indicator_width2  1



input string   prf = "ivgfSP#";

input string   s003 = ""8? F5=K 4;O 8=48:0B>@0";

input string   s004 = "!>>B25BAB2C5B AB0=40@B=K< >1>7=0G5=8O< "";

input string   s005 = "> C<>;G0=8N Open. ";

input int      IndPRC_TYPE = PRICE_OPEN;



#define MXSIZE_KYPC   551

#define MXSIZE_P      801

input string   s00 = ">;8G5AB2> 10@>2 8AB>@88 4;O ?@>3=>70";

input string   s01 = "MAX = 550";

input int      HistoryBarsCount  =  30;

input string   s02 = "+----------------------------+";

input string   s03 = "><5@ 10@0, ?> B5:CH59 =C<5@0F88 10@>2,";

input string   s04 = "4;O :>B>@>3> 45;05BAO ?@>3=>7";

input int      FROM =  0;

input string   s10 = "+============================+";

input string   s11 = ">;8G5AB2> 10@>2 4;O ?@>3=>70";

input string   s12 = "!C<<0 0@>2 8AB>@88 8 ?@>3=>78@C5<KE 10@>2";

input string   s13 = "5 4>;6=0 ?@52KH0BL 800";

input int      PredictionBarsCount =  30;

input int      RetrospektivaBarsCount = 500;



int Shft = 12;

int SIZE_KYPC = 20;

int SIZE_P    = 60;

#define KYPC_DIGITS  6

double KYPC[MXSIZE_KYPC];/* = {1.3635, 1.3630, 1.3625, 1.3620, 1.3615,

                          1.3612, 1.3610, 1.3608, 1.3606, 1.3602,

                          1.3603

                         };

                         */

double cP1[MXSIZE_P],cP2[MXSIZE_P],cP3[MXSIZE_P];

double UpSig[];

double DnSig[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   SetIndexBuffer(0,UpSig,INDICATOR_DATA);

   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW);

   PlotIndexSetInteger(0,PLOT_ARROW,233);

   SetIndexBuffer(1,DnSig,INDICATOR_DATA);

   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW);

   PlotIndexSetInteger(1,PLOT_ARROW,234);

   ArraySetAsSeries(UpSig,true);

   ArraySetAsSeries(DnSig,true);

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---- indicators

   SIZE_KYPC = HistoryBarsCount;

   SIZE_P    = SIZE_KYPC + PredictionBarsCount;

//----

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

//deleteObjectsByPrefix(prf);

   ObjectsDeleteAll(0,prf);

   ChartRedraw();

//----

  }

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

//| Custom indicator iteration function                              |

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

/*

double GAMMADIST(double X, double Alfa, double betta, bool IsIntegral)

{

    if(betta==1)

        return(StdGAMMADIST());

    if(IsIntegral)

        return();

}



int P1Prediction(double Prc[])

{

int rez = 0;

int PrcCnt = ArraySize(Prc);

    return(rez);

}



int P2Prediction(double Prc[])

{

int rez = 0;

int PrcCnt = ArraySize(Prc);

    return(rez);

}



int P3Prediction(double Prc[])

{

int rez = 0;

int PrcCnt = ArraySize(Prc);

    return(rez);

}



int SultonovPrediction(double Prc[])

{

int res = P1Prediction(Prc)+P2Prediction(Prc)+P3Prediction(Prc);

    if(MathAbs(res)==3)

        return(res);

    return(0);

}

*/



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

//|                                                                  |

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

int SultonovPrediction(double &P1[], double &P2[], double &P3[], double &K[], int NP, int NK)

  {

   int i=0;

   int SzK = NK;

//ArraySize(K);

//Print("SzK = ",SzK );

   double tt[];

   ArrayResize(tt,NP);

   double tr[];

   ArrayResize(tr,NP);

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

     {

      tt[i] = i;

      tr[i] = i;

     }



   double SumK = 0.0;

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

     {

      SumK = SumK + K[i];

     }



   double SumJ = 0.0;

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

     {

      SumJ = SumJ + tt[i];

     }



   double k = -0.5+ MathSqrt(0.25+2.0*SumJ);//-0,5+(0,25+2*SUM(J$1:J$1048576))^0,5

//Print("SumJ = ",SumJ," k = ",k );

   /*

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

       {

           Print("K[",i,"] = ",DoubleToStr(K[i],KYPC_DIGITS) );

       }

   */

   double Cy[];    // dK = K[i+1]-K[i];

   ArrayResize(Cy,NP);

   Cy[0] = 0.0;

   for(i=1; i<SzK; i++)

     {

      Cy[i] = K[i]-K[i-1];

     }

   for(; i<NP; i++)

     {

      Cy[i] = 0;

     }

   /*

   for(i=1;i<SzK;i++)

   {

       Print("Cy[",i,"] = ",DoubleToStr(Cy[i],KYPC_DIGITS) );

   }

   */

   double xy[];    //tt[i]*Cy[i]

   ArrayResize(xy,SzK);

   for(i=1; i<SzK; i++)

     {

      xy[i] = tt[i]*Cy[i];

     }



   /*

   for(i=1;i<SzK;i++)

   {

       Print("xy[",i,"] = ",DoubleToStr(xy[i],KYPC_DIGITS) );

   }

   */

   double SumA = 0.0;

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

     {

      SumA = SumA + xy[i];

     }



//Print("SumA = ",SumA );

   double SumM = 0.0;

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

     {

      SumM = SumM + Cy[i];

     }

//Print("SumM = ",SumM );



//(H2*SUM(A$1:A$1048576)-SUM(J$1:J$1048576)*SUM(M$1:M$1048576))/((H2*(H3*(H3+1)*(2*H3+1)/6)-SUM(J$1:J$1048576)^2))

//(H2*SUM(A$1:A$1048576)-SUM(J$1:J$1048576)*SUM(M$1:M$1048576))

//((H2*(H3*(H3+1)*(2*H3+1)/6)-SUM(J$1:J$1048576)^2))

   double derr = 0.00000001;



   double b1 = (k*SumA-SumJ*SumM);

   double b2 = (k*(k*(k+1)*(2*k+1)/6.)-SumJ*SumJ);

   if(MathAbs(b2)<=derr)

     {

      if(b2>=0)

         b2 =  derr;

      if(b2< 0)

         b2 = -derr;

     }

   double b  = b1/b2;

//Print("b = ",DoubleToStr(b,10) );

//(SUM(M$1:M$1048576)*(H3*(H3+1)*(2*H3+1)/6)-SUM(J$1:J$1048576)*SUM(A$1:A$1048576))/(H2*(H3*(H3+1)*(2*H3+1)/6)-SUM(J$1:J$1048576)^2)+B2*I2

   double k1Yr2 = (k*(k*(k+1)*(2*k+1)/6.)-SumJ*SumJ);

   if(MathAbs(k1Yr2)<=derr)

     {

      if(k1Yr2>=0)

         k1Yr2 =  derr;

      if(k1Yr2< 0)

         k1Yr2 = -derr;

     }

   double k1Yr = (SumM*(k*(k+1)*(2*k+1)/6.)-SumJ*SumA)/k1Yr2;

//Print("k1Yr = ",DoubleToStr(k1Yr,10) );

   double Yr[];

   ArrayResize(Yr,NP);

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

     {

      Yr[i] = k1Yr  + b*tr[i];

     }

   /*

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

       {

           Print("Yr[",i,"] = ",DoubleToStr(Yr[i],14) );

       }

   */

   int Trend1[], Trend2[],Trend3[];

   ArrayResize(Trend1,NP);

   ArrayResize(Trend2,NP);

   ArrayResize(Trend3,NP);

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

     {

      if(SumA>0)

         Trend1[i] = 1;

      else

        {

         if(SumA<0)

            Trend1[i] = -1;

         else

            Trend1[i] =  0;



        }

      if(b>0)

         Trend2[i] = 1;

      else

        {

         if(b<0)

            Trend2[i] = -1;

         else

            Trend2[i] =  0;



        }

      if(Yr[i]>0)

         Trend3[i] = 1;

      else

        {

         if(Yr[i]<0)

            Trend3[i] = -1;

         else

            Trend3[i] =  0;



        }



     }

   /*

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

       {

           Print("TYrends[",i,"] => ", Trend1[i], " ", Trend2[i], " ", Trend3[i]);

       }

   */

//IF(J3>0;IF(K3-K2<0;LN(-(K3-K2)/(J3+J2)*2);LN((K3-K2)/(J3+J2)*2))*IF(J3=0;0;1);0)

   double LnC_t[];

   ArrayResize(LnC_t,NP);

   LnC_t[0] = 0;

   for(i=1; i<SzK; i++)

     {

      double dtt = (tt[i]+tt[i-1]);

      if(MathAbs(dtt)<derr)

        {

         if(dtt>=0)

            dtt =  derr;

         if(dtt< 0)

            dtt = -derr;

        }

      if(tt[i]>0)

        {

         if(Cy[i]<0)

           {

            LnC_t[i] = MathLog(-Cy[i]/(dtt*2.));//(tt[i]+tt[i-1])*2);

           }

         else

           {

            if(Cy[i]>0)

              {

               LnC_t[i] = MathLog(Cy[i]/(dtt*2.));//(tt[i]+tt[i-1])*2);

              }

            else

               LnC_t[i] = 0;

           }

        }

      else

         LnC_t[i] = 0;

     }

   /*

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

       {

           Print("LnC_t[",i,"] => ", LnC_t[i]);

       }

   */



//IF(J3>0;(J3+J2)/2*N3;0)

   double tLnC_t[];

   ArrayResize(tLnC_t,SzK);

   tLnC_t[0] = 0;

   for(i=1; i<SzK; i++)

     {

      if(tt[i]>0)

        {

         tLnC_t[i] = (tt[i]+tt[i-1])/2.*LnC_t[i];

        }

      else

         tLnC_t[i] = 0;

     }



   /*

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

       {

           Print("tLnC_t[",i,"] => ", tLnC_t[i]);

       }

   */

   double SumN = 0.0;

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

     {

      SumN = SumN + LnC_t[i];

     }



   double SumO = 0.0;

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

     {

      SumO = SumO + tLnC_t[i];

     }

//Print("SumN = ",SumN," SumO = ",SumO );



//(H3*(H3*(H3+1)*(2*H3+1)/6-(H3/2+0,25)*H3)-(H3*(H3+1)/2-H3/2)^2)/((H3*(H3+1)/2-H3/2)*SUM(N$1:N$1048576)-H3*SUM(O$1:O$1048576))

   double T2 = ((k*(k+1)/2.-k/2.)*SumN-k*SumO);

   if(MathAbs(T2)<=derr)

     {

      if(T2>=0)

         T2 =  derr;

      if(T2< 0)

         T2 = -derr;

     }

   double T = (k*(k*(k+1)*(2*k+1)/6.-(k/2.+0.25)*k)-(k*(k+1)/2.-k/2)*(k*(k+1)/2.-k/2))/T2;

   if(MathAbs(T)<=derr)

     {

      if(T>=0)

         T =  derr;

      if(T< 0)

         T = -derr;

     }

//Print("T = ",T );

//P3^2/EXP((SUM(N$1:N$1048576)*(H3*(H3+1)*(2*H3+1)/6-(H3/2+0,25)*H3)-(H3*(H3+1)/2-H3/2)*SUM(O$1:O$1048576))/(H3*(H3*(H3+1)*(2*H3+1)/6-(H3/2+0,25)*H3)-(H3*(H3+1)/2-H3/2)^2))

   double D2 = (k*(k*(k+1)*(2*k+1)/6.-(k/2.+0.25)*k)-(k*(k+1)/2.-k/2)*(k*(k+1)/2.-k/2)) ;//);

   if(MathAbs(D2)<=derr)

     {

      if(D2>=0)

         D2 =  derr;

      if(D2< 0)

         D2 = -derr;

     }

   double D = (T*T)/MathExp((SumN*(k*(k+1)*(2*k+1)/6.-(k/2.+0.25)*k)-(k*(k+1)/2.-k/2.)*SumO)/D2);

//Print("D = ",D );

   double P0 = K[0]+0.00000001;//(K2+0,00000001)*IF(K3=0;0;1)

   if(K[1]==0)

      P0=0.0;

// IF(E3>0;1;-1)*(1-(1+I3/P3)*EXP(-I3/P3))*Q3

   double PrE[];

   ArrayResize(PrE,SzK);

   PrE[0] = 0;

   for(i=1; i<SzK; i++)

     {

      PrE[i] = Trend1[i]*(1-(1+tr[i]/T)*MathExp(-tr[i]/T))*D;

     }



   /*

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

       {

           Print("PrE[",i,"] => ", PrE[i]);

       }

   */

   double SumT = 0.0;

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

     {

      SumT = SumT + PrE[i];

     }

   if(MathAbs(SumT)<=derr)

     {

      if(SumT>=0)

         SumT =  derr;

      if(SumT< 0)

         SumT = -derr;

     }

//Print("SumT = ",SumT );

//ABS((SUM(K$1:K$1048576)-(H3+1)*L3)/SUM(S$1:S$1048576))*P3^2/EXP((SUM(N$1:N$1048576)*(H3*(H3+1)*(2*H3+1)/6-(H3/2+0,25)*H3)-(H3*(H3+1)/2-H3/2)*SUM(O$1:O$1048576))/(H3*(H2*(H2+1)*(2*H2+1)/6-(H2/2+0,25)*H2)-(H3*(H3+1)/2-H3/2)^2))

   double DCorr = MathAbs((SumK-(k+1)*P0)/SumT)*(T*T)/MathExp((SumN*(k*(k+1)*(2*k+1)/6.-(k/2.+0.25)*k)-(k*(k+1)/2.-k/2)*SumO)/(k*(k*(k+1)*(2*k+1)/6.-(k/2.+0.25)*k)-(k*(k+1)/2.-k/2.)*(k*(k+1)/2.-k/2.)));//

//Print("DCorr = ",DCorr );

//(SUM(K$1:K$1048576)-L2-ABS((SUM(K$1:K$1048576)-(H3+1)*L3))*IF(E3<0;-1;1))/H3+(1-(1+I3/P3)*EXP(-I3/P3))*R3*IF(E3<0;-1;1)

   P1[0] = K[0];

   for(i=1; i<NP; i++)

     {

      P1[i] = (SumK-P0-MathAbs((SumK-(k+1)*P0))*Trend1[i])/k+(1-(1+tr[i]/T)*MathExp(-tr[i]/T))*DCorr*Trend1[i];

     }

//(SUM(K$1:K$1048576)-L2-ABS((SUM(K$1:K$1048576)-(H3+1)*L3))*IF(F3<0;-1;1))/H3+(1-(1+I3/P3)*EXP(-I3/P3))*R3*IF(F3<0;-1;1)

   P2[0] = K[0];

   for(i=1; i<NP; i++)

     {

      P2[i] = (SumK-P0-MathAbs((SumK-(k+1)*P0))*Trend2[i])/k+(1-(1+tr[i]/T)*MathExp(-tr[i]/T))*DCorr*Trend2[i];

     }

//(SUM(K$1:K$1048576)-L2-ABS((SUM(K$1:K$1048576)-(H3+1)*L3))*IF(G3<0;-1;1))/H3+(1-(1+I3/P3)*EXP(-I3/P3))*R3*IF(G3<0;-1;1)

   P3[0] = K[0];

   for(i=1; i<NP; i++)

     {

      P3[i] = (SumK-P0-MathAbs((SumK-(k+1)*P0))*Trend3[i])/k+(1-(1+tr[i]/T)*MathExp(-tr[i]/T))*DCorr*Trend3[i];

     }

   /*

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

       {

           Print("P1[",i,"] => ", DoubleToStr(P1[i],8)," P2[",i,"] => ", DoubleToStr(P2[i],8)," P3[",i,"] => ", DoubleToStr(P3[i],8) );

       }

   */

   int CurBarNumber = NK-1;

   int rez = Trend1[CurBarNumber]+Trend2[CurBarNumber]+Trend3[CurBarNumber];

//>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

   ArrayResize(PrE,0);

   ArrayResize(tLnC_t,0);

   ArrayResize(LnC_t,0);

   ArrayResize(Trend3,0);

   ArrayResize(Trend2,0);

   ArrayResize(Trend1,0);

   ArrayResize(Yr,0);

   ArrayResize(xy,0);

   ArrayResize(Cy,0);

   ArrayResize(tr,0);

   ArrayResize(tt,0);

   if(MathAbs(rez)==3)

      return(rez);

   return(0);

  }//int SultonovPrediction(double &P1[], double &P2[], double &P3[], int N, double K[])





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

//|                                                                  |

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

bool IsNewChartTFBar()

  {

   static int nB=-1,nP=-1;

   static datetime nT=-1;

   if((nB==Bars(_Symbol,_Period))&&(nT==iTime(_Symbol,_Period,0))&&(nP==Period()))

      return(false);

   nB = Bars(_Symbol,_Period);

   nT = iTime(_Symbol,_Period,0);

   nP = Period();

   return(true);

  }//IsNewChartTFBar()



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

//|                                                                  |

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

datetime GetTimeByBarNumber(string SMBL, ENUM_TIMEFRAMES periodInMin, int barNumber)

  {

   if(periodInMin == 0)

      periodInMin = Period();



   if(barNumber >= 0)

      return(iTime(SMBL, periodInMin, barNumber));

   else

      return(iTime(SMBL, periodInMin, 0) - barNumber*periodInMin*60);

  }



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

//|                                                                  |

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

string GetDateByBarTime(datetime bTm)

  {

   MqlDateTime dt;

   TimeToStruct(bTm,dt);

   return("Y:"+(string)dt.year+" M:"+(string)dt.mon+" D:"+(string)dt.day+" H:"+(string)dt.hour+" Min:"+(string)dt.min+" Sec:"+(string)dt.sec);

  }

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

//|                                                                  |

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

double mtGetPriceByType(int pType, int i=0)

  {

   double prc=-1;

   switch(pType)

     {

      case PRICE_CLOSE     :

         prc= iClose(_Symbol,_Period,i);

         break;//0

      case PRICE_OPEN      :

         prc= iOpen(_Symbol,_Period,i);

         break;//1

      case PRICE_HIGH      :

         prc= iHigh(_Symbol,_Period,i);

         break;//2

      case PRICE_LOW       :

         prc= iLow(_Symbol,_Period,i);

         break;//3

      case PRICE_MEDIAN    :

         prc= (iHigh(_Symbol,_Period,i)+iLow(_Symbol,_Period,i))*0.5;

         break;//4

      case PRICE_TYPICAL   :

         prc= (iHigh(_Symbol,_Period,i)+iLow(_Symbol,_Period,i)+iClose(_Symbol,_Period,i))/3;

         break;//5

      case PRICE_WEIGHTED  :

         prc= (iHigh(_Symbol,_Period,i)+iLow(_Symbol,_Period,i)+iClose(_Symbol,_Period,i)+iClose(_Symbol,_Period,i))*0.25;

         break;//6

      default              :

         prc= iClose(_Symbol,_Period,i);

         break;//0

     }

   return(prc);

  }//double mtGetPriceByType(int pType, int i=0 )





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

//|                                                                  |

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

int CheckSltPrdSignal(int &rezTrend, int _NP, double &_P1[], double &_P2[], double &_P3[], double &_K[], int PRC_TYPE=PRICE_OPEN, int BarsCnt=30, int _from=0, bool draw =  true)

  {

   int from = _from;

   if(PRC_TYPE!=PRICE_OPEN)

     {

      if(from<=0)

         from=1;

     }

   int j = from;

   int i = 0;

   int _NK = BarsCnt;

   double point001 = 0.001*_Point;



   if(BarsCnt>=MXSIZE_KYPC)

      return(- 1);

   if(_NP>=MXSIZE_P)

      return(-10);

   for(i=_NK-1; i>=0; i--,j++)

     {

      KYPC[i] = mtGetPriceByType(PRC_TYPE,j);//Open[j];//

      //Print("KYPC[",i,"] = ",KYPC[i]);

     }

   for(i=_NK-1; i>=0; i--)

     {

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

         if(MathAbs(KYPC[i]-KYPC[j])<point001)

            KYPC[j]=KYPC[j]+point001;

      //Print("KYPC[",i,"] = ",KYPC[i]);

     }



//Print("Call SP() !");

   rezTrend = SultonovPrediction(_P1, _P2, _P3, KYPC, _NP, _NK);

//Print("Call SP() Ok!");

   int j0=1, j1=2;

   int i0=1, i1=2;

//Print("SIZE_P = ", SIZE_P," SIZE_KYPC = ",SIZE_KYPC );

   /*

   for(int id=_NP-1; id>=0;id--)

   {

       Print("P1[",id,"] = ", P1[id]," P2[",id,"] = ", P2[id]," P3[",id,"] = ", P3[id]);

   }

   */

   if(!draw)

      return(0);

   j0 = _NK-i0;

   j1 = _NK-i1;

   for(; i1<_NP; i0++,i1++,j0--,j1--)

     {

      datetime Point1Time  = GetTimeByBarNumber(Symbol(), Period(), j0+from), Point2Time  = GetTimeByBarNumber(Symbol(), Period(), j1+from);

      //double   Point1Price = P1[i0], Point2Price = P1[i1];

      string LnNm = prf+(string)i0;

      //Print(LnNm," Point1Time = ",GetDateByBarTime(Point1Time), " Point1Price = ", Point1Price," Point2Time = ",GetDateByBarTime(Point2Time), " Point2Price = ", Point2Price );

      draw_line(prf+"#1"+"#"+(string)from+"#"+(string)HistoryBarsCount+"#"+(string)i0, Point1Time, cP3[i0], Point2Time, cP3[i1], Yellow, DRAW_LINE,  5);

      draw_line(prf+"#2"+"#"+(string)from+"#"+(string)HistoryBarsCount+"#"+(string)i0, Point1Time, cP2[i0], Point2Time, cP2[i1], Blue,   DRAW_LINE,  3);

      draw_line(prf+"#3"+"#"+(string)from+"#"+(string)HistoryBarsCount+"#"+(string)i0, Point1Time, cP1[i0], Point2Time, cP1[i1], Red,    STYLE_DASH, 0);

     }

   return(0);

  }



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

//|                                                                  |

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

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

  {

   if(rates_total-prev_calculated==0)

      return(rates_total);

//----

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

   ArrayInitialize(UpSig,0);

   ArrayInitialize(DnSig,0);

   for(int ib=fmin(RetrospektivaBarsCount-1,rates_total-1); ib>=FROM; ib--)

     {

      int trend=0;

      bool DrawIndi = false;

      if(ib==FROM)

         DrawIndi = true;

      int err = CheckSltPrdSignal(trend, SIZE_P, cP1, cP2, cP3, KYPC, IndPRC_TYPE, SIZE_KYPC, ib,  DrawIndi);

      UpSig[ib] = 0;

      DnSig[ib] = 0;



      if(trend==3)

        {

         UpSig[ib] = low[ib]  - Shft*_Point;

        }

      if(trend==-3)

        {

         DnSig[ib] = high[ib] + Shft*_Point;

        }

      //Print(ib," trend = ",trend ," UpSig = ",UpSig[ib]," DnSig = ",DnSig[ib]  );

     }

//Print(" >>>>>>>>>>>>> Culculation Ok ! <<<<<<<<<<<<<<< ");

   /*

   for( ib=RetrospektivaBarsCount-1;ib>=FROM;ib--)

   {

       Print("UpSig[",ib,"] = ",UpSig[ib]," DnSig[",ib,"] = ",DnSig[ib]  );

   }

   */

   ChartRedraw();

// ----

   return(rates_total);

  }



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

//|                                                                  |

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

int draw_line(string lnName, datetime TimeFrom, double PriceFrom, datetime TimeTo, double PriceTo, color c, int type, int width)

  {

   int     err = GetLastError();

   string  buff_str = lnName;

   err = 0;

   if(ObjectFind(0,buff_str)!=-1)

      ObjectDelete(0,buff_str);

   if(!ObjectCreate(0,buff_str, OBJ_TREND, 0, TimeFrom, PriceFrom, TimeTo, PriceTo))

     {

      err = GetLastError();

      Print("Can't create object #", buff_str, "# Error(",err,"):", err);

      return(err);

     }

   ObjectSetInteger(0,buff_str, OBJPROP_RAY, 0);

   ObjectSetInteger(0,buff_str, OBJPROP_COLOR, c);

   ObjectSetInteger(0,buff_str, OBJPROP_WIDTH, width);

   ObjectSetInteger(0,buff_str, OBJPROP_STYLE, type);

//ObjectMove(buff_str,0,TimeFrom, PriceFrom);

//ObjectMove(buff_str,1,TimeTo, PriceTo);

   return(0);

  }//





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

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

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