Try Normalize Bid.
//+----------Price_Buy Function double Price_Buy(double Price_Buy){ Price_Buy=NormalizeDouble(Ask,Digits); return(Price_Buy);} //+----------Price_Sell Function double Price_Sell(double Price_Sell){ Price_Sell=NormalizeDouble(Bid,Digits); return(Price_Sell);} OrderSend(Symbol(),OP_SELL,Lots,Price_Sell,3,SellStopLoss,0,"RatReverseSell",RRSell,0,Red);
Add this string
Print("bid - ",DoubleToString(Bid,5)," Ask - ",DoubleToString(Ask,5)," stop - ",DoubleToString(SellStopLoss,5));
after
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,SellStopLoss,0,"RatReverseSell",RRSell,0,Red);
and show us what is in logs.
You need to enter the stops via an OrderModify after the trade is completed. You cannot enter a stoploss or takeprofit with a market order at an ECN/STP broker. It will test correctly in the tester(which cannot tell the difference between market execution and instant execution) but will not work live/demo.
You never need to normalize Bid/Ask. You don't need to normalize the TP/SL, but they must be bigger than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point from the orderClosePrice.
You do need to make stops via orderModify. You do need to adjust for 5 digit brokers, including slippage.
//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Hi WHRoeder,
I agree with you about the normalisation of Bid/Ask, but I was somewhat surprised at your statement that you do not need to normalise TP/SL values, since this is contrary to my information.
Given the fact that you clearly know your way around MQL4, this is causing me to question my understanding and information. Please could you expand on this or point me towards some reading material.
I was also quite interested to note that a normalisation problem will return ERROR 129 rather than ERROR 130.
Seperating the The stop loss and Take Profit entries from the OrderSend and placing them into an OrderModify, following the OrderSend will resolve your issue. You will most likely want 1 code path for non ECN brokers and one code path for ECN brokers. This way, fast exexcution on non ECN and somewhat slower on ECN.
Seperating the The stop loss and Take Profit entries from the OrderSend and placing them into an OrderModify, following the OrderSend will resolve your issue. You will most likely want 1 code path for non ECN brokers and one code path for ECN brokers. This way, fast exexcution on non ECN and somewhat slower on ECN.
thank you

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When I trade by entering the stops manually and initially set the stop parameter in OrderSend to "0" the trade will go through - and that is pretty much the only time it will work (on MB Trading & IBFX). It also works when I backtest the EA in StrategyTester. Here is the code that sets the stops and enter the orders (the EA is run on daily charts and a typical stop loss value is about 65 pips).
double StopRange=iATR(NULL, 0, 10, 1)/2;
if (Point==0.01)
pipValue=2;if (Point==0.001)
pipValue=3;
if(Point==0.0001)
pipValue=4;
if (Point==0.00001)
pipValue=5;
BuyStopLoss=NormalizeDouble(highest-StopRange,pipValue); //Highest and lowest will always be below (highest), & above (lowest) current market entry price.
SellStopLoss=NormalizeDouble(lowest+StopRange,pipValue);
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,SellStopLoss,0,"RatReverseSell",RRSell,0,Red);
2010.08.16 15:17:18 RatReversal EURUSD,Daily: OrderSendSell failed with error # 130 SellStopLoss:1.2825 (well above market price - the print function only prints 4 places after the decimal place but I believe I put in 5 digits after) BuyStopLoss:1.2892
Any ideas or suggestions would be appreciated. Thanks,