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 Close Order menggunakan MA Cros?

Discussion in 'Belajar MQL dari Nol' started by Klik Alfan, 27 Jun 2019.

  1. Klik Alfan

    Klik Alfan New Member

    Equity
    Credit
    Ref Point
    Bagaimana contoh code untuk close order by MA cros?
     
  2. Niguru

    Niguru Member Credit Hunter

    Equity
    Credit
    Ref Point
    Silakan gunakan code berikut ini:

    Code:
    //+------------------------------------------------------------------+
    //| Closing                                                          |
    //+------------------------------------------------------------------+
    void ClosePosition()
      {
       if(OrdersTotal()==0) return;
       double fast_ma,slow_ma;
       fast_ma=iMA(NULL,0,12,0,0,0,0);
       slow_ma=iMA(NULL,0,60,0,0,0,0);
    //---
       for(int i=0;i<OrdersTotal();i++)
         {
          if(!OrderSelect(i,SELECT_BY_POS)) break;
          if(OrderMagicNumber()!=MagicNum || OrderSymbol()!=Symbol()) continue;
          //--- check order type
          if(OrderType()==OP_BUY)
            {
             if(fast_ma<slow_ma)
               {
                if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
                   Print("OrderClose error ",GetLastError());
               }
             break;
            }
          if(OrderType()==OP_SELL)
            {
             if(fast_ma>slow_ma)
               {
                if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
                   Print("OrderClose error ",GetLastError());
               }
             break;
            }
         }
    //---
      }
    //--------------------------------------------------------------------  
    
    Code di atas hanyalah contoh, silakan sesuaikan sendiri dengan kebutuhan.
    Selamat beraktivitas .. Have a nice day :)
     

Share This Page