-
Play videoPlease edit your post.
For large amounts of code, attach it.
Order2Ticket=OrderSend(Symbol(),OP_SELL,Order2LotSize,Bid,3,0,0,NULL,MagicNumber,0,Red);
Check your return codes (OrderSend) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 ArticlesOrder3Ticket=OrderSend(Symbol(),OP_BUYSTOP,Order3LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green);
You can't post a pending order at current market price.
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- Check your return codes (OrderSend) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Hi WHRoeder, thanks for responding to my post. I forgot to mention I am also a newbie to this forum :)
Actually the line of code that you've highlighted was intended to be a OP_BUY instead, not OP_BUYSTOP. I was just playing around hoping to workaround the issue.
The OrderSend function is supposed to return the integer value of the ticket number. Is there something wrong with the codes?
int Order1Ticket=0; int Order2Ticket=0; int Order3Ticket=0; Order3Ticket=OrderSend(Symbol(),OP_BUY,Order3LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green);
Following is the journal log from the MT4 backtester. From the log, the first and second trades are correctly opened with SL and TP correctly set.
But it just refused to enter the 3rd trade, and there is no error in the log. Do you know what could be wrong?
2015.04.18 02:03:54.670 EURUSD,M1: 4160923 tick events (92931 bars, 4161924 bar states) processed within 1326 ms (total time 1950 ms)
2015.04.18 02:03:53.438 2015.01.07 00:07 Tester: take profit #2 at 1.18560 (1.18537 / 1.18552)
2015.04.18 02:03:53.375 2015.01.05 00:02 Tester: stop loss #1 at 1.18560 (1.18549 / 1.18564)
2015.04.18 02:03:53.360 2015.01.02 19:11 The Recovery Algorithm (5) EURUSD,M1: Order 2.0 was successfully modified.
2015.04.18 02:03:53.360 2015.01.02 19:11 The Recovery Algorithm (5) EURUSD,M1: modify #2 sell 0.08 EURUSD at 1.20060 sl: 1.22060 tp: 1.18560 ok
2015.04.18 02:03:53.360 2015.01.02 19:11 The Recovery Algorithm (5) EURUSD,M1: open #2 sell 0.08 EURUSD at 1.20060 ok
2015.04.18 02:03:53.360 2015.01.02 09:00 The Recovery Algorithm (5) EURUSD,M1: Order 1.0 was successfully modified.
2015.04.18 02:03:53.360 2015.01.02 09:00 The Recovery Algorithm (5) EURUSD,M1: modify #1 buy 0.01 EURUSD at 1.20560 sl: 1.18560 tp: 1.22060 ok
2015.04.18 02:03:53.360 2015.01.02 09:00 The Recovery Algorithm (5) EURUSD,M1: open #1 buy 0.01 EURUSD at 1.20560 ok
2015.04.18 02:03:53.344 The Recovery Algorithm (5) inputs: InitialLotSize=0.01; RecoveryZoneWidth=50; DistanceToTakeProfit=150; TakeProfit=10; FirstOrderBuyOrSell=0; MaxOrders=10; MagicNumber=1234;
2015.04.18 02:03:52.720 TestGenerator: spread set to 15
2015.04.18 02:03:52.705 Expert The Recovery Algorithm (5) EURUSD,M1: removed
If you had done as WHRoeder suggested and checked the return from the order send, you might get some clue.
But I think that it is highly likely that the price did not actually return to the level that would trigger the 3rd trade as The EURUSD was in free fall at that time.
Did you actually check that conditions were met to open the 3rd trade?
If you had done as WHRoeder suggested and checked the return from the order send, you might get some clue.
But I think that it is highly likely that the price did not actually return to the level that would trigger the 3rd trade as The EURUSD was in free fall at that time.
Did you actually check that conditions were met to open the 3rd trade?
I don't see anything too wrong with your code, but it is always a good habit to avoid unnecessary function calls to keep it as efficient as possible.
{//This first section of codes is to open the first trade (BUY order) and no issue with this. if(OpenOrdersTotal==0) //This function is called every tick to test the condition, so not really necessary to call again { BuyLevel=MarketInfo(Symbol(),MODE_ASK); SellLevel=BuyLevel-RecoveryZoneWidth; UpperLevel=BuyLevel+DistanceToTakeProfit; LowerLevel=BuyLevel-RecoveryZoneWidth-DistanceToTakeProfit; Order1Ticket=OrderSend(Symbol(),OP_BUY,Order1LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green); if(Order1Ticket>0 && OrderSelect(Order1Ticket,SELECT_BY_TICKET,MODE_TRADES)==true) { if(OrderModify(Order1Ticket,OrderOpenPrice(),LowerLevel,UpperLevel,0,CLR_NONE)) Print("Order ",Order1Ticket," was successfully modified."); else Print("Order ",Order1Ticket," was NOT successfully modified.",GetLastError()); //OpenOrdersTotal=CountOrders(); OpenOrdersTotal++; RefreshRates(); //Why call after placing the order? } else { //Error report for failed OrderSend } }
I don't see anything too wrong with your code, but it is always a good habit to avoid unnecessary function calls to keep it as efficient as possible.

- 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 folks, I am a newbie in coding and I am coding a Zone Recovery EA, but I am stuck with this problem for a while and still unable to fix it.
I've extracted out a section of the source code as you can see below. This section of codes is supposed to make the EA do the following:
1) Open a BUY order when there is no active trade
2) If price moves downwards against my BUY order for a certain amount of pips distance, the EA will open a SELL order
3) After the SELL order is opened and if the price moves up again for a certain amount of pips distance, the EA will open another BUY order
When I do backtesting, the EA has no problem entering the first and second trades with the defined SL and TP, but for some reason it is always unable to enter the 3rd trade.
Below is the extract of the source. I've spent a number of late nights trying to figure this out but still unable to fix. So any help or advice is greatly appreciated! :)