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 Mohon sample code untuk lock profit

Discussion in 'Belajar MQL dari Nol' started by popay, 20 Sep 2015.

  1. popay

    popay Member Credit Hunter

    Equity
    Credit
    Ref Point
    Agan2 sekalian, mohon bantuannya dong untuk sample code lock profit tiap 100poin lock 1 poin.
     
  2. popay

    popay Member Credit Hunter

    Equity
    Credit
    Ref Point
    Akhirnya nyoba2 code sendiri, hasil pemikiran ane seperti ini
    Code:
    extern int lockprofit = 100;
    extern int pipstolock = 1;
    
    void Lockprofit() {
      double  v1    = 0.0,
                v2    = 0.0;
      double  sl    = 0.0,
                ptl  = 0.0;
      for (int i = 0; i < OrdersTotal(); i++) {
          if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == mgc) {
            if (OrderType() == OP_BUY) {
                v2 = floor((Bid - OrderOpenPrice())/lockprofit);
                if ((v1 < v2) && (v2 != 0)) {
                  v1    = v2;
                  ptl  = ((v1 - 1) * lockprofit) + pipstolock;
                  sl    = OrderOpenPrice() + (ptl * Point);
                  if (OrderStopLoss() < sl) {
                      if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, Green))
                        Print("OrderModify Buy : ", GetLastError());
                  }
                }
            }      
            if (OrderType() == OP_SELL) {
                v2 = floor((OrderOpenPrice() - Ask)/lockprofit);
                if ((v1 < v2) && (v2 != 0)) {
                  v1    = v2;
                  ptl  = ((v1 - 1) * lockprofit) - pipstolock;
                  sl    = OrderOpenPrice() - (ptl * Point);
                  if (OrderStopLoss() > sl) {
                      if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, Red))
                        Print("OrderModify Sell : ", GetLastError());
                  }
                }
            }
          }    
      }
    }
    Nah, tugas baris code ntuh yang ane harapkan kira2 seperti ini
    sample OP adalah BUY
    Poin naik 100 poin, lock 1 poin
    Poin naik 200 poin, lock di 101 poin
    Poin naik 300 poin, lock di 201 poin
    dst
    tapi masalahnya code tersebut setelah ane ujicoba, gak dieksekusi
    adakah baris yang salah? kalau ane compile sih ok ok aja
    mohon petunjuknya ya teman2 sekalian

    colek mas Amir Syarifudin
     
  3. ngasqus

    ngasqus Active Member Pioneer

    Equity
    Credit
    Ref Point
    ikut belajar donk ;)
    maksudnya gimana ini ya??? apa tidak lebih baik pakai trailing stop???
     
  4. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    coba script dibawah ini Gan dan silahkan tambah magicnumbernya, cara pemakaian untuk ngunci 100 point >> TrailingStop(100);
    void TrailingStop(int trailingpip)
    {
    double point=MarketInfo(Symbol(),MODE_POINT);
    int suc;
    for(int i=0;i<OrdersTotal();i++)
    {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
    {
    if(OrderProfit()>0)
    {
    if(OrderType()==OP_BUY)
    {
    if((OrderClosePrice()-OrderOpenPrice())/point>trailingpip && (OrderClosePrice()-OrderStopLoss())/point>trailingpip)
    {
    suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-(trailingpip*point),0,0,clrNONE);
    }
    }
    else if(OrderType()==OP_SELL)
    {
    if((OrderOpenPrice()-OrderClosePrice())/point>trailingpip && (OrderStopLoss()-OrderClosePrice())/point>trailingpip)
    {
    suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()+(trailingpip*point),0,0,clrNONE);
    }
    }
    }
    }
    }
    }
     
  5. popay

    popay Member Credit Hunter

    Equity
    Credit
    Ref Point
    mas ngasqus kalo pake trailing stop bagusnya untuk scalping. tapi masalahnya ini ndak buat scalping. targetnya bisa 2000 poin. Cuma masalahnya terkadang ada false signal juga. kalau pakai trailing stop, cepat banget kena TS nya.

    jadi maunya sistem lockprofit tapi dinamis seperti contoh. :)
    makasih ya mas Amir Syarifudin
    tapi blom kena mas yang ane maksud. :(
    tapi tar saya coba dulu dah di apply di sistemnya.
    kali aja lebih bagus hasilnya
    :)
     
  6. ngasqus

    ngasqus Active Member Pioneer

    Equity
    Credit
    Ref Point
    coba masnya liat kode di sini https://www.mql5.com/en/code/11649
    ini sebagian kodenya

    Code:
    if(LockProfitAfter>0 && ProfitLock>0 && Points>=LockProfitAfter)
            {
            if(Points<=LockProfitAfter+TrailingStop)
                LockProfit(OrderTicket(),LockProfitAfter,ProfitLock);
            else if(Points>=LockProfitAfter+TrailingStop)
                            SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep);
            }
          else if(LockProfitAfter==0)
            SteppingTrailingStop(OrderTicket(),TrailingStop,TrailingStep);
     
  7. popay

    popay Member Credit Hunter

    Equity
    Credit
    Ref Point
    siap mas
    coba saya pelajari dulu ya mas
    makasih sebelumnya mas
     
  8. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    kalau masih belum ketemu, coba ini gan
    Code:
    void TrailingStop(int trailingpip)
      {
      double point=MarketInfo(Symbol(),MODE_POINT);
      int traillingtmp=trailingpip;
      int suc;
      for(int i=0;i<OrdersTotal();i++)
        {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          {
          if(OrderProfit()>0)
            {
              if(OrderType()==OP_BUY)
                {
                if(OrderStopLoss()<OrderOpenPrice())traillingtmp=2;
                if((OrderClosePrice()-OrderOpenPrice())/point>traillingtmp && (OrderClosePrice()-OrderStopLoss())/point>traillingtmp * 2)
                  {
                    suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-(traillingtmp*point),0,0,clrNONE);
                  }
                }
              else if(OrderType()==OP_SELL)
                {
                if(OrderStopLoss()>OrderOpenPrice())traillingtmp=2;
                if((OrderOpenPrice()-OrderClosePrice())/point>traillingtmp && (OrderStopLoss()-OrderClosePrice())/point>traillingtmp * 2)
                  {
                    suc=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()+(traillingtmp*point),0,0,clrNONE);
                  }
                }
            }
          }
        }
      }
     

Share This Page