if(StopLoss > 0) buyStopLoss = pendingBuyPrice - (StopLoss * _Point); if(StopLoss > 0) sellStopLoss = pendingSellPrice + (StopLoss * _Point); if(TakeProfit > 0) buyTakeProfit = pendingBuyPrice + (TakeProfit * _Point); if(TakeProfit > 0) sellTakeProfit = pendingSellPrice - (TakeProfit * _Point);
You buy at the Ask and sell at the Bid. There for pendingBuyPrice must be relative to the Ask, but your buyStopLoss and buyTakeProfit must be relative to the Bid. You have them relative to the open price, therefor even if StopLoss equals TakeProfit you will not have a 1:1 RRR.- Why to you calculate those, when you will recalculate them when pendingBuyPrice < upperStopLevel? Move the pending prices, then calculate the stops.
- You are not testing if your stops are greater than stopLevel.
- You are not
adjusting
SL, TP, and slippage; for 4/5 digit brokers
and for JPY pairs.
- 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 and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
if(Ask > pendingSellPrice) gSellTicket = ...
What is the purpose of the if? You already moved pendingSellPrice below Bid - lowerStopLevel, therefor the if will always be true.- On ECN type brokers you must open first and then set stops.
- Check your return codes
and find out why.
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
whroeder1:
- You buy at the Ask and sell at the Bid. There for pendingBuyPrice must be relative to the Ask, but your buyStopLoss and buyTakeProfit must be relative to the Bid. You have them relative to the open price, therefor even if StopLoss equals TakeProfit you will not have a 1:1 RRR.
- Why to you calculate those, when you will recalculate them when pendingBuyPrice < upperStopLevel? Move the pending prices, then calculate the stops.
- You are not testing if your stops are greater than stopLevel.
- You are not
adjusting
SL, TP, and slippage; for 4/5 digit brokers
and for JPY pairs.
- 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 and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- What is the purpose of the if? You already moved pendingSellPrice below Bid - lowerStopLevel, therefor the if will always be true.
- On ECN type brokers you must open first and then set stops.
- Check your return codes
and find out why.
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
Thanks for this advice but I'm a little stuck on how to get the Bid and Ask prices from the previous day? Bid and Ask are predefined variables to only current price?
Stephen Reynolds:
Thanks for this advice but I'm a little stuck on how to get the Bid and Ask prices from the previous day? Bid and Ask are predefined variables to only current price?
Thanks for this advice but I'm a little stuck on how to get the Bid and Ask prices from the previous day? Bid and Ask are predefined variables to only current price?
You can't get the Ask.
You can get the Bid price at the open, high, low and close of any previous bar.
I'd suggest working with the close price.
Stephen Reynolds: Thanks for this advice but I'm a little stuck on how to get the Bid and Ask prices from the previous day? Bid and Ask are predefined variables to only current price?
| You can't on MT4. You get the Bid price from a previous bar and add the current average spread (Ask-Bid) to estimate it. |
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
Why an I receiving ordersend error 4107 and invalid takeprofit for ordersend function on testing the following code?