-
Play videoPlease edit your post.
For large amounts of code, attach it.
double slAmt = dTrailingStop * Point; // pips or points * Point. 0.00010 double dStopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); // stop level in points 20 if (slAmt < dStopLevel) slAmt = dStopLevel; // sl amount 20 price = Bid; slPrice = price - slAmt; // Bid +/- 20 rc = OrderModify (OrderTicket(), OrderOpenPrice(), ND(slPrice), OrderTakeProfit(), 0, Red);
Of course it's calculated as 20.755- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.
It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- Of course it's calculated as 20.755
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
Thank you for your reply. In reference to your points:
1) Fixed, thank you for pointing out the correct way to place code into a post
2) I'm not sure I understand. Is the
double slAmt = dTrailingStop * Point;
not the correct way to scale a pip value to a point representation? Since that is what I'm doing in my code, could you maybe offer an explanation slightly more detailed than just saying "Of course it's calculated as 20.755".
Please don't misunderstand: I appreciate you taking the time to help me (and others) out, but after your replay, I'm genuinely confused about what the correct way of scaling pips to a point value is (and why my code is not working). Following your post and some more research, I've found this link from one of your posts and changed my code to
if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. __pips2dbl = Point*10; __pips2points = 10; } else { __pips2dbl = Point; __pips2points = 1; }
but when using the thus calculated __pips2dbl value, SL still is calculated incorrectly.
On a related question, your code example contained the following construct
int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips)
which however fails to compile for me. What I am doing wrong here?
3) Thank you for pointing out the deficiencies of NormalizeDouble. I've read the links you pointed to and have changed my code accordingly.
All in all, thank you for your informative reply, if you could spare a few more minutes for me, I'm sure it would help me a great deal.
double slAmt = dTrailingStop * Point;
That converts a number of points to a double (a change in price,) not the number of pips to a double. dTrailingStop * _pips2dbl will convert a number of pips to a double.- Since Build 600, dots can't be in variable names. Remove it or rename it.
double dStopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); // stop level in points 20 if (slAmt < dStopLevel) slAmt = dStopLevel; // sl amount 20
You are still comparing a double (change in price) to number of points. Is an Orange < an Apple? The question does not make sense.
- That converts a number of points to a double (a change in price,) not the number of pips to a double. dTrailingStop * _pips2dbl will convert a number of pips to a double.
- Since Build 600, dots can't be in variable names. Remove it or rename it.
- You are still comparing a double (change in price) to number of points. Is an Orange < an Apple? The question does not make sense.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm backtesting an EA I have written and I have the following code for handling stop-loss calculation & setting:
When altering a buy order, everything is fine. However, when altering a sell order (say for EURGBP, price being around the 0.755 level), SL is set to 20.755. The odd thing is, the line
prints out 0.001. For reference, ND is defined as follows:
So given the above, I don't see how Stop-Loss could be calculated to 20.755 (again, this only happens for sell orders). I've been staring at this for hours and I guess it must be something totally stupid but I'm just not seeing it. I'd appreciate any pointers as to what I'm doing wrong.