Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 4 Libraries | LotsRisk | MQL5 Release

New free code from MQL5: indicators, EAs, and scripts for traders.

Image for LotsRisk

Parameters:

  • riskPercent - percent of the current balance you want to risk
  • sl - the value of the StopLoss for the given order
  • price - the open price of the order
  • error - refereced parameter. an error code, that is returned by the function

Note: I can't say that it works correctly. I've checked it approximately. So your comments are appreciated.

Here is an example:

Trade Renko charts automatically using the advanced Renko Expert Advisors. Clean trends, better entries. Discover them here.


   int riskPercentage = 3,
      error;
   double sl = Ask - 40 * Point,
      openPrice = Ask;   

   double lots = GetNeccessaryLotsWithRisk(riskPercentage, sl, openPrice, error);
   
   if (CompareDoubles(lots, 0))
   {
      switch (error)
      {
         case LOTS_TOO_BIG:   // lots are bigger than max lots
            Alert("Risk percentage is too big");
            break;

         case LOTS_TOO_SMALL: // lots are smaller than min lots
            Alert("Risk percentage is too small");
            break;

         default:             // formula's result =)
            Alert("It seems like you've got $0 or stoploss is too far");
            break;
      }
   }

Level up your trading with professional RobotFX expert advisors and indicators. Visit robotfx.org for proven MT4/MT5 tools.

8568

Best MetaTrader Indicators + Profitable Expert Advisors