What does GetLastError() print in those error cases?
Also: my suggestion is to place ResetLastError() before you call OrderSend(). In that case you will be sure that the error message in GetLastError() is the result of OrderSend().
OrderSend(mrequest,mresult); ⋘⋘⋘⋘⋘⋘⋘⋘⋘⋘ OrderSend was called here } ⋘⋘⋘⋘⋘⋘⋘⋘⋘⋘ Condition 3 & 4 } ⋘⋘⋘⋘⋘⋘⋘⋘⋘⋘ Condition 1 ⋘⋘⋘⋘⋘⋘⋘⋘⋘⋘ OrderSend may not have been called here // get the result code ⋘⋘⋘⋘⋘⋘⋘ What result code?Test your result codes after the call to OrderSend. Currently, you are testing them whether you call it or not.
What does GetLastError() print in those error cases?
Also: my suggestion is to place ResetLastError() before you call OrderSend(). In that case you will be sure that the error message in GetLastError() is the result of OrderSend().
4756 | Trade request sending failed |
On the journal tab in MT5 (after a few more tries) sometimes prints:
failed exchange buy 0.1 EURUSD at 1.24172 sl: -298.75828 tp: 1001.24172 [Invalid stops]
After moving ResetLastError() before OrderSend() , GetLastError() prints:
ERR_TRADE_POSITION_NOT_FOUND | 4753 | Position not found |
and again sometimes prints the invalid stops error
Not sure if it's something strange with my sl and tp numbers. I have it set at sl=30 and tp=100, multiplied by ten if it's a three/five digit quote.
Test your result codes after the call to OrderSend. Currently, you are testing them whether you call it or not.
Hi,
⋘⋘⋘⋘⋘⋘⋘⋘⋘⋘ OrderSend may not have been called here
I'm not quite sure what you mean. ^^^
Get result code comment is referring to the lines below it.
Codes checked:
10008 | TRADE_RETCODE_PLACED | Order placed |
10009 | TRADE_RETCODE_DONE | Request completed |
This is your code if Condition1 is false
if(Buy_Condition_1) { ⋮ ⋘⋘⋘⋘ Not executed because of a false condition. } // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Buy order request could not be completed -error:",GetLastError()); ResetLastError(); return; }
What are you testing?
This is your code if Condition1 is false
What are you testing?
Yes that is correct. It is just that when all conditions are true, the code executes all the way to OrderSend() , but prints out the highlighted message, meaning the order did not place. It is also printing another message, invalid stops, see my response to WindmillMQL.
Get Last Error prints
4756 | Trade request sending failed |
On the journal tab in MT5 (after a few more tries) sometimes prints:
failed exchange buy 0.1 EURUSD at 1.24172 sl: -298.75828 tp: 1001.24172 [Invalid stops]
After moving ResetLastError() before OrderSend() , GetLastError() prints:
ERR_TRADE_POSITION_NOT_FOUND | 4753 | Position not found |
and again sometimes prints the invalid stops error
Not sure if it's something strange with my sl and tp numbers. I have it set at sl=30 and tp=100, multiplied by ten if it's a three/five digit quote.
You have tried to place an order with a negative stoploss price. Such an order will not be accepted, so that's why you get an error message "trade request sending failed".
To be honest: both the stoploss and profit taker prices seem strange to me. The EURUSD is usually about 1.1 or so. Why do you use a negative value for sl and a value of about one thousand as pt? That doesn't make sense to me.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
What's the reason the highlighted alert keeps showing? Even though all buy conditions are true. Is there a way to debug this to see the code run automatically (without breakpoints) but not instantly? Thanks