1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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

Risk Management

Discussion in 'Belajar MQL dari Nol' started by dod gaming, 08 Sep 2019.

  1. dod gaming

    dod gaming New Member

    Equity
    Credit
    Ref Point
    Gan mau tanya nih
    saya punya risk management yang mau saya terapkan di EA saya

    seperti ini kira2:

    jika balance - equity = equity*10% margin (order yang loss ditutup)
    dan jika kurang dari 10% equity maka tetap lanjut

    bagaimana ya master codingnya?
     
  2. amtwoxtwo

    amtwoxtwo Member

    Equity
    Credit
    Ref Point
    Code:
    void OnTick(){
    double marjin = AccountMargin();
    double ekuity = AccountEquity();
    double saldo = AccountBalance();
     
    if(saldo-ekuity>=ekuity*(marjin*0.1)){closeloss();}
    }
    
    int closeloss(){
      int TotalClose=0;
      int Slippage=3;
      if(Digits==3 || Digits==5){
      Slippage=Slippage*10;
      }
      for( int i=OrdersTotal()-1;i>=0;i-- ) {
      if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES )){
      double ClosePrice;
      RefreshRates();
      if(OrderType()==OP_BUY) ClosePrice=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),Digits);
      if(OrderType()==OP_SELL) ClosePrice=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits);
    if(AccountProfit()<0){
      if(OrderClose(OrderTicket(),OrderLots(),ClosePrice,Slippage,CLR_NONE)){
      TotalClose++;
      }
      else{
      Print("Order failed to close with error - ",GetLastError());
      }
      }
      else{
      Print("Failed to select the order - ",GetLastError());
      }  
      }
      }
      return(TotalClose);
    }
    
     
  3. dod gaming

    dod gaming New Member

    Equity
    Credit
    Ref Point
    makasih master bantuannya saya sangat terbantu sekali untuk penulisan risk manajemen ini
     

Share This Page