Скачать MetaTrader 5
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий
Скачай мобильную версию MetaTrader 5 и торгуй из любой точки мира!
vasile
15
vasile 2014.01.31 18:21 


пожалуйста, помогите с этим кодом, я не могу понять, где я совершал ошибки






//+------------------------------------------------------------------+
//|                                                Level Trading.mq4 |
//|                                                         by Accel |
//+------------------------------------------------------------------+
#property copyright "Accel"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//----









extern int     FractalBarsOnEachSide=7;
int     ProceedMaxHistoryBars=20000;
int     LevelActuality=1440;
int p=5;
extern int     ExtremumToLevelMaxGap=1;
extern double  PriceDeltaFor1Bar=0;
//----
int LevelLength[];
int LevelWidth[];
int PriceCrossedLevel;
double long[];
double short[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0,long);
   SetIndexBuffer(1,short);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   int i=0;
//----
   for(i=Bars-1;i>=0;i--)
      if (ObjectFind(StringConcatenate("Level_",1,"_",i))!=-1)
         ObjectDelete(StringConcatenate("Level_",1,"_",i));
   for(i=Bars-1;i>=0;i--)
      if (ObjectFind(StringConcatenate("Trend_",1,"_",i))!=-1)
         ObjectDelete(StringConcatenate("Trend_",1,"_",i));
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int LastBarWasHighLow(int LELB, int LEHB)
  {
   if (LELB==-1 && LEHB!=-1)
      return(1);
   
   if (LELB!=-1 && LEHB!=-1 && LELB!=LEHB)
      return(1);
  /* if (LELB!=-1 && LEHB!=-1 && LELB!=LEHB)
      return(-1);*/

  return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,j;
   int BarsToCheck;
   int Stop;
   int CurrState; //CurrState=0 - не нашли пересечения, 1-пересечение вверх, -1-пересечение вниз
   int LastExtremumHighBar=-1;
   int LastExtremumLowBar=-1;
   int LastExtremumBar=-1;
   double iFractalValue=0,jFractalValue=0;
//----
   if (IndicatorCounted()<0)
      return(-1);
   if (Bars-IndicatorCounted()==1)
      return(0);
//----
   deinit();
   SetIndexStyle(0,DRAW_ARROW,0,3);
   SetIndexArrow(0,251);
   SetIndexStyle(1,DRAW_ARROW,0,3);
   SetIndexArrow(1,251);
   ArrayInitialize(long,0);
   ArrayInitialize(short,0);
//----
   
  
//----
   
   ArrayResize(LevelLength,Bars);
   ArrayInitialize(LevelLength,0);
   ArrayResize(LevelWidth,Bars);
   ArrayInitialize(LevelWidth,1);
//----

  
  
  
   for(i=Bars;i>=FractalBarsOnEachSide;i--)
     {
      //Ищем нижний фрактал
      if (i==Lowest(Symbol(),Period(),MODE_LOW,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide))
        {
         switch(LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
           {
            case -1:
              {
               if ((Low[i]<Low[LastExtremumLowBar])&&Low[i]==iCustom(NULL,0,"MTF_FractalsChannel",p,false,1,i-FractalBarsOnEachSide))
                 {
                  long[i]=Low[i];
                  long[LastExtremumLowBar]=0;
                  LastExtremumLowBar=i;
                 }
               break;
              }
            case 1:
              {
               if ((Low[i]<High[LastExtremumHighBar])&&Low[i]==iCustom(NULL,0,"MTF_FractalsChannel",p,false,1,i-FractalBarsOnEachSide))
                 {
                  long[i]=Low[i];
                  LastExtremumLowBar=i;
                 }
               break;
              }
            case 0:
              {
               long[i]=Low[i];
               LastExtremumLowBar=i;
               break;
              }
           }
        }
      //Ищем верхний фрактал
      if (i==Highest(Symbol(),Period(),MODE_HIGH,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide) && long[i]==0)
        {
         switch(LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
           {
            case 1:
              {
               if ((High[i]>High[LastExtremumHighBar]/*||High[i]<High[LastExtremumHighBar]*/)&&High[i]==iCustom(NULL,0,"MTF_FractalsChannel",p,false,2,i))
                 {
                  short[i]=High[i];
                  short[LastExtremumHighBar]=0;
                  LastExtremumHighBar=i;
                 }
               break;
              }
            case -1:
              {
               if ((High[i]>Low[LastExtremumLowBar]/*||High[i]<Low[LastExtremumHighBar]*/)&&High[i]==iCustom(NULL,0,"MTF_FractalsChannel",p,false,2,i))
                 {
                  short[i]=High[i];
                  LastExtremumHighBar=i;
                 }
               break;
              }
            case 0:
              {
               short[i]=High[i];
               LastExtremumHighBar=i;
               break;
              }
           }
        }
     }
   
  for(i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
     {
      if (long[i]==Low[i])
        {
         Stop=-1;
         CurrState=0;
         for(j=i-1;j>=0 && Stop==-1;j--)
           {
            if (CurrState==-1)
               if (High[j]>Low[i]+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
                  Stop=j;
            if (CurrState==0)
               if (Low[j]<Low[i]+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
                  CurrState=-1;
           }
         if (Stop!=-1)
            LevelLength[i]=i-Stop;
         else
            LevelLength[i]=i;
        }
      if (short[i]==High[i])
        {
         Stop=-1;
         CurrState=0;
         for(j=i-1;j>=0 && Stop==-1;j--)
           {
            if (CurrState==1)
               if (Low[j]<High[i]+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
                  Stop=j;
            if (CurrState==0)
               if (High[j]>High[i]+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
                  CurrState=1;
           }
         if (Stop!=-1)
            LevelLength[i]=i-Stop;
         else
            LevelLength[i]=i;
        }
     }
   //aproximeaza
  for(i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
     {
      if (LevelLength[i]>0)
        {
         if (long[i]!=0)
            iFractalValue=long[i];
         if (short[i]!=0)
            iFractalValue=short[i];
         BarsToCheck=MathMin(LevelActuality,LevelLength[i]);
         j=i-1;
         LevelLength[i]=BarsToCheck;
         while(BarsToCheck>0)
           {
            if (LevelLength[j]>0)
              {
               if (long[j]!=0)
                  jFractalValue=long[j];
               if (short[j]!=0)
                  jFractalValue=short[j];
               if (MathAbs(iFractalValue+(i-j)*PriceDeltaFor1Bar*Point-jFractalValue)<ExtremumToLevelMaxGap*Point)
                 {
                  BarsToCheck=MathMin(LevelActuality,LevelLength[j]);
                  LevelLength[i]=i-j+BarsToCheck;
                  LevelLength[j]=0;
                  LevelWidth[i]++;
                 }
              }
            BarsToCheck--;
            j--;
           }
        }
     }

  
   // linii gri dispar
   for(i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
     {
      if (LevelLength[i]!=0)
        {
         if (long[i]!=0)
            iFractalValue=long[i];
         if (short[i]!=0)
            iFractalValue=short[i];
//----
         ObjectCreate(StringConcatenate("Level_",1,"_",i),OBJ_TREND,0,
               Time[i],iFractalValue,Time[i-LevelLength[i]],iFractalValue+LevelLength[i]*PriceDeltaFor1Bar*Point);
         if (i!=LevelLength[i])
            ObjectSet(StringConcatenate("Level_",1,"_",i),OBJPROP_RAY,0);
         ObjectSet(StringConcatenate("Level_",1,"_",i),OBJPROP_COLOR,DarkGray);
         if (LevelWidth[i]>1)
           {
           

ObjectSet(StringConcatenate("Level_",1,"_",i),OBJPROP_WIDTH,LevelWidth[i]);

           }
         else
           {
            ObjectSet(StringConcatenate("Level_",1,"_",i),OBJPROP_COLOR,DarkGray);
            ObjectSet(StringConcatenate("Level_",1,"_",i),OBJPROP_STYLE,STYLE_DOT);
           }
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
Vladimir Skorina
488
Vladimir Skorina 2014.02.01 06:29  
что конкретно надо? народу не очень хочеться сотню кода листать и разбираться.. скажи что тебе надо и что у тебя получаеться..
vasile
15
vasile 2014.02.01 07:31  
мне нада чтобы принцып рисунка сработал, чтобы когда меняться ширина, было так A - - - - - - B -------------- C
в данном коде он делает так A ----------- B -------------- C
/
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий