# Stoploss : From profit/loss(in currency) to price...

10050

Hi,

I'm looking for a way to fix the price of my stoploss using a lossprofit (x% of account currency) :

```double StopAtEquity = RelativeSL * Equity / 100; <---- x% of equity tolerated as a loss for each trades
for (x=1;x<10000;x=x+1) { <---- using this loops doesn't seems to work (too large !)
StopLvl = NormalizeDouble((Bid - (pi2po(x) * _Point) - ((SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)) * _Point)),digit); <--- pi2po convert pips in profit
StopLevel = MathRound(StopLvl / SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)) * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE); <--- correction of the stop
if (MyAccount.OrderProfitCheck(_Symbol,ORDER_TYPE_BUY,volume,priceopen,StopLevel) == (-1 * StopAtEquity)) { printf("******* Value found : %g",StopLevel); break; }
}```

First, the interval tested is too large (in points).

Second, the "==" of the OrderProfitCheck statement is too accurate, it never falls *exactly* on the right value.

Anyone there have a clue on how to get out of this ?

Thanks.

Moderator
31620

You are working upside down. You have to fix a stoploss, then calculate your trading volume.
10050

angevoyageur:
You are working upside down. You have to fix a stoploss, then calculate your trading volume.

Well I need this *R e l a t i v e* SL. Such a function based on profit is a nice way to control before any optimization the drawdown allowed by the EA.

You wish to work with a rel DD @ 10% easy-go, just set it. It won't never be more. Using a fixed SL you'll have to play onto the risk and it won't never reflect as with this method the rel dd.

So any help regarding the previous posted function ?

Moderator
31620

blouf:

Well I need this *R e l a t i v e* SL. Such a function based on profit is a nice way to control before any optimization the drawdown allowed by the EA.

You wish to work with a rel DD @ 10% easy-go, just set it. It won't never be more. Using a fixed SL you'll have to play onto the risk and it won't never reflect as with this method the rel dd.

So any help regarding the previous posted function ?

lotsize = StopAtEquity / (((MathAbs(openprice - stoploss) / ticksize) * tickvalue).
10050

angevoyageur:
lotsize = StopAtEquity / (((MathAbs(openprice - stoploss) / ticksize) * tickvalue).
Will try it later. Merci.
10050

It works. For symbol using a different currency, I have to make the conversion in my account currency.