So you check that result is > 0 and the print the last error ? and what do you get ? can you copy and paste the log entry please. Perhaps you Broker became an ECN Broker ?
Here is the result of:
if (result<=0) { Print("Last Error: ", GetLastError()); };
2012.03.01 00:23:49 MyGreatStrategy EURUSD,H4: Last Error: 0.
I am on a test account created from within MetaTrader 4. I get this phenomenon both on MetaQuotes and Forex.com test accounts :-(
Any clues? :-)
Best regards
Huckey
Any clues? :-)
What other code do you have between the 2 bits of code that you posted ?
Try something like this instead . . .
RefreshRates(); if (pOrderType==OP_BUY) { result=OrderSend(pSymbol, pOrderType, pLots, Ask, 0, /*Ask-NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Ask+NormalizeDouble(pTP*SymPoints,SymDigits)); if (result < 0) Print("Buy order failed: ", GetLastError()); else Print("Buy order placed, ticket: ", result); } else { result=OrderSend(pSymbol, pOrderType, pLots, Bid, 0, /*Bid+NormalizeDouble(pSL*SymPoints,SymDigits)*/ 0, Bid-NormalizeDouble(pTP*SymPoints,SymDigits)); if (result < 0) Print("Sell order failed: ", GetLastError()); else Print("Sell order placed, ticket: ", result); } }
2012.03.01 00:23:49 MyGreatStrategy EURUSD,H4: Last Error: 0.
- That means no error. You most likely didn't even call OrderSend
- Only call getLastError after you get error return, like Raptor showed.
- OrderSend returns -1 on error (zero may be a valid ticket)
- Post ALL the code from after the decision through the alerts.
- On ECN brokers you must open first and THEN set stops
- Drop your NormalizeDouble. That call is ALWAYS unnecessary - don't use it.
Hi again,
just wanted to thank for all replies - they led me to the solution.
Eventually, the code proposed by Raptor did not change the situation - I still got 0. I started playing around and come to the conclusion that there was a problem with Take Profit parameter in my code. The strange thing is that I did not get INVALID_STOPS error but 0 and that the code had worked before and stop working without any change to it (and was working on a test account).
So the case is closed and the error showed to be invalid Take Profit.
Best regards
Jacek

- 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,
since a few days (the last update) I have noticed a problem with my Expert: OrderSend function 0 and no position is opened. There is no error returned but no ticket is created. Here is my code:
.
In another version of this Expert I am also checking it the Trading Context is free (even though I do not get any error suggesting it) and it is.
What can be the reason? I am really getting frustrated...
Best regards
Huckey