Download MetaTrader 5
To add comments, please log in or register
Register as a seller and start making profit!
Syphon
75
Syphon 2015.12.25 13:33 

Hi All

 

I have previously coded in mql5 however i am new to mql4. I want to basically use my entire capital in every trade. I need to calculate the highest lot size. Here is the function i use in mql5 :

 

   if(OrderCalcMargin(ORDER_TYPE_BUY,"AUDJPY",1.0,SymbolInfoDouble("AUDJPY",SYMBOL_ASK),AUDJPY_required_margin)) // Calculate margin required on 1 lot

        {

         if(NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)/AUDJPY_required_margin,2))

           {

            AUDJPY_trade_volume=NormalizeDouble((AccountInfoDouble(ACCOUNT_FREEMARGIN)/AUDJPY_required_margin)*0.99,2);

           }

        }

 

Cab someone help me with the mql4 equivalent? 

whroeder1
13596
whroeder1 2015.12.25 19:06  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. I want to basically use my entire capital in every trade.
    Can't be done; you can only use your entire margin. If you do that, one tick down: margin call; you've lost half of your account.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
    • Do NOT use TickValue by itself - DeltaPerlot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
Syphon
75
Syphon 2015.12.26 00:37  

Sorry about the source code. I rarely post on the forums. 

 

Thank you. Just one more question, is there any function to calculate the lot size where every pip is 1% of your balance?  ie stoploss will be 100 pips in the opposite direciton?

Donald Gibson
482
Donald Gibson 2015.12.26 02:38  
syphon:

Hi All

 

I have previously coded in mql5 however i am new to mql4. I want to basically use my entire capital in every trade. I need to calculate the highest lot size. Here is the function i use in mql5 :

 

   if(OrderCalcMargin(ORDER_TYPE_BUY,"AUDJPY",1.0,SymbolInfoDouble("AUDJPY",SYMBOL_ASK),AUDJPY_required_margin)) // Calculate margin required on 1 lot

        {

         if(NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)/AUDJPY_required_margin,2))

           {

            AUDJPY_trade_volume=NormalizeDouble((AccountInfoDouble(ACCOUNT_FREEMARGIN)/AUDJPY_required_margin)*0.99,2);

           }

        }

 

Cab someone help me with the mql4 equivalent? 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double RMLotSize()
  {
//-------------------------------------------------------------------------------------------------
double Risk_Percent=2.0;//Percentage of Account Balance to Risk
 double Acct_Equity=AccountInfoDouble(ACCOUNT_EQUITY);
double Acct_RiskCapitol=Acct_Equity*(Risk_Percent*0.01);
//-------------------------------------------------------------------------------------------------
//lotsize based on risk capitol
   double LotSize=Acct_RiskCapitol*Pips;
//-------------------------------------------------------------------------------------------------
//if lotsize is more than is permitted change the lotsize to the maximum  permitted
   if(LotSize>MarketInfo(Symbol(),MODE_MAXLOT)) {LotSize=MarketInfo(Symbol(),MODE_MAXLOT);}
//-------------------------------------------------------------------------------------------------
//if lotsize is less than is permitted change the lotsize to the minimum  permitted  
   if(LotSize<MarketInfo(Symbol(),MODE_MINLOT)) {LotSize=MarketInfo(Symbol(),MODE_MINLOT);}
//-------------------------------------------------------------------------------------------------
//if there is no orders available print Account Information and LotSize available   
   if(OrdersTotal()==0)
     {
      Print("-------------------------------------------------------------------------------------------------");
      Print("LotSize based on the Capitol available...",DoubleToStr(LotSize,2));
      Print("Amount of Capitol to Risk...",DoubleToStr(Acct_RiskCapitol,2));
      Print("-------------------------------------------------------------------------------------------------");
     }
   return(LotSize);
  }
/
To add comments, please log in or register