А для какой цели, я и так знаю какие ошибки вылетают 10015 и 10016. Дело в том что в спецификации инструмента XAUUSD и XAGUSD указан шаг цены 0,01 а тики в тестере генерируются с шагом 0,001. Ошибку 10016 Неправильные стопы в запросе я вроде победил, а вот ошибку 10015 Неправильная цена в запросе победить не могу.
//+------------------------------------------------------------------+ //| Test_04.mq5 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #include <TradeTrade.mqh> CTrade trade; int m_atr=0; int Period_ATR=21; ENUM_TIMEFRAMES TF_ATR=PERIOD_CURRENT; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double price=0.0; double volume=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN); //int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS); //double ts=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE); //double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID); //double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK); //if(bid<=0.0 || ask<=0.0)return; if(!PositionSelect(_Symbol)) { trade.Buy(volume,_Symbol); } double SL=Dynamic_Stop(_Symbol,3); double TP=Dynamic_Stop(_Symbol,6); Modify(_Symbol,SL,TP); Trailing_Stop(_Symbol,SL); } //+------------------------------------------------------------------+ bool NewBar(string symbol,ENUM_TIMEFRAMES period) { static datetime lastbar; datetime curbar=(datetime) SeriesInfoInteger(symbol,period,SERIES_LASTBAR_DATE); if(lastbar==0)lastbar=(datetime)SeriesInfoInteger(symbol,period,SERIES_LASTBAR_DATE); if(lastbar!=curbar) { lastbar=curbar; return(true); } return(false); } //+------------------------------------------------------------------+ void Modify(string symbol,double sl,double tp) { if(sl<0 || tp<0)return; double price=0.0; double bid=SymbolInfoDouble(symbol,SYMBOL_BID); double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); double point=SymbolInfoDouble(symbol,SYMBOL_POINT); int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); double ts=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE); if(bid<=0.0 || ask<=0.0)return; if(PositionSelect(symbol)) { if(PositionGetDouble(POSITION_SL)==0 && PositionGetDouble(POSITION_TP)==0) { price=PositionGetDouble(POSITION_PRICE_OPEN); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { //tp=NormalizeDouble(normalize(symbol,bid+tp*point),digits); //sl=NormalizeDouble(normalize(symbol,bid-sl*point),digits); tp=NormalizeDouble(normalize(symbol,price+tp*point),digits); sl=NormalizeDouble(normalize(symbol,price-sl*point),digits); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { //tp=NormalizeDouble(normalize(symbol,ask-tp*point),digits); //sl=NormalizeDouble(normalize(symbol,ask+sl*point),digits); tp=NormalizeDouble(normalize(symbol,price-tp*point),digits); sl=NormalizeDouble(normalize(symbol,price+sl*point),digits); } if(sl<0 || tp<0)return; trade.PositionModify(symbol,sl,tp); } } } //+------------------------------------------------------------------+ void Trailing_Stop(string symbol,double sl) { double tp=0.0; if(sl<=0)return; double bid=SymbolInfoDouble(symbol,SYMBOL_BID); double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); double point=SymbolInfoDouble(symbol,SYMBOL_POINT); int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); if(bid<=0.0 || ask<=0.0)return; if(PositionSelect(symbol)) { if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { tp=PositionGetDouble(POSITION_TP); sl=NormalizeDouble(normalize(symbol,bid-sl*point),digits); if(sl<=PositionGetDouble(POSITION_SL))return; } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { tp=PositionGetDouble(POSITION_TP); sl=NormalizeDouble(normalize(symbol,ask+sl*point),digits); if(sl>=PositionGetDouble(POSITION_SL))return; } if(sl<0 || tp<0)return; trade.PositionModify(symbol,sl,tp); } } //+------------------------------------------------------------------+ double Dynamic_Stop(string symbol,double k) { double atr[1]; double ts=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE); double point=SymbolInfoDouble(symbol,SYMBOL_POINT); if(Bars(symbol,TF_ATR)<Period_ATR+1)return(WRONG_VALUE); if(m_atr==INVALID_HANDLE || m_atr==0) { m_atr=iATR(symbol,TF_ATR,Period_ATR); return(WRONG_VALUE); } if(CopyBuffer(m_atr,0,1,1,atr)<1)return(WRONG_VALUE); double vol=atr[0]/point*k; if(vol<=SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL))vol*=2.0; //vol=NormalizeDouble(vol/ts,0)*ts; return(vol); } //+------------------------------------------------------------------+ double normalize(string symbol,double value) { double ts=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE); return(NormalizeDouble(value/ts,0)*ts); } //+------------------------------------------------------------------+
The MQL4 OrderSend Error 4107 mainly occurs during an Expert Advisor (EA) backtesting in the MT4 platform. It refers to an invalid price issue in the OrderSend function that prevents your EA from reading the price data correctly.
An automated trading system may fail to recognize the MT4 price quote for multiple reasons. However, fixing such issues is not as complex as we might think. This guide will explain what is MQL4 OrderSend Error 4107 and how to fix it within a few simple steps.
What is MT4 (MQL4) Error 4107?
MT4 error 4107 is an MQL4 runtime error that refers to an invalid price parameter of the expert advisor.
It means your EA is not reading the ask/bid rate provided by the MT4 system as a valid price. Whenever the system encounters an invalid price for the OrderSend function, it stops working and sends the error code.
Generally, we experience the MT4 OrderSend error 4107 while performing the backtest of EAs. However, your system may send the same error code due to OrderSend and OrderModify function failures. In such a case, the platform displays ERR_INVALID_PRICE_PARAM to address the invalid price issue.
Why does MT4 (MQL4) error 4107 happen?
MQL4 error 4107 happens due to the following reasons:
- Negative value issue: When your EA uses an invalid price parameter, it may read the MetaTrader 4 quotes as invalid prices and display “error 4107 – invalid price for OrderSend function.” An invalid price parameter means the order execution price requested by the EA is not matching the current ask/bid rate. A negative value issue may also affect buy-stop, sell-stop, stop-loss, and take-profit parameters of the OrderSend or OrderModify functions.
- Unnormalized doubles: If your expert advisor tries to place a five decimal price order in a 4-digit MT4 terminal, you will still encounter MQL4 OrderSend error 4107. In this case, the EA finds the 5th decimal missing in the MetaTrader price quote and eventually considers it an invalid price for order executions. Like negative values, unnormalized doubles also affect your automated trading program’s OrderSend and OrderModify functions.
How to fix MT4’s OrderSend error 4107 in MQL4?
Time needed: 5 minutes.
- Check the price parameters of the EA:
Make sure your expert advisor is not applying negative parameters in the order opening and modification functions. You may consider checking the RefreshRates, OrderSend, OrderModification, ask/bid point limits, and stop-loss functions to ensure a valid price parameter.
Moreover, some brokers allow the take profit target and stop-loss settings or modification only after activating an order. In that regard, an EA should request an order activation and TP/SL parameters only after executing an entry successfully.
If you want your EA to open orders without a TP or SL, try the following settings in the OrderSend function:
- Normalize price doubles:
Both the EA and MetaTrader4 terminal should be using the same digit price to avoid unnormalized doubles. Therefore, consider normalizing all the price doubles by using the standard MT4 functions:
- Consider changing the broker:
If you want to fix the MQL4 OrderSend Error 4107 without modifying your EA, then consider switching to a 5-digit broker.
I ended up modifying the code in the MQL part of the EA
MqlTick _trade_current_price;
if (_type == 0)
{
//_price = _trade_open_price.ask;
if(_symbol == «NULL») {
double _trade_open_price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
Comment(«Order is buy: «, _trade_open_price);
ticket = OrderSend(Symbol(), _type, _lots, _trade_open_price, MaximumSlippage, sl, tp, _comment, _magic);
} else {
double _trade_open_price = SymbolInfoDouble(_symbol, SYMBOL_ASK);
Comment(«Order is buy: «, _trade_open_price);
ticket = OrderSend(_symbol, _type, _lots, _trade_open_price, MaximumSlippage, sl, tp, _comment, _magic);
}
} else if (_type == 1)
{
//_price = _trade_open_price.bid;
if(_symbol == «NULL») {
double _trade_open_price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
Comment(«Order is sell: «, _trade_open_price);
ticket = OrderSend(Symbol(), _type, _lots, _trade_open_price, MaximumSlippage, sl, tp, _comment, _magic);
} else {
double _trade_open_price = SymbolInfoDouble(_symbol, SYMBOL_BID);
Comment(«Order is sell: «, _trade_open_price);
ticket = OrderSend(_symbol, _type, _lots, _trade_open_price, MaximumSlippage, sl, tp, _comment, _magic);
}
} else
{
if(_symbol == «NULL») {
ticket = OrderSend(Symbol(), _type, _lots, _price, MaximumSlippage, sl, tp, _comment, _magic);
} else {
ticket = OrderSend(_symbol, _type, _lots, _price, MaximumSlippage, sl, tp, _comment, _magic);
}
}
These are the results I get. Please note that when I tried it multiple times, before the mods, it didn’t work at all:
C:UsersLungile MadiAnaconda3libsite-packagesipykernelparentpoller.py:116: UserWarning: Parent poll failed. If the frontend dies,
the kernel may be left running. Please let us know
about your system (bitness, Python, etc.) at
ipython-dev@scipy.org
ipython-dev@scipy.org»»»)
runfile(‘C:/Users/Lungile Madi/Documents/project1/dwx-zeromq-connector-master/v2.0.1/python/api/DWX_ZeroMQ_Connector_v2_0_1_RC8.py’, wdir=’C:/Users/Lungile Madi/Documents/project1/dwx-zeromq-connector-master/v2.0.1/python/api’)
_zmq = DWX_ZeroMQ_Connector()
[INIT] Ready to send commands to METATRADER (PUSH): 32768
[INIT] Listening for responses from METATRADER (PULL): 32769
_zmq.DWX_MTX_GET_ALL_OPEN_TRADES()
{‘_action’: ‘OPEN_TRADES’, ‘_trades’: {}}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483640, ‘_open_time’: ‘2019.04.11 17:02:45’, ‘_open_price’: 1.12704, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_CLOSE_TRADES_BY_MAGIC(123456)
{‘_action’: ‘CLOSE_ALL_MAGIC’, ‘_magic’: 123456, ‘_responses’: {155483640: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12701, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}}, ‘_response_value’: ‘SUCCESS’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_response’: ‘129’, ‘response_value’: ‘invalid price’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_response’: ‘129’, ‘response_value’: ‘invalid price’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_response’: ‘136’, ‘response_value’: ‘off quotes’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483856, ‘_open_time’: ‘2019.04.11 17:06:26’, ‘_open_price’: 1.12688, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_response’: ‘129’, ‘response_value’: ‘invalid price’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483877, ‘_open_time’: ‘2019.04.11 17:06:39’, ‘_open_price’: 1.12678, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_CLOSE_TRADES_BY_MAGIC(123456)
{‘_action’: ‘CLOSE_ALL_MAGIC’, ‘_magic’: 123456, ‘_responses’: {155483877: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12675, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}, 155483856: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12676, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}}, ‘_response_value’: ‘SUCCESS’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483920, ‘_open_time’: ‘2019.04.11 17:07:22’, ‘_open_price’: 1.12694, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483922, ‘_open_time’: ‘2019.04.11 17:07:25’, ‘_open_price’: 1.12694, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_magic’: 123456, ‘_ticket’: 155483926, ‘_open_time’: ‘2019.04.11 17:07:28’, ‘_open_price’: 1.12698, ‘_sl’: 500.0, ‘_tp’: 500.0}
_zmq.DWX_MTX_CLOSE_TRADES_BY_MAGIC(123456)
{‘_action’: ‘CLOSE_ALL_MAGIC’, ‘_magic’: 123456, ‘_responses’: {155483926: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12685, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}, 155483922: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12685, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}, 155483920: {‘_symbol’: ‘EURUSD’, ‘_close_price’: 1.12685, ‘_close_lots’: 0.01, ‘_response’: ‘CLOSE_MARKET’}}, ‘_response_value’: ‘SUCCESS’}
_zmq.DWX_MTX_NEW_TRADE()
{‘_action’: ‘EXECUTION’, ‘_response’: ‘136’, ‘response_value’: ‘off quotes’}
The GetLastError() function returns the last error code. The Error code constants are defined in the stderror.mqh file.
To print text messages use the ErrorDescription() function defined in the stdlib.mqh file.
Constant
Value
Description
-
#1
I have been on demo with SLM MT4 for a few weeks and get the occasional invalid price when trying to open or close a position, this is mostly when price is moving fast and I was prepared to put up with it because genarally I really like the platfrom.
90% of the time I set pending buy/sell stop orders but 10% of the time I like to use the instant execution option.
These last 2 days I have been getting so many «invalid Prices» messages in a row when trying to open or close a position.
I tried to open a position on EU/US and clicked buy 5 times in a row and got the same message so I gave up.
This happened many times to me yesterday on GBP/USD too.
I was trying to close a position and I kept getting that same error message.
I was going to open a live account but will have to see if the problem can be solved.
It is being looked into now.
1)Anyone else had a similar problem as this?
2) Is it practical to open a spreadbetting account with a US company if I am British living in the UK?
3) Are there any other UK Spreadbetting firms that offer mt4?
4) Can anyone recommend a good UK Spreadbetting firm with a good platform.
-
#2
1) Yes
2) Spreadbetting isn’t legal in the US
3) Don’t think so now
4) They all have good and bad points, but CityIndex seems good these days
-
#3
Thanks for the reply Ross.
Regarding my first question which you replied yes to. What platform and company did/do you experience the repetitive invalid price problem?
Everything was fine until a couple of days ago when it started. It is not during news or fast moving prices but seemingly most the time now. I made a quick recording and will try to post it in the SLM thread later. It was only 3 attempts but my record is 12 before giving up.
I really like MT4 charting and the whole platfrom really.
I see Alpari are US based but have a branch in London, they have 4 platfroms to choose from but do not offer spreadbetting.
I will have a look at Cityindex.
Which ever company I go with I will need to test out the platform on a Demo account for a while.
-
#4
Quite pissed off that I got the Invalid Prices thing and another error if im not wrong but I remember I got the Invalid prices crap 5 TIMES today at 14:00 hours on the EuroUsd…There was no sudden or volatile movement at that point on my chart, I had a short trade that I really needed to take…But couldn’t. Missed out my trade which in the end would have netted me 42 pips or so of profit.
I have a chart to prove I had a short signal but not sure if they would honor it as I spoke to them on the phone and mentioned this is unacceptable as ive had this Invalid prices tripe going on my slm’s mt4 for over a month to a month and a half now…
i dont have problems with my Internet connection and im on a solid 20mb connection so theres not any bandwidth problems either…
I actually moved to SLM from IG based on a recommendation from a close friend who also moved with me, but im quite disappointed with this as its frankly taking the mick with re-quotes or Invald price errors around 1 out of every 2 trades I execute so Its causing me to get higher prices and causing me to miss trades and potential profit, missing out on my profit causes the rest of my targets and MM to **** up for the week.
Any ideas? I have the latest build of mt4. I dont seem to have firewall/router or antivirus issues as ive checked and double checked that now as Im a network engineer. Ive spoken to Virgin who is my ISP and they dont appear to have any problems on my line either.
Suggesstions? Numerous people are having this and frankly if its not dealt with is going to lead to some bad rep for SLM im sure.
-
#5
Obviously SLM are having issues at the moment. They normally post on here regularly but have been quiet the past week or so. The last time they did this was also a time when everyone was complaining about problams. I think the issue (as someone else mentioned) is how they bridge the FX and futures feeds to a single spreadbet platform. It cant be easy.