How can a SL based on currency be set up?
-
@trader-philipps said in How can a SL based on currency be set up?:
@l-andorrà You might also consider trading costs such as commissions. That can be significant for a scalper for instance. And also consider minimum stopplevel on symbol as that can easily mess up your risk management.
All in all I don't think that that approach is a good one as it keeps out market condition from risk calculations at all.Oh, man. I'm still trying to understand what road did and you are pushing it far beyond
Give me a breath, man! 
-
@l-andorrà what @roar tries to do is to calculate the pip value in the base currency. You might check this thread if there's an indicator doing the job for you. https://www.forexfactory.com/showthread.php?t=54800
I haven't tried any of those, but maybe that's what you need.
Once you know the pip value you can divide your risk money by your static lot size and then you know your SL in pips. -
I will take a look on it, trader. Thank you very much.

-
@roar said in How can a SL based on currency be set up?:
@l-andorrà When I think about it, actually it doesn't get that much more complicated.
You just need to do the final correction with a pair EURxxx, where xxx is the base currency of your chart.
Example: when trading GBPJPY, sl formula is now:
SL (price fraction) = risked money / (lotsize*100000) * iClose(EURJPY,0,0)https://fxdreema.com/shared/mmBhaLp9
Check this example project, it's mql5 thoughOk. Now I finally took a look on it and I have a few more questions, please.
- Is the 'conversion_pair' variable of a string type? What is its default value?
- What if the account is in USD and not in EUR? Some symbols are 'USD'+conversion_pair and others conversion_pair+'USD'. Should I modify the formula text on a case by case basis?
-
@l-andorrà Here is a simple implementation without taking into account trading costs such as commissions, spread, etc.
0_1575001388915_pipvalue-simple.mq4
I hope the calculation is right like that. Maybe @roar may check. Further I put calculation on the onInit tab. Somehow it diesn't realize changing the constants unless you change the currency pair, but this is just ment to be a prototype. The pip value calculation I took from here (https://www.mql5.com/de/code/12418). So all honours go to the author.
-
@l-andorrà sorry, I should have left some more detailed explanation with my scribble.
- Is the 'conversion_pair' variable of a string type? What is its default value?
Yes, it's a string. It has empty default value - the value will anyway get replaced here:

- What if the account is in USD and not in EUR? Some symbols are 'USD'+conversion_pair and others conversion_pair+'USD'. Should I modify the formula text on a case by case basis?
The "lots" you buy or sell are always in the base currency. So the first part of the formula calculates the SL in terms of that base currency, whatever it is.

Now that we have solved the SL in the base currency, we have to set a multiplier to get the correct EUR value (or dollar, or whatever you like)

This is done by getting the current exchange rate of the base currency of our trade and EUR (or dollar, or whatever you like).
I find the exchange rate by building the symbol in the string:

Note that I select the "Quote currency" instead of "Base currency", because we are sort of reversing the effect.
If you need the SL in dollars instead of euros, just replace EUR with USD in the string. Just those 3 letters, nothing else. This should work in all cases, no matter if its USDxxx or xxxUSD, the EA will always know the base currency.BUT you need to have that EURxxx currency in your symbols list, otherwise you must take a detour:
If EURJPY is missing from your mt4, use USDJPY * EURUSD to get the value.@trader-philipps I couldn't get proper results from your example, maybe I tested it wrong

Here's my version in mql4: https://fxdreema.com/shared/VO1OeuqKb
And a backtest result on AUDJPY, sl and tp set to 50 euros (note the average profit/loss differs a bit from 50, because the EA doesn't take trading costs into account.

-
@trader-philipps Thank you very much.
-
@roar Thank you very much, roar.