someone help, to calculate the amount of money on certain stoploss or take profit(position size calculator) - page 2

 
Dominik Egert #:
One.

There is one possible risk setting with a stop loss.

Please share alternatives. I am curious.

I have already shared it read my previous comments

 
Thank you. I did read it.

Could you explain how this is related to a different type of risk control that is actually a control of your risk?

As far as I understand, your approach is not how much to risk as an input value, but as a result.


 
Dominik Egert #:
Thank you. I did read it.

Could you explain how this is related to a different type of risk control that is actually a control of your risk?

As far as I understand, your approach is not how much to risk as an input value, but as a result.


basically I wanted to understand the calculation that could help me set stoploss to risk a specific percentage of account balance to any symbol, suppose my account balance is 1000$ and I want to risk 1% of it in a trade which equals to 10$. The algorithm would help me to construct the accurate stoploss from any lotsize I will put as a functional argument, This is important since all symbols have different Points and ips values so no matter its value you will still risk the same amount through your stoploss.Example Testing it NASDAQ, #ford and BTCUSD with the same lotsize value of 0.01 on the buy position the stoploss were constructed differently with different NASDAQ = 200points below the ask price, #ford 1000points below ask price and BTCUSD was 1000000 points below ask price different stoplosses but same risk, that is the idea(the risk was only 10$(1% of accountbalance) for each trade

 
Omega J Msigwa #: I am not sure if this is an automated message or not

No automated messages on the forums, only the green colored links.

 
William Roeder #:

No automated messages on the forums, only the green colored links.

I thought you automated it but no bigger deal

 
Yes. I understood very well.

The issue I see is following and I'll explain this on how it should be done:

You look at your chart. You have a plan on what you want to do. So you see a setup forming and your strategy is giving you a go. It will tell you at absolute minimum: when the setup is invalid. Where to enter.

Now you draw your stop onto the chart and your entry. The distance between the two is given by the setup. Now you take your risk amount, let's call it risk unit. In your example 1% (which is quite a lot) and you calculate the volume that fits into this stop distance.

This is how it is done.

Now let's say you have a TP and it is three times your SL, then you will make 3 risk units profit. And this profit is directly on your account. In your case 3% on the account balance.

According to your example, 30$.

Got it?

There is no other way to do it. Else it is simply no strategy, it's gambling. Just as already stated a few posts earlier.


 

Just look for a calculator on the net, why bother with the formulas? The strategy I follow - in terms of risk optimization and optimal profitability the best one will be the "golden mean" - partial reinvestment with a monthly withdrawal of part of the profit of $200. I use this calculator https://www.earnforex.com/position-size-calculator/, perhaps it`ll be more convenient for you.  After careful analysis of the obtained data, you can make a decision about the expediency of opening a deal. But remember, the data presented in the calculator is for informational purposes, and the responsibility for the transactions lies with you. After all, the calculator is a good auxiliary tool, but don`t take it as a guide to action.

 

 
Chrisorg #:

Just look for a calculator on the net, why bother with the formulas? The strategy I follow - in terms of risk optimization and optimal profitability the best one will be the "golden mean" - partial reinvestment with a monthly withdrawal of part of the profit of $200. I use this calculator https://www.earnforex.com/position-size-calculator/, perhaps it`ll be more convenient for you.  After careful analysis of the obtained data, you can make a decision about the expediency of opening a deal. But remember, the data presented in the calculator is for informational purposes, and the responsibility for the transactions lies with you. After all, the calculator is a good auxiliary tool, but don`t take it as a guide to action.

 

Don't bring up closed topics for no good reason, I honestly think you know that we are developers here, we are used to work with formulas. Formulas and numbers are our game. Thanks for the advice but that's not what I asked for, anyway I believe it is the most common advice to me and other programmers.

 

I use this function to calculate the lot size of a market order

//+------------------------------------------------------------------+
//| Calculate the appropriate volume for the trade operation planned.|
//+------------------------------------------------------------------+
double OrderCalcVolume(ENUM_ORDER_TYPE ordertype, string symbol, double risk_money, double commission_lot, double price_open, double price_sl, bool adjust_volume = true)
  {
//--- Calculation using TICK_VALUE is less accurate.
//   double TickSize  = SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
// //double TickValue = SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE_LOSS);
//   double TickValue = mTickValue(symbol);
//   double sl_ticks  = MathRound((ordertype == ORDER_TYPE_BUY ? price_open - price_sl : price_sl - price_open) / TickSize);
//   double lots      = risk_money/(sl_ticks*TickValue+commission_lot);
//---
   double lots=0;
   double profit_one_lot=0;
   double margin=0;
//---
   if(OrderCalcProfit(ordertype,symbol,1.0,price_open,price_sl,profit_one_lot) && profit_one_lot < 0)
     {
      lots=risk_money/(MathAbs(profit_one_lot)+commission_lot);

      //--- Round lots to lotstep.
      double lotstep=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
      lots=MathFloor(lots/lotstep)*lotstep;

      if(adjust_volume)
        {
         //--- Adjust lots to broker limits.
         double minlot=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
         double maxlot=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
         if(lots < minlot)
           {
            lots=0;
           }
         if(lots > maxlot)
           {
            lots=maxlot;
           }
         //--- Adjust lots to account free margin.
         if(OrderCalcMargin(ordertype,symbol,lots,price_open,margin))
           {
            double free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
            if(free_margin<0)
              {
               lots=0;
              }
            else if(free_margin<margin)
              {
               lots=lots*free_margin/margin;
               lots=MathFloor(lots/lotstep-1)*lotstep;
              }
           }
        }

     }
//---
   return lots;
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart(void)
  {
   string symbol="EURCAD";
//---
   double sl_points=100;    // means sl = 100 points below ask
   double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
   double price=SymbolInfoDouble(symbol,SYMBOL_ASK);
   double price_sl=price-sl_points*point;
//---
   double balance=AccountInfoDouble(ACCOUNT_BALANCE);
   double risk_percent=2;   // means risk = 2% of account balance
   double risk_money=risk_percent/100.0*balance;
   double commission_lot=7.0;  //round-trip commission per lot = 7
//---
   Print("lots = ",OrderCalcVolume(ORDER_TYPE_BUY,symbol,risk_money,commission_lot,price,price_sl));
  }

//+------------------------------------------------------------------+

To be able to calculate your predicted risk money in case your SL is hit:

Use OrderCalcProfit()

   https://www.mql5.com/en/docs/trading/ordercalcprofit

For example like this:

   double risk_money=0;
   double commission_per_lot=7.0  // means 7 dollars per dollar round trip

   if(OrderCalcProfit(ordertype,symbol,lots,price,price_sl,risk_money) && risk_money < 0)
     {
      risk_money=MathAbs(risk_money) + commission_per_lot * lots;
     }
     
   Print("money at risk= ", risk_money);