1. Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
    Dismiss Notice

Question Cara membuat versi MTF(multi timeframe) indikator trendline

Discussion in 'Belajar MQL dari Nol' started by MazquFx, 22 Apr 2016.

  1. MazquFx

    MazquFx New Member

    Equity
    Credit
    Ref Point
    apakah ada rekan-rekan atau master-master yang bisa membantu saya untuk menjadikan indikator ini agar bisa di masukin input setingan TF (timeframe)
    indikator ini mengacu kepada indikator fractal dan membuat trendline scra otomatis..
    Code:
    //+------------------------------------------------------------------+
    //|                                     Fractals - adjustable period |
    //+------------------------------------------------------------------+
    #property link      "www.forex-tsd.com"
    #property copyright "www.forex-tsd.com"
    
    #property indicator_chart_window
    #property indicator_buffers 2
    #property indicator_color1  DeepSkyBlue
    #property indicator_color2  PaleVioletRed
    #property indicator_width1  0
    #property indicator_width2  0
    
    //
    //
    //
    //
    //
    
    extern int    FractalPeriod          = 5;
    extern double UpperArrowDisplacement = 0.1;
    extern double LowerArrowDisplacement = 0.1;
    extern int    Size_Fractal           = 0;
    extern color Color_fractal1     = Blue;
    extern color Color_fractal2     = Magenta;
    
    extern color  UpperColorLama1         = Green;
    extern color  LowerColorLama1         = Maroon;
    
    extern color  UpperColorLama2         = Gray;
    extern color  LowerColorLama2         = Gray;
    
    //extern color  UpperColorLama3         = Violet;
    //extern color  LowerColorLama3         = Violet;
    
    extern color  UpperCompletedColor    = DarkBlue;
    extern color  UpperUnCompletedColor  = DarkBlue;
    
    
    extern color  LowerCompletedColor    = Maroon;
    extern color  LowerUnCompletedColor  = Maroon;
    extern int    CompletedWidth         = 3;
    extern int    UnCompletedWidth       = 2;
    extern string UniqueID               = "FractalTrendLines1";
    
    double UpperBuffer[];
    double LowerBuffer[];
    
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    //
    //
    //
    //
    //
    
    int init()
    {
       if (MathMod(FractalPeriod,2)==0)
             FractalPeriod = FractalPeriod+1;
       SetIndexBuffer(0,UpperBuffer); SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,Size_Fractal,Color_fractal2); SetIndexArrow(0,217);
       SetIndexBuffer(1,LowerBuffer); SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,Size_Fractal,Color_fractal1); SetIndexArrow(1,218);
    }
    int deinit()
    {
       ObjectDelete(UniqueID+"up1");
       ObjectDelete(UniqueID+"up2");
       ObjectDelete(UniqueID+"up3");
       ObjectDelete(UniqueID+"up4");
       ObjectDelete(UniqueID+"up5");
       
       ObjectDelete(UniqueID+"dn1");
       ObjectDelete(UniqueID+"dn2");
       ObjectDelete(UniqueID+"dn3");
       ObjectDelete(UniqueID+"dn4");
       ObjectDelete(UniqueID+"dn5");
       
       return(0);
    }
    
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    //
    //
    //
    //
    //
    
    int start()
    {
       int half = FractalPeriod/2;
       int i,limit,counted_bars=IndicatorCounted();
    
       if(counted_bars<0) return(-1);
       if(counted_bars>0) counted_bars--;
               limit=MathMin(MathMax(Bars-counted_bars,FractalPeriod),Bars-1);
    
       //
       //
       //
       //
       //
    
       for(i=limit; i>=0; i--)
       {
             bool   found     = true;
             double compareTo = High[i];
             for (int k=1;k<=half;k++)
                {
                   if ((i+k)<Bars && High[i+k]> compareTo) { found=false; break; }
                   if ((i-k)>=0   && High[i-k]>=compareTo) { found=false; break; }
                }
             if (found)
                   UpperBuffer[i]=High[i]+iATR(NULL,0,20,i)*UpperArrowDisplacement;
             else  UpperBuffer[i]=EMPTY_VALUE;
    
          //
          //
          //
          //
          //
         
             found     = true;
             compareTo = Low[i];
             for (k=1;k<=half;k++)
                {
                   if ((i+k)<Bars && Low[i+k]< compareTo) { found=false; break; }
                   if ((i-k)>=0   && Low[i-k]<=compareTo) { found=false; break; }
                }
             if (found)
                  LowerBuffer[i]=Low[i]-iATR(NULL,0,20,i)*LowerArrowDisplacement;
             else LowerBuffer[i]=EMPTY_VALUE;
       }
       //
       //
       //
       //
       //
    
          int lastUp[6];
          int lastDn[6];
             int dnInd = -1;
             int upInd = -1;
             for (i=0; i<Bars; i++)
             {
                if (upInd<5 && UpperBuffer[i] != EMPTY_VALUE) { upInd++; lastUp[upInd] = i; }
                if (dnInd<5 && LowerBuffer[i] != EMPTY_VALUE) { dnInd++; lastDn[dnInd] = i; }
                   if (upInd==5 && dnInd==5) break;
             }
             createLine("up1",High[lastUp[1]],Time[lastUp[1]],High[lastUp[0]],Time[lastUp[0]],UpperUnCompletedColor,UnCompletedWidth);
             createLine("up2",High[lastUp[2]],Time[lastUp[2]],High[lastUp[1]],Time[lastUp[1]],UpperCompletedColor,CompletedWidth);
             createLine("up3",High[lastUp[3]],Time[lastUp[3]],High[lastUp[2]],Time[lastUp[2]],UpperColorLama1,UnCompletedWidth);
            createLine("up4",High[lastUp[4]],Time[lastUp[4]],High[lastUp[3]],Time[lastUp[3]],UpperColorLama2,UnCompletedWidth);
           //  createLine("up5",High[lastUp[5]],Time[lastUp[5]],High[lastUp[4]],Time[lastUp[4]],UpperColorLama3,UnCompletedWidth);
             
             
             createLine("dn1",Low[lastDn[1]] ,Time[lastDn[1]],Low[lastDn[0]] ,Time[lastDn[0]],LowerUnCompletedColor,UnCompletedWidth);
             createLine("dn2",Low[lastDn[2]] ,Time[lastDn[2]],Low[lastDn[1]] ,Time[lastDn[1]],LowerCompletedColor,CompletedWidth);
             createLine("dn3",Low[lastDn[3]] ,Time[lastDn[3]],Low[lastDn[2]] ,Time[lastDn[2]],LowerColorLama1,UnCompletedWidth);
           createLine("dn4",Low[lastDn[4]] ,Time[lastDn[4]],Low[lastDn[3]] ,Time[lastDn[3]],LowerColorLama2,UnCompletedWidth);
           //  createLine("dn5",Low[lastDn[5]] ,Time[lastDn[5]],Low[lastDn[4]] ,Time[lastDn[4]],LowerColorLama3,UnCompletedWidth);
             
             
       return(0);
    }
    
    //
    //
    //
    //
    //
    
    void createLine(string add, double price1, datetime time1, double price2, datetime time2, color theColor, int width)
    {
       string name = UniqueID+add;
          ObjectDelete(name);
          ObjectCreate(name,OBJ_TREND,0,time1,price1,time2,price2);
             ObjectSet(name,OBJPROP_COLOR,theColor);
             ObjectSet(name,OBJPROP_WIDTH,width);
    }
     

Share This Page