Try to check the value of special last_error variable by GetLastError().
https://docs.mql4.com/constants/errors :
ERR_INVALID_STOPS | 130 | Invalid stops. |
https://docs.mql4.com/trading/OrderSend :
"StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated."
Normalization => https://docs.mql4.com/convert/NormalizeDouble
It's stange
Print("Error :"+MarketInfo(Symbol(),MODE_STOPLEVEL));
it 's give : Return Error : 0.00000000
And if i put manually very high take profit and very low stop low, i sill get the same error.
Use https://docs.mql4.com/convert/DoubleToStr to print.
And do use normalization => https://docs.mql4.com/convert/NormalizeDouble :
"The calculated StopLoss and TakeProfit values, as well as open price of pending orders must be normalized with a precision the value of which is stored in the pre-defined variable of Digits."
Hi again, and thanx for your previous answer.
I tried with all digit from 1 to 8 with values near and far from current price, but i'm still getting the same error. I can't find what is false :(.
- You do not have to normalize the stops (at least on IBFX) as long as they're beyond MarketInfo(Symbol(), MODE_STOPLEVEL)*Point from the market.
- On a ECN broker, you must open the trade and then set the stops.
- On a five digit broker, you must adjust TP, SL, and 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
Thanks for your answer.
I tried many think but i'm certainly don't doint it well.
For example, for this order :
OrderSend( Symbol(), 0, 0.1,Ask, 3,Ask - 50 * Point,Ask + 25 * Point,"Achat",0,0,Green);
How would you write it with your variables?
I tried to understand, but i'm not enought exprerienced to
Thanx a lot
...
//< 7.4. Data Feed 29 >```````````````````````````````````````````````````````````````````````````````````````//< 397>
//< 398>
//< 7.4.1. Common Data 14 > //< 399>
avd.QuoteAsk = MarketInfo ( aes.Symbol , MODE_ASK ) ; //< 400>
avd.QuoteBid = MarketInfo ( aes.Symbol , MODE_BID ) ; //< 401>
avd.QuotePoint = MarketInfo ( aes.Symbol , MODE_POINT ) ; //< 402>
avd.QuoteSpread = MarketInfo ( aes.Symbol , MODE_SPREAD ) * avd.QuotePoint ; //< 403>
avd.QuoteFreeze = MarketInfo ( aes.Symbol , MODE_FREEZELEVEL ) * avd.QuotePoint ; //< 404>
avd.QuoteStops = MarketInfo ( aes.Symbol , MODE_STOPLEVEL ) * avd.QuotePoint ; //< 405>
avi.Digits = MarketInfo ( aes.Symbol , MODE_DIGITS ) ; //< 413>
...
//</7.4.1. Common Data 14 > //< 414>
...
//< 7.5. Trading Strategy Interface Reset 4 >`````````````````````````````````````````````````````````````````//< 442>
//< 443>
avi.Command = EMPTY ; //< 444>
avd.Price = EMPTY ; //< 445>
avd.Stop = EMPTY ; //< 446>
avd.Take = EMPTY ; //< 447>
//< 448>
//</7.5. Trading Strategy Interface Reset 4 >`````````````````````````````````````````````````````````````````//< 449>
...
//< 7.7. Trading Strategy Logic 33 >``````````````````````````````````````````````````````````````````````````//< 546>
...
//< 7.7.2. Buy Rules 2 > //< 553>
if ( NormalizeDouble ( avd.Close.1 - avd.Average.1 , avi.Digits ) > 0 ) //< 554>
if ( NormalizeDouble ( avd.QuoteAsk - ( avd.High.1 + avd.QuoteSpread ) , avi.Digits ) > 0 ) //< 555>
//</7.7.2. Buy Rules 2 > //< 556>
//< 557>
//< 7.7.3. Trading Strategy Interface Set for Buy 8 > //< 558>
{ avd.Price = NormalizeDouble ( avd.QuoteAsk , avi.Digits ) ; //< 559>
avd.Stop = NormalizeDouble ( avd.High.1 + avd.QuoteSpread - avd.QuoteStop , avi.Digits ) ; //< 560>
avd.Take = NormalizeDouble ( avd.QuoteAsk + avd.QuoteTake , avi.Digits ) ; //< 561>
//< 562>
if ( NormalizeDouble ( //< 563>
( avd.Take - avd.Price ) - avd.QuoteStops , avi.Digits ) > 0 ) //< 564>
if ( NormalizeDouble ( //< 565>
( avd.Price - avd.QuoteSpread - avd.Stop ) - avd.QuoteStops , avi.Digits ) > 0 ) //< 566>
avi.Command = OP_BUY ; } //< 567>
//</7.7.3. Trading Strategy Interface Set for Buy 8 > //< 568>
...
//</7.7. Trading Strategy Logic 33 >``````````````````````````````````````````````````````````````````````````//< 591>
...
//< 7.8.4. Order Send Trading Function 29 > //< 636>
...
int ali.Ticket = OrderSend ( aes.Symbol , avi.Command , ald.Size , //< 654>
avd.Price , 0 , avd.Stop , avd.Take , "" , //< 655>
aci.OrderID , 0 , 0 ) ; //< 656>
...
Ok thank you i will try that.
Just one question, is
Ask
equivalent to
MarketInfo (Symbol(), MODE_ASK)
?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody,
I'm just beginning to use MQL4 and i'm begining to like it!!
I'm encoutering my first issue, i'm trying to set BUY and SELL order, but it don't work when i put stop loss and take profit values (if i put 0 it works).
For exemple if i put :
it works, but not with :
it return -1 !
Do you know why it doesn't work?
Cyrille