Download MetaTrader 5

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

To add comments, please log in or register
Icham Aidibe
10050
Icham Aidibe  

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.

Alain Verleyen
Moderator
31620
Alain Verleyen  
You are working upside down. You have to fix a stoploss, then calculate your trading volume.
Icham Aidibe
10050
Icham Aidibe  
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 ?

Alain Verleyen
Moderator
31620
Alain Verleyen  
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).
Icham Aidibe
10050
Icham Aidibe  
angevoyageur:
   lotsize = StopAtEquity / (((MathAbs(openprice - stoploss) / ticksize) * tickvalue).
Will try it later. Merci.
Icham Aidibe
10050
Icham Aidibe  
It works. For symbol using a different currency, I have to make the conversion in my account currency.
To add comments, please log in or register