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

Mohon koreksinya untuk coding indi saya suhu

Discussion in 'Belajar MQL dari Nol' started by iyoks, 13 Apr 2020.

  1. iyoks

    iyoks New Member

    Equity
    Credit
    Ref Point
    Saya ingin bikin indikator dari oprekan indi lama yang bisa menampilkan candle daily sama weekly secara bersamaan pada chart TF H1. namun saya coba utak atik candle weeklynya ga muncul dan juga sekalian nambahin opsi true atau false untuk tampilan candle Weekly nya bisa full color pada bodynya ga hanya garis kotak saja. mohon masukannya dibagian mana bisa saya perbaiki suhu

    Code:
    extern string Timeframe="D1";
    extern string Timeframe="W1";
    extern int CountBars=5;
    extern color Bear=clrRed;
    extern color Bull=clrGreen;
    extern int ColorUp=clrGreen;
    extern int ColorDown=clrRed;
    extern int  Width =2;
    extern bool Background= false;
    //----
    
       datetime time1;
       datetime time2;
       double open_price,close_price;
       int bar_tf;
       int PeriodName=0;
       int num=0;
       string error="EROR :)";
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
       void ObjDel()
      {
       for(;num>=0;num--)
          ObjectDelete("Objtf"+num);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int init()
      {
       if (Timeframe=="M1") PeriodName=PERIOD_M1;
       else
          if (Timeframe=="M5") PeriodName=PERIOD_M5;
          else
             if (Timeframe=="M15")PeriodName=PERIOD_M15;
             else
                if (Timeframe=="M30")PeriodName=PERIOD_M30;
                else
                   if (Timeframe=="H1") PeriodName=PERIOD_H1;
                   else
                      if (Timeframe=="H4") PeriodName=PERIOD_H4;
                      else
                         if (Timeframe=="D1") PeriodName=PERIOD_D1;
                         else
                            if (Timeframe=="W1") PeriodName=PERIOD_W1;
                            else
                               if (Timeframe=="MN") PeriodName=PERIOD_MN1;
                               else
                                 {
                                  Comment(error);
                                  return(0);
                                 }
       Comment("LargeTimeframe(",Timeframe,")");
       return(0);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int deinit()
      {
       ObjDel();
       Comment("");
       return(0);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    int start()
      {
       int i;
       ObjDel();
       num=0;
    //----
       if (PeriodName<=Period())
         {
          Comment(error);
          return(0);
         }
    //----
       for(bar_tf=CountBars;bar_tf>=0;bar_tf--)
         {
          time1=iTime(NULL,PeriodName,bar_tf);
          i=bar_tf-1;
          if (i<0)
             time2=Time[0];
          else
             time2=iTime(NULL,PeriodName,i)-Period()*60;
          open_price=iOpen(NULL,PeriodName,bar_tf);
          close_price=iClose(NULL,PeriodName,bar_tf);
    //---
          ObjectCreate("Objtf"+num,OBJ_RECTANGLE,0,time1,open_price,time2,close_price);
          ObjectSetInteger(0,"Objtf"+num, OBJPROP_BACK, Background );
          ObjectSet("Objtf"+num, OBJPROP_WIDTH, Width);
          ObjectSet("Objtf"+num, OBJPROP_RAY, false);
    //      ObjectSet("Objtf"+num, OBJPROP_BACK, true);
        
          if (time2-time1<PeriodName*60/2)
             time2=Time[0];
          else
             time2=time1+PeriodName*60/2;
          num++;
    //----    
          ObjectCreate("Objtf"+num,OBJ_TREND,0,time2,iHigh(NULL,PeriodName,bar_tf),time2,iLow(NULL,PeriodName,bar_tf));
          ObjectSet("Objtf"+num, OBJPROP_WIDTH, Width);
          ObjectSet("Objtf"+num, OBJPROP_RAY, false);
          ObjectSet("Objtf"+num, OBJPROP_BACK, Background);
    //----    
          if (close_price>open_price)
            {
             ObjectSet("Objtf"+(num-1),OBJPROP_COLOR, Bull);
             ObjectSet("Objtf"+num,OBJPROP_COLOR, Bull);
            }
          else
            {
             ObjectSet("Objtf"+(num-1),OBJPROP_COLOR, Bear);
             ObjectSet("Objtf"+num,OBJPROP_COLOR, Bear);
            }
          num++;
         }
       return(0);
      }
    //+------------------------------------------------------------------+
     
    Last edited: 13 Apr 2020
  2. stadevata

    stadevata Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    Timeframe khan sudah d definisikan

    extern string Timeframe="D1";
    extern string Timeframe="W1";

    variable gak bisa d definisikan 2 kali bang
    programnya nya tar bingung .. ini Timeframe yg mau dipake yg mana ?? D1 pa W1
    kecuali dibuat 2 variable Timeframe yg berbeda

    extern string Timeframe1="D1";
    extern string Timeframe2="W1";


    btw... khan lebih enak pake 2 indi aja dalam chart nya, yg satu d set D1 satunya lagi set di W1
     
  3. iyoks

    iyoks New Member

    Equity
    Credit
    Ref Point
    Sebelumnya udah ane coba pake 2 indi malah ga muncul satunya om. btw tq pencerahannya om
     
  4. stadevata

    stadevata Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    satunya ga muncul karena nama object nya sama bang ...

    ganti -->> "Objtf"
    dengan nama lain selain objtf

    tar jadi nya kek gini :
    TF asli H1
    candle yg ada warna background nya TF H4
    candle yg ada tdk ada warna background nya TF D1
    tfcandle.png
     
    Last edited: 22 Apr 2020
  5. iyoks

    iyoks New Member

    Equity
    Credit
    Ref Point
    Boleh di SS codingnya dimari hu? mumet kaga ngerti ane ngerubahnya wkwk
     
  6. stadevata

    stadevata Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    sudah saya rubah nama objectnya
    "Objtf"+num+Timeframe"
    jadi tinggal pakai indicator yg sama tapi beda parameter input timeframe nya saja
     

    Attached Files:

  7. iyoks

    iyoks New Member

    Equity
    Credit
    Ref Point
    Makasi banyak hu
     

Share This Page