- Show your code
- Print out your variables used in the OrderSend, including Ask/Bid and find out why.
- You can't move stops closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
- 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 and MetaTrader 4 - MQL4 programming 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 and MetaTrader 4 - MQL4 programming 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 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming 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.
In the codes below StopLoss, TakeProfit, Slippage and TrailingStop are constant.
OrderSend :
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0; if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0; OrderSend(Symbol(), OP_BUY, OptimizedLots(), Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
OrderModify :
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
When there is no SL and no TP (so 0 and 0 values) the EA can open positions without problems in test and real, so SL/TP are the problem here.
In the codes below StopLoss, TakeProfit, Slippage and TrailingStop are constant.
OrderSend :
OrderModify :
When there is no SL and no TP (so 0 and 0 values) the EA can open positions without problems in test and real, so SL/TP are the problem here.
You are ignoring the information and links that @whroeder1 has outlined in his post. Visit every link he has provided and follow-up on what they tell you.
For example, you are not checking for minimum allowable stops size, and you are also ignoring the fact that Buy orders close on the Bid price and not the Ask price. These are just two examples, but all the details are in the links that he provided!
Don't just expect us to give you a clean code solution, as that will not help you in the future. You have to understand the "why" and "how", so follow the links and study the information.
Then post your improved code attempt to verify!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I developed an EA for the DAX (ger30), it works perfectly in tests I have no error.
But when I go into real OrderSend and OrderModifiy returns the error "invalid tp or sl", while I never had this error in test. So I just ask for your help after spending the long hours digging into my code and doing some research on it .. Do you have any ideas ?
Thank you in advance for your help.
PS: the automatic trading is already authorized on the EA side and on the MT4 side.