AGAIN: Calculate lot size wit fix risk and fix points - page 2

 

Thanx again Alain 

IT WORKS - But i must say i dont get it -> i missed WHAT IS A TICK.

So i g**gl tick is a minimum price change and can be everything - for example 0,25 then 4 ticks are ... and here is the question pips or points i dont know.

but when i now a tick is 0.25 mySL is 500_Points i end up with (500/.025=) 2000_ticks

now i know my tick value is 0.28_USD i can multiplie  (2000_ticks * 0.28_USDbyTick) 560_USD

i think i understand the principle by now


here i have a cooding problem what does the "?" and what is with the ":" 

 double lots   = (tickCount*tickValue)!=0 ? valueToRisk/(tickCount*tickValue) : 0;

NEW TO ME ?? 

 

Found anwer here: https://www.mql5.com/en/docs/basis/operators/ternary

Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
  • www.mql5.com
Language Basics / Operators / Ternary Operator ?: - Reference on algorithmic/automated trading language for MetaTrader 5
 

OK if i get everithing right i end up wit this function:

Percen = double 2.15

Points = 500 POINT

base is the lower: Equity or Balanc value

returns double for Lot          ATTENTION ==> minimum 0.01 so you do not get an error opening positions with Lot 0 - but in this case it can be more than % value !!


double RiskPointsToVol(double fMyRiskPercent, int fMyRiskPoints)
{
   double fMyMoney      = MathMin(AccountInfoDouble(ACCOUNT_EQUITY),AccountInfoDouble(ACCOUNT_BALANCE));
   double fTickTotal    = (fMyRiskPoints*_Point)/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
   double fMyRiskMoney  = (fMyMoney*fMyRiskPercent)/100;  
   double fTickValue    = SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE);  
   double fLot          = (fTickTotal*fTickValue)!=0 ? fMyRiskMoney/(fTickTotal*fTickValue) : 0.01;
   
return(fLot);
}

(Basicly turned Alains idea into a function) - this function looks fine for me. Do i miss something?

 
Zar88:

OK if i get everithing right i end up wit this function:

Percen = double 2.15

Points = 500 POINT

base is the lower: Equity or Balanc value

returns double for Lot          ATTENTION ==> minimum 0.01 so you do not get an error opening positions with Lot 0 - but in this case it can be more than % value !!


(Basicly turned Alains idea into a function) - this function looks fine for me. Do i miss something?

Of course the code I provided is only to illustrate the needed calculation.

You need to normalize your lotsize and check against minimum and maximum allowed by the broker.

 
Vladimir Karputov: To calculate, you need two parameters: a loss (set only positive numbers) and a StopLoss level.
Vladimir Karputov: Not quite right. I did not take into account the level of margin.
You need three values, loss, SL, and a conversion factor.
  • 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/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • 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
 

@ Alain - In my code lots are splitet up to 3 trades, this is when i cheque ;-) THNX

@ whroeder - i have seen your post before but i wos not able to understand it then... now i untherstand TICKVALUE now it works....

Reason: