TRUE Forex

Просмотр кода форекс индикатора !!XCM-MT4-07 LSMA TF1.mq4

//+------------------------------------------------------------------+
//|                                                 Copyright © 2010, JACreative |
//|                                                                 KGForexWorld.com |
//|                                                       Update: 01-Agustus-2011 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, KGForexWorld.com"
#property link      "http://www.kgforexworld.com"

#property indicator_chart_window
#property indicator_buffers 8

extern    string    Readme1            = "#--- Periode Huruf/Angka",
                        Readme2            = "5M 15M 30M 1H 4H 8H 12H 16H",
                        Readme3            = "1D 1W 2W 1MH 4MH 6MH 1Y 4Y",
                        Periode            = "8H",
                        PriceMode        = "HLOC";
extern    bool        BolingerBands    = false,
                        Prediktor        = false,
                        ShowID             = true,
                        ShowPrice         = false;
extern    color        MidUpColor        = 0,
                        MidDownColor    = 0,
                        BBColor            = 0;
extern    int        MidWidth            = 3,
                        BBWidth            = 1;
extern    int        LabelDistance    = 30;
extern    bool        ALARM                = false;

int        Per,TPer,CBar,TChar,LIST[10];

double    LSMA_MID_UP[],LSMA_MID_DOWN[],
            LSMA_BB_UP_01[],LSMA_BB_UP_02[],LSMA_BB_UP_03[],
            LSMA_BB_DOWN_01[],LSMA_BB_DOWN_02[],LSMA_BB_DOWN_03[],
            X,X2,Y[2],XY[2],
            P_Y,P_XY,
            A,B,PosisiHarga,PosisiLastHarga,STDDEV,
            LinePrice,SelisihLinePrice,BB;

color        MidUp,MidDown,TMPWarna;

bool        FIRST = true,
            ERROR = false;

string    NamaLabel,SaveAlarm;

datetime NewBar;

//+------------------------------------------------------------------+
//| init()                                                                         |
//+------------------------------------------------------------------+
int init(){
    int i;

    // indikator Digits+1 digit, Perubahan warna lebih Presisi
    IndicatorDigits(Digits+2);

    if(GlobalVariableCheck("CBar"))
        CBar = GlobalVariableGet("CBar");
    else    
        GlobalVariableSet("CBar",0);

    TChar = StringLen(PriceMode);
    for(i=0;i<TChar;i++){
        LIST[i] = StringGetChar(PriceMode,i);
    }

    if(Periode == "4Y" || Periode == "4y")                { Periode = "4Y";        MidUp    = RosyBrown;        MidDown    = Red;                Per = MathCeil((345600*4)/Period()); }
    else if(Periode == "1Y" || Periode == "1y")        { Periode = "1Y";        MidUp    = RosyBrown;        MidDown    = Red;                Per = MathCeil(345600/Period()); }
    else if(Periode == "6MH"    || Periode == "6mh")    { Periode = "6MH";    MidUp    = YellowGreen;        MidDown    = Red;                Per = MathCeil(172800/Period()); }
    else if(Periode == "4MH"    || Periode == "4mh")    { Periode = "4MH";    MidUp    = Olive;                MidDown    = C'60,60,0';        Per = MathCeil(115200/Period()); }
    else if(Periode == "1MH"    || Periode == "1mh")    { Periode = "1MH";    MidUp    = DodgerBlue;       MidDown    = DodgerBlue;        Per = MathCeil(28800/Period()); }
    else if(Periode == "2W"        || Periode == "2w")    { Periode = "2W";        MidUp    = Maroon;            MidDown    = Red;                Per = MathCeil(14400/Period()); }
    else if(Periode == "1W"        || Periode == "1w")    { Periode = "1W";        MidUp    = Magenta;            MidDown    = Magenta;            Per = MathCeil(7200/Period()); }
    else if(Periode == "1D"        || Periode == "1d")    { Periode = "1D";        MidUp    = Lime;                MidDown    = Lime;             Per = MathCeil(1440/Period()); }
    else if(Periode == "16H"    || Periode == "16h")    { Periode = "16H";    MidUp    = Coral;                MidDown    = Red;                Per = MathCeil(960/Period()); }
    else if(Periode == "12H"    || Periode == "12h")    { Periode = "12H";    MidUp    = Orchid;            MidDown    = C'101,32,134';    Per = MathCeil(720/Period()); }
    else if(Periode == "8H"        || Periode == "8h")    { Periode = "8H";        MidUp    = Blue;               MidDown    = White;              Per = MathCeil(480/Period()); }
    else if(Periode == "7H"        || Periode == "7h")    { Periode = "7H";        MidUp    = White;                MidDown    = White;                Per = MathCeil((60*7)/Period()); }
    else if(Periode == "6H"        || Periode == "6h")    { Periode = "6H";        MidUp    = White;                MidDown    = White;                Per = MathCeil((60*6)/Period()); }
    else if(Periode == "4H"        || Periode == "4h")    { Periode = "4H";        MidUp    = Turquoise;        MidDown    = RoyalBlue;        Per = MathCeil(240/Period()); }
    else if(Periode == "3H"        || Periode == "3h")    { Periode = "3H";        MidUp    = White;                MidDown    = White;                Per = MathCeil((60*3)/Period()); }
    else if(Periode == "2H"        || Periode == "2h")    { Periode = "2H";        MidUp    = Blue;                MidDown    = White;                Per = MathCeil((60*2)/Period()); }
    else if(Periode == "1H"        || Periode == "1h")    { Periode = "1H";        MidUp    = Red;                MidDown    = Red;                Per = MathCeil(60/Period()); }
    else if(Periode == "30M"    || Periode == "30m")    { Periode = "30M";    MidUp    = DarkViolet;        MidDown    = Red;                Per = MathCeil(30/Period()); }
    else if(Periode == "15M"    || Periode == "15m")    { Periode = "15M";    MidUp    = White;                MidDown    = Red;                Per = MathCeil(15/Period()); }
    else if(Periode == "5M"        || Periode == "5m")    { Periode = "5M";        MidUp    = Peru;                MidDown    = Red;                Per = MathCeil(5/Period()); }
    else{
      if(IsDigit(Periode)){
         MidUp        = White;
         MidDown    = White;
            Per    = StrToInteger(Periode);
        }
        else{
            Alert("Periode tidak ditemukan!");
            ERROR = true;
            return(0);
        }
    }

    if(MidUpColor != 0)
        MidUp    = MidUpColor;
        
    if(MidDownColor != 0)
        MidDown    = MidDownColor;
        
    if(BBColor == 0){
        BBColor             = MidUp;
    }

    
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, MidWidth, MidUp);
   SetIndexBuffer(0, LSMA_MID_UP);
    SetIndexLabel(0, "LSMA "+Periode+" UP");

    if(MidUp != MidDown){
       SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, MidWidth, MidDown);
       SetIndexBuffer(1, LSMA_MID_DOWN);
       SetIndexLabel(1, "LSMA "+Periode+" Down");
    }

    if(BolingerBands){
       SetIndexStyle(2, DRAW_LINE, STYLE_DOT, BBWidth, BBColor);
       SetIndexBuffer(2, LSMA_BB_UP_01);
           SetIndexLabel(2, "LSMA "+Periode+" SD +1");

       SetIndexStyle(3, DRAW_LINE, STYLE_DOT, BBWidth, BBColor);
        SetIndexBuffer(3, LSMA_BB_DOWN_01);
       SetIndexLabel(3, "LSMA "+Periode+" SD -1");
    
       SetIndexStyle(4, DRAW_LINE, STYLE_DOT, BBWidth, BBColor);
       SetIndexBuffer(4, LSMA_BB_UP_02);
       SetIndexLabel(4, "LSMA "+Periode+" SD +2");

       SetIndexStyle(5, DRAW_LINE, STYLE_DOT, BBWidth, BBColor);
       SetIndexBuffer(5, LSMA_BB_DOWN_02);
       SetIndexLabel(5, "LSMA "+Periode+" SD -2");
   
       SetIndexStyle(6, DRAW_LINE, STYLE_SOLID, BBWidth, BBColor);
       SetIndexBuffer(6, LSMA_BB_UP_03);
       SetIndexLabel(6, "LSMA "+Periode+" SD +3");
   
       SetIndexStyle(7, DRAW_LINE, STYLE_SOLID, BBWidth, BBColor);
       SetIndexBuffer(7, LSMA_BB_DOWN_03);
       SetIndexLabel(7, "LSMA "+Periode+" SD -3");
    }

    NamaLabel    = "P_KGLSMA"+Periode+PriceMode;
    deinit();
}// END init


//+-------------------------------------------------------------------+
//| deinit                                                                          |
//+-------------------------------------------------------------------+
void deinit(){
    int i,obj_total;
    string name;
    obj_total=ObjectsTotal();
    for(i=obj_total;i>=0;i--){
        name    = ObjectName(i);
        if(StringFind(name, NamaLabel, 0) != -1)
            ObjectDelete(name);
    }

    //GlobalVariableDel("_LSMA_BB_"+Symbol()+Period()+"_"+Periode+"_"+PriceMode+"_0");
}


//+------------------------------------------------------------------+
//| start                                                                           |
//+------------------------------------------------------------------+
void start(){

    if((Per <= 0) || ERROR)
        return(0);
    
    int        i,j,limit,counted_bars;

    counted_bars    = IndicatorCounted();

   if (counted_bars < 0)    return(-1);
   if(counted_bars > 0)        counted_bars++;

    limit    = Bars-counted_bars;

    if(counted_bars == 0){
       deinit();
        TPer    = Per-1;
        X        = 0;
        X2     = 0;    
        XY[1] = 0;    XY[0] = 0;
        Y[1]    = 0;    Y[0]    = 0;
        for(i=1;i<=Per;i++){
            X    += i;
            X2    += i*i; 
        }

        if((CBar!=0) && (limit>=CBar+(Per+1)))
            limit    = CBar;
        else
            limit -=(Per+1);
    }

    for(i=limit; i>=0; i--){
        while(TPer>0){
            PosisiHarga = POSISI_HARGA(i+TPer);
            Y[1]    += PosisiHarga;
            XY[1]    += (Per-TPer)*PosisiHarga;
            TPer--;
        }
        // Tambah Kepala
        PosisiHarga    = POSISI_HARGA(i);
        Y[0]    = Y[1] + PosisiHarga;
        XY[0]    = XY[1] + (Per*PosisiHarga);

        // Kalkulasi
        B = ((Per*XY[0])-(X*Y[0]))/((Per*X2)-(X*X));
        A = (Y[0]-(B*X))/Per;
        LSMA_MID_UP[i]    = A+(B*Per);

        if(LSMA_MID_UP[i+1] > LSMA_MID_UP[i]){
            if((LSMA_MID_DOWN[i+1] == EMPTY_VALUE) && (LSMA_MID_DOWN[i+2] != EMPTY_VALUE)){
                SET_LINE(Time[i+2], Time[i+2], Time[i+1], LSMA_MID_UP[i+2], LSMA_MID_UP[i+1], MidUp);
            }
            LSMA_MID_DOWN[i]        = LSMA_MID_UP[i];
            LSMA_MID_DOWN[i+1]    = LSMA_MID_UP[i+1];
        }
        else{
            LSMA_MID_DOWN[i]        = EMPTY_VALUE;
            if(LSMA_MID_UP[i+2] < LSMA_MID_UP[i+1])
                LSMA_MID_DOWN[i+1]    = EMPTY_VALUE;
            ObjectDelete(NamaLabel+Time[i+2]);
        }

        if(BolingerBands){
            STDDEV=0;
            for(j=1; j<=Per; j++)
                STDDEV += MathPow(POSISI_HARGA((i+Per)-j)-(A+(B*j)),2);

            STDDEV = MathSqrt(STDDEV/Per);

            LSMA_BB_UP_01[i]        = LSMA_MID_UP[i]+STDDEV;
            LSMA_BB_DOWN_01[i]    = LSMA_MID_UP[i]-STDDEV;

            LSMA_BB_UP_02[i]        = LSMA_MID_UP[i]+STDDEV*2;
            LSMA_BB_DOWN_02[i]    = LSMA_MID_UP[i]-STDDEV*2;

            LSMA_BB_UP_03[i]        = LSMA_MID_UP[i]+STDDEV*3;
            LSMA_BB_DOWN_03[i]    = LSMA_MID_UP[i]-STDDEV*3;
        }
        // BB GLOBAL VARIABEL
        else if((i==0) && (ShowID)){
            STDDEV=0;
            for(j=1; j<=Per; j++)
                STDDEV += MathPow(POSISI_HARGA((i+Per)-j)-(A+(B*j)),2);
            STDDEV = MathSqrt(STDDEV/Per);
        }
        
        // Kurang Ekor
        if(i!=0){
            PosisiLastHarga    = POSISI_HARGA(i+(Per-1));
            XY[0]    = XY[0] - Y[0];
            Y[0]    = Y[0] - PosisiLastHarga;
            
            XY[1]    = XY[0];
            Y[1]    = Y[0];
        }
    }// END FOR

    if(ShowID)
        BB    = (Close[0]-LSMA_MID_UP[0])/STDDEV;
    //GlobalVariableSet("_LSMA_BB_"+Symbol()+Period()+"_"+Periode+"_"+PriceMode+"_0", BB);

    // Prediktor ------------------------------------------------------------------
    if(Prediktor){
        P_Y    = Y[0];
        P_XY    = XY[0];

        // Kurang Ekor
        PosisiLastHarga = POSISI_HARGA(Per-1);
        P_XY    -= P_Y;
        P_Y    -= PosisiLastHarga;

        // Tambah Next Kepala
        PosisiHarga        = Close[0];
        P_Y    += PosisiHarga;
        P_XY    += Per*PosisiHarga;

        // Kalkulasi
        B = ((Per*P_XY)-(X*P_Y))/((Per*X2)-(X*X));
        A = (P_Y-(B*X))/Per;
        LinePrice    = A+(B*Per);

        if(LinePrice>LSMA_MID_UP[0])
            SET_LINE("PLSMA", Time[0], Time[0]+(Period()*60), LSMA_MID_UP[0], LinePrice, MidUp);
        else
            SET_LINE("PLSMA", Time[0], Time[0]+(Period()*60), LSMA_MID_UP[0], LinePrice, MidDown);

        if(NewBar != Time[0]){
            SaveAlarm    = "";
            NewBar        = Time[0];
        }
        
        if((ALARM) && (SaveAlarm=="")){
            // UP
            if((LSMA_MID_UP[1]>LSMA_MID_UP[0]) && (LSMA_MID_UP[0] < LinePrice)){
                PrintAll(StringConcatenate(" ",Symbol()," TF:",Period()," LSMA [",Periode,"] UP"), true, false, true);
                SaveAlarm    = "UP";
            }
            // DOWN
            else if((LSMA_MID_UP[1]<LSMA_MID_UP[0]) && (LSMA_MID_UP[0] > LinePrice)){
                PrintAll(StringConcatenate(" ",Symbol()," TF:",Period()," LSMA [",Periode,"] DOWN"), true, false, true);
                SaveAlarm    = "DOWN";
            }
        }
    }

    if(ShowID || ShowPrice){
        if(LSMA_MID_UP[0] < LSMA_MID_UP[1])
            TMPWarna = MidDown;
        else
            TMPWarna = MidUp;

        SET_LABEL("LSMA_MID", DoubleToStr(BB,1)+" "+Periode+" LSMA       ", Time[0]+(Period()*60*LabelDistance), LSMA_MID_UP[0], TMPWarna);

        if(BolingerBands){
            SET_LABEL("LSMA_U1", "+1", Time[0]+(Period()*60*LabelDistance), LSMA_BB_UP_01[0], BBColor);
            SET_LABEL("LSMA_U2", "+2", Time[0]+(Period()*60*LabelDistance), LSMA_BB_UP_02[0], BBColor);
            SET_LABEL("LSMA_U3", "+3", Time[0]+(Period()*60*LabelDistance), LSMA_BB_UP_03[0], BBColor);

            SET_LABEL("LSMA_L1", "-1", Time[0]+(Period()*60*LabelDistance), LSMA_BB_DOWN_01[0], BBColor);
            SET_LABEL("LSMA_L2", "-2", Time[0]+(Period()*60*LabelDistance), LSMA_BB_DOWN_02[0], BBColor);
            SET_LABEL("LSMA_L3", "-3", Time[0]+(Period()*60*LabelDistance), LSMA_BB_DOWN_03[0], BBColor);
        }
    }

}// END START


//+------------------------------------------------------------------+
//| PrintAll()                                                                         |
//+------------------------------------------------------------------+
void PrintAll(string TEXT, bool PRINT=true, bool COMMENT=false, bool ALERT=false){
    if(PRINT)
      Print(TEXT);
    if(COMMENT)
      Comment(TEXT);
    if(ALERT)
      Alert(TEXT);
}


//+------------------------------------------------------------------+
//|  SET_LINE                                                        |
//+------------------------------------------------------------------+
void SET_LINE(string name, datetime Tm1, datetime Tm2, double Prc1,  double Prc2, color clr=Lime){
    if(ObjectFind(NamaLabel+name) == -1)
        ObjectCreate(NamaLabel+name, OBJ_TREND,0,Tm1,Prc1,Tm2,Prc2);

    ObjectSet(NamaLabel+name, OBJPROP_TIME1, Tm1);
    ObjectSet(NamaLabel+name, OBJPROP_TIME2, Tm2);
    ObjectSet(NamaLabel+name, OBJPROP_PRICE1, Prc1);
    ObjectSet(NamaLabel+name, OBJPROP_PRICE2, Prc2);

    ObjectSet(NamaLabel+name, OBJPROP_RAY, false);
    ObjectSet(NamaLabel+name, OBJPROP_WIDTH, MidWidth);
    ObjectSet(NamaLabel+name, OBJPROP_COLOR, clr);
    ObjectSet(NamaLabel+name, OBJPROP_STYLE, STYLE_SOLID);
    //ObjectSet(NamaLabel+name, OBJPROP_BACK, false);

}


//+------------------------------------------------------------------+
//| POSISI_HARGA                                                                     |
//+------------------------------------------------------------------+
double POSISI_HARGA(int Bar){

    int i;
    double POSISI=0;
    //H=104/72 L=76/108 O=79/111    C=67/99

    for(i=0;i<TChar;i++){
        //-- HIGH
        if((LIST[i] == 104) || (LIST[i] == 72)){
            POSISI += High[Bar];
        }
        //-- LOW
        else if((LIST[i] == 76) || (LIST[i] == 108)){
            POSISI += Low[Bar];
        }
        //-- OPEN
        else if((LIST[i] == 79) || (LIST[i] == 111)){
            POSISI += Open[Bar];
        }    
        //-- CLOSE
        else if((LIST[i] == 67) || (LIST[i] == 99)){
            POSISI += Close[Bar];
        }
    }
    return(POSISI/TChar);
}// END POSISI_HARGA



//+------------------------------------------------------------------+
//|  SET_LABEL                                                       |
//+------------------------------------------------------------------+
void SET_LABEL(string NAMA, string TEXT, datetime WAKTU, double HARGA, color WARNA){

    if(ShowPrice){
        if(ObjectFind(NamaLabel+NAMA) == -1)
            ObjectCreate(NamaLabel+NAMA, OBJ_ARROW, 0, WAKTU, HARGA);

        ObjectSet(NamaLabel+NAMA, OBJPROP_TIME1, WAKTU);
        ObjectSet(NamaLabel+NAMA, OBJPROP_PRICE1, HARGA);
        ObjectSet(NamaLabel+NAMA, OBJPROP_COLOR, WARNA);
        ObjectSet(NamaLabel+NAMA, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
    }

    if(ShowID){
        NAMA = NAMA+" TXT";
       if(ObjectFind(NamaLabel+NAMA) == -1)
            ObjectCreate(NamaLabel+NAMA, OBJ_TEXT, 0, WAKTU, HARGA);

        ObjectSet(NamaLabel+NAMA, OBJPROP_TIME1, WAKTU);
        ObjectSet(NamaLabel+NAMA, OBJPROP_PRICE1, HARGA);
        ObjectSetText(NamaLabel+NAMA, TEXT, 8, "Verdana", WARNA);
        ObjectSetText(NamaLabel+NAMA, TEXT, 8, "Verdana", WARNA);
    }
}// END SET_LABEL


//+------------------------------------------------------------------+
//| IsDigit                                                          |
//+------------------------------------------------------------------+
bool IsDigit(string str){
   bool        result=true;
   string    s=str;
   int         lenght=StringLen(str)-1,symbol;

   while(lenght>0){
      symbol=StringGetChar(s,lenght);
      if(!(symbol>47 && symbol<58)){
         result=false;
         break;
      }
      lenght--;
   }
   return(result);
}

Комментарии к исходному коду форекс индикатора !!XCM-MT4-07 LSMA TF1.mq4
В целях безопасности и борьбы со спамом в тексте комментариев запрещено размещать html-теги и ссылки. Благодарим за понимание.

  • X
  • 0% загружено
« индикатор !!XCM-MT4-06 RSI.mq4
индикатор !!XCM-MT4-07 LSMA TF4.mq4 »