Platform: MT5
Robot: Breakout Strategy Advisor
Lot: 0.01
Tick: 0.01
Contract Size: 100
Stop Loss: 15 pips
Take Profit: 1250 pips
Problem: My Europa broker account has a SL of 15 pips, but the actual loss is $2-6. However, in the Asian broker account calculator, the same robot with a SL of 15 pips shows a loss of $1.50
I've tried changing the lot, checking the tick, contract, and regional server (AS03), but nothing helps.
Question: Why is the SL set correctly at the pips, but the actual $ is always higher? How can I set it so that the SL is $1.50 on my account?
SL calculation code in EA:
double slPrice = NormalizeDouble(entryPrice - StopLoss * _Point, _Digits);
- Determining Expert Advisor parameters
- Virtual hosting in MetaTrader 4 and MetaTrader 5: How it works
- Mathematical calculations
Vikitiki1998:
Platform: MT5
Robot: Breakout Strategy Advisor...
Problem: My Europa broker account has a SL of 15 pips, but the actual loss is $2-6. However, in the Asian broker account calculator, the same robot with a SL of 15 pips shows a loss of $1.50...
European broker-dealers and Asian broker-dealers generally have different account currencies, so you have to detect that first, and then you can put some code in your EA to calculate the value of your SL:
// in globals input double MaxRiskPercent = 1.1; input int StopPips = 178; double point, pointMultiplier, tickSize, tickValue, pointValue, pipValue, accountBalance, maxRiskMoney, lotSize; // in OnInit() point = SymbolInfoDouble(BaseSymbol, SYMBOL_POINT); tickSize = SymbolInfoDouble(BaseSymbol, SYMBOL_TRADE_TICK_SIZE); tickValue = SymbolInfoDouble(BaseSymbol, SYMBOL_TRADE_TICK_VALUE); pointValue = point * (tickValue / tickSize); if(_Digits == 3 || _Digits == 5) { pipValue = pointValue * 10 * lotSize; pointMultiplier = 10; } else { pipValue = pointValue * lotSize; pointMultiplier = 1; } accountBalance = AccountInfoDouble(ACCOUNT_BALANCE); maxRiskMoney = accountBalance * MaxRiskPercent / 100; lotSize = NormalizeDouble(GetLot(ORDER_TYPE_BUY, NormalizeDouble(2.00000 - StopPips * _Point * pointMultiplier, _Digits), NormalizeDouble(2.00000, _Digits), maxRiskMoney), 2); if(pipValue * StopPips * lotSize > maxRiskMoney) { Alert("Math error! Initial StopPips and lotSize exceed max risk of $" + DoubleToString(maxRiskMoney, 2)); ExpertRemove(); } Print("lotSize: ", lotSize);
Here, I'm comparing the value of my SL to the value of my max risk. In this code snippet, pipValue * StopPips (highlighted) is what you want.
Note that NormalizeDouble() and DoubleToString() are somewhat blunt functions that round decimal digits. Those are fine for my purposes but if you want pinpoint accuracy in your math, see Fernando Carreiro's post in another thread.
problem with NormalizeDouble
- 2024.12.18
- www.mql5.com
However, that is not the correct way to adjust the volume, nor is it the correct way to adjust for the stop-loss risk. Invalid volumes in trade operations limiting number of lots by a specific symbol for calculating the risk for the stop-loss size, and adjust the volume
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register