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

Cara membandingan 3 garis MA

Discussion in 'Belajar MQL dari Nol' started by stef_arc1989, 02 Jul 2020.

  1. stef_arc1989

    stef_arc1989 New Member

    Equity
    Credit
    Ref Point
    Halo saya baru belajar bahasa mql dan ingin membuat ea dengan syarat :
    - 3 garis ma, (contoh misalnya 20, 50, 100)
    - jadi logikanya membandingan 3 garis ma
    - jika garis 20 diatas, garis 50 ditengah, garis 100 dibawah dan candle menyentuh garis ma 20 maka BUY dan TP jika garis ma 50

    codingnya seperti apa ya soalnya saya uda coba berbagai cara salah semua. thanks before
     
  2. Noir_

    Noir_ New Member

    Equity
    Credit
    Ref Point
    Code:
    string Signal;
    if (MA20>MA50 && MA50>MA100 && Close[i]>=MA20) {Signal = "BUY";} else {
    if((MA20<MA50 && MA50<MA100 && Close[i]<=MA20) {Signal = "SELL";} else { Signal = "NONE";}}
    
    if(Signal == "BUY")  //code buy di sini;
    if(Signal == "SELL")  //code sell di sini;
    
     
  3. stef_arc1989

    stef_arc1989 New Member

    Equity
    Credit
    Ref Point

    Iya makasih pak
    Saya udah berhasil sampai dia order saat garis ma 20 menyentuh candle, tapi gimana cara nentuin TP saat garis ma 50 menyentuh candle ya?
    Pakai perintah apa ya?
     
  4. Noir_

    Noir_ New Member

    Equity
    Credit
    Ref Point
    saya bingung dengan TP nya bos
    kalau buy di ma20 sedangkan ma50 di bawah ma20 , bukannya jadi stop loss yha

    Code:
    string SignalClose;
    int ticket;
    
    if(Close[i]<=MA50) {SignalClose = "CloseBUY";}
    
    //Cari Order BUY
    if (OrdersTotal() <= 0)
       return;
    for (int x=OrdersTotal()-1; x>=0; x--)
          {
           if (OrderSelect(x, SELECT_BY_POS, MODE_TRADES)==true)
                {
                if (OrderType()==0  &&  SignalClose=="CloseBUY")
                   {
                   ticket=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(),MODE_BID),10);
                   if (ticket==-1) Print ("Error: ",  GetLastError());
                   }
                }
          }
    
     
  5. Onyx MIB

    Onyx MIB Member

    Equity
    Credit
    Ref Point
    Code:
    string Signal = "";
    if (MA20>MA50 && MA50>MA100 && Close[0]==MA20 ) {
    [INDENT]Signal = "BUY";[/INDENT]
    }else if((MA20<MA50 && MA50<MA100 && Close[0]==MA20) {
    [INDENT]Signal = "SELL";[/INDENT]
    }
    
    double sl = 0.0, tp = 0.0;
    if (Signal == "BUY"){
    [INDENT]sl = MA50;
    OrderSend(_Symbol, OP_BUY, 0.01, Ask, 3, sl, tp, "");[/INDENT]
    }else if (Signal == "SELL"){
    [INDENT]sl = MA50;
    OrderSend(_Symbol, OP_SELL, 0.01, Bid, 3, sl, tp, "");[/INDENT]
    }
    
    
    Untuk itu diskusi dan belajar Code MQL, silakan bergabung di group telegram https://t.me/codeMQL
     
  6. stef_arc1989

    stef_arc1989 New Member

    Equity
    Credit
    Ref Point
    sorry lupa update, case closed uda dpt caranya :ok:
     

Share This Page