https://docs.mql4.com/trading/errors.
https://www.mql5.com/en/forum/133824.
If you send the orders with stoploss and take profit of Zero and that doesn't solve your problem .. then follow the documentations recommendations and make sure its not a problem from the first link.
But if you look at my code, the part that creates one market order and one pending order together should not be called if hedgeCreated is true. However, those OrderSends are still being sent after hedgeCreated is set to true.
This part ? if hedgeCreated is true it can create one order on the first run through and the other on the next . . . please show what is printed to the journal/experts tab . . .
if (hedgeCreated) { if ((nextPos=="short") && (Bid <= SHedge)) { ticket=OrderSend(Symbol(),OP_BUYSTOP,nextLot,LHedge,3,longStop,longTake); if (ticket>0) Print("Created LHedge ",LHedge," ",nextLot," lots"); else { err=StringConcatenate("New Hedge long failed:",GetLastError(),"|",LHedge,"|stop:",longStop,"|Take:",longTake); Print(err); } nextLot*=2; nextPos="long"; } if ((nextPos=="long") && (Ask >= LHedge)) { ticket=OrderSend(Symbol(),OP_SELLLIMIT,nextLot,SHedge,3,shortStop,shortTake); if (ticket>0) Print("Created LHedge ",SHedge," ",nextLot," lots"); else { err=StringConcatenate("New Hedge short failed:",GetLastError(),"|",SHedge,"|stop:",shortStop,"|Take:",shortTake); Print(err); } nextLot*=2; nextPos="short"; } }
actually the part before in the if (!hedgeCreated) block.....inside it i set hedgecreated to true so the block should be called only once but the orders in there are being called more than once.This part
if (!hedgeCreated)
{
if (Ask >= LHedge)
{
//ticket=OrderSend(Symbol(),OP_BUY,startLot,LHedge,1,longStop,longTake);
ticket=OrderSend(Symbol(),OP_BUY,startLot,LHedge,1,0,0);
if (ticket>=0) Print("Hedge long at ",LHedge," ",longStop," ",longTake);
else { err=StringConcatenate("Hedge long failed:",GetLastError(),"|",LHedge,"|stop:",longStop,"|Take:",longTake); Print(err); }
if (ticket>=0)
OrderModify(ticket,LHedge,longStop,longTake,0,CLR_NONE);
nextLot=startLot*3;
//ticket=OrderSend(Symbol(),OP_SELLSTOP,nextLot,SHedge,1,shortStop,shortTake);
ticket=OrderSend(Symbol(),OP_SELLSTOP,nextLot,SHedge,1,0,0);
if (ticket>=0) Print("Hedge short at ",SHedge," ",shortStop," ",shortTake);
else { err=StringConcatenate("Pending Hedge short failed:",GetLastError(),"|",SHedge,"|stop:",shortStop,"|Take:",shortTake); Print(err); }
if (ticket>=0)
OrderModify(ticket,SHedge,shortStop,shortTake,0,CLR_NONE);
nextLot*=2;
hedgeCreated=true;
nextPos="short";
}
if (Bid <= SHedge)
{
//OrderSend(Symbol(),OP_SELL,startLot,SHedge,1,shortStop,shortTake);
ticket=OrderSend(Symbol(),OP_SELL,startLot,SHedge,1,0,0);
if (ticket>=0) Print("Hedge short at ",SHedge," ",shortStop," ",shortTake);
else Print("Hedge short failed:",GetLastError());
if (ticket>=0)
OrderModify(ticket,SHedge,shortStop,shortTake,0,CLR_NONE);
nextLot=startLot*3;
//OrderSend(Symbol(),OP_BUYLIMIT,nextLot,LHedge,1,longStop,longTake);
ticket=OrderSend(Symbol(),OP_BUYLIMIT,nextLot,LHedge,1,0,0);
if (ticket>=0) Print("Hedge long at ",LHedge," ",longStop," ",longTake);
else { err=StringConcatenate("Pending Hedge long failed:",GetLastError(),"|",LHedge,"|stop:",longStop,"|Take:",longTake); Print(err); }
if (ticket>=0)
OrderModify(ticket,LHedge,longStop,longTake,0,CLR_NONE);
nextLot*=2;
hedgeCreated=true;
nextPos="long";
}
}
actually the part before in the if (!hedgeCreated) block.....
The code I posted will do what you described . . . ". . . . the part that creates one market order and one pending order together should not be called if hedgeCreated is true. However, those OrderSends are still being sent after hedgeCreated is set to true."
Please post the Prints from the journal/experts tab to show what is actually opening the Orders . . .
Here is the latest update of the EA. I'll post the Prints from Experts once I have enough data in that tab.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I created an EA to open a hedged trade with opposing stoploss and take profit in both direction. It also adds pending orders of increasing lotsize as price direction reverses.
However, sometimes the EA fails to open the orders and i get error 130.
Can someone please tell me what I'm doing wrong? Thanks in advance....