- There are no mind readers here. We can't see your code.
- Do you bother to 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
- There are no mind readers here. We can't see your code.
- Do you bother to 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
This is my code for my pending orders:
if(Hour()==9 && Minute()==0 && Seconds()==0) //Specific time for pending/limit order placement { if (Bars!=ThisBarTrade) { ThisBarTrade=Bars; // ensure only one trade opportunity per bar double BuyPendingPrice=Ask+(PendingPips*Point); double SellPendingPrice=Bid-(PendingPips*Point); OrderSend(Symbol(),OP_BUYSTOP,POLotSize,BuyPendingPrice,5,SellPendingPrice+(Break*Point),Ask+(TakeProfit*Point),"Buy Stop Order",POMagicNumber,TimeCurrent()+59400,Purple); OrderSend(Symbol(),OP_SELLSTOP,POLotSize,SellPendingPrice,5,BuyPendingPrice-(Break*Point),Bid-(TakeProfit*Point),"Sell Stop Order",POMagicNumber,TimeCurrent()+59400,Purple); } }And this is my code for my MA orders:
{ double CurrentFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,1); double PreviousFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,2); double CurrentMedium = iMA(NULL,0,MediumMA,MediumMAShift,MediumMAMethod,MediumMAAppliedTo,1); double PreviousMedium = iMA(NULL,0,MediumMA,MediumMAShift,MediumMAMethod,MediumMAAppliedTo,2); double CurrentSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,1); double PreviousSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,2); if(CurrentFast>CurrentSlow && CurrentMedium>CurrentSlow && PreviousFast<PreviousMedium && CurrentFast>CurrentMedium)OrderEntry(0); if(CurrentFast<CurrentSlow && CurrentMedium<CurrentSlow && PreviousFast>PreviousMedium && CurrentFast<CurrentMedium)OrderEntry(1); } void OrderEntry(int direction) { if((Hour()>=StartTimeMA && Hour()<=FinishTimeMA)) //Preferred trading hours { if (Bars!=ThisBarTrade) { ThisBarTrade=Bars; // ensure only one trade opportunity per bar if(direction==0) { double MABSL = Ask-(MAStopLoss*Point); double MABTP = Ask+(MATakeProfit*Point); int buyticket = OrderSend(Symbol(),OP_BUY,MALotSize,Ask,5,0,0,"MA Buy Order",MAMagicNumber,0,SteelBlue); //placing order with ecn broker if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(),MABSL,MABTP,0,CLR_NONE); } if(direction==1) { double MASSL = Bid+(MAStopLoss*Point); double MASTP = Bid-(MATakeProfit*Point); int sellticket = OrderSend(Symbol(),OP_SELL,MALotSize,Bid,5,0,0,"MA Sell Order",MAMagicNumber,0,SteelBlue); if(sellticket>0)OrderModify(sellticket,OrderOpenPrice(),MASSL,MASTP,0,CLR_NONE); } } }
DeanDeV: This is my code
| Answer the question
Do you bother to Check your return codes? |
DeanDeV: This is my code | Answer the question Do you bother to Check your return codes? |
The return codes, and I get OrderSend error code #4107 and error code #3 ??
Not sure if this code is right though... (please note the newly added return code functions)
if((Hour()>=StartTimeMA && Hour()<=FinishTimeMA)) //Preferred trading hours { if (Bars!=ThisBarTrade) { ThisBarTrade=Bars; // ensure only one trade opportunity per bar if(direction==0) { double MABSL = Ask-(MAStopLoss*Point); double MABTP = Ask+(MATakeProfit*Point); int buyticket = OrderSend(Symbol(),OP_BUY,MALotSize,Ask,5,0,0,"MA Buy Order",MAMagicNumber,0,SteelBlue); //placing order with ecn broker if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(),MABSL,MABTP,0,CLR_NONE); if(buyticket<0) { Print("Order Send failed, error # ",GetLastError()); } } if(direction==1) { double MASSL = Bid+(MAStopLoss*Point); double MASTP = Bid-(MATakeProfit*Point); int sellticket = OrderSend(Symbol(),OP_SELL,MALotSize,Bid,5,0,0,"MA Sell Order",MAMagicNumber,0,SteelBlue); if(sellticket>0)OrderModify(sellticket,OrderOpenPrice(),MASSL,MASTP,0,CLR_NONE); if(sellticket<0) { Print("Order Send failed, error # ",GetLastError()); } } } }
if(Hour()==9 && Minute()==0 && Seconds()==0) //Specific time for pending/limit order placement { if (Bars!=ThisBarTrade) { ThisBarTrade=Bars; // ensure only one trade opportunity per bar double BuyPendingPrice=Ask+(PendingPips*Point); double SellPendingPrice=Bid-(PendingPips*Point); OrderSend(Symbol(),OP_BUYSTOP,POLotSize,BuyPendingPrice,5,SellPendingPrice+(Break*Point),0,"Buy Stop Order",POMagicNumber,TimeCurrent()+59400,Purple); OrderSend(Symbol(),OP_SELLSTOP,POLotSize,SellPendingPrice,5,BuyPendingPrice-(Break*Point),0,"Sell Stop Order",POMagicNumber,TimeCurrent()+59400,Purple); } } if(OrderSend(Symbol(),OP_BUYSTOP,POLotSize,BuyPendingPrice,5,SellPendingPrice+(Break*Point),0,"Buy Stop Order",POMagicNumber,TimeCurrent()+59400,Purple)<0) { Print("Order Send failed, error # ",GetLastError()); } if(OrderSend(Symbol(),OP_SELLSTOP,POLotSize,SellPendingPrice,5,BuyPendingPrice-(Break*Point),0,"Sell Stop Order",POMagicNumber,TimeCurrent()+59400,Purple)<0) { Print("Order Send failed, error # ",GetLastError()); }
DeanDeV: This is my code | Answer the question Do you bother to Check your return codes? |
- Since your error message are all the same, you have no idea which OrderSend is failing or all.
- Print out your values sent to the failing OrderSend, and Bid/Ask and find out why.
- Also Print your marketInfo stoplevel, minlot, lotstep
Hey man, is it possible to please assist? I ran the GetLastError() function and got OrderSend error codes 3 and 4107. I have no idea how to fix them? Any help would be greatly appreciated.
Check error codes in help file.
This two you mentioned mean this:
#define ERR_INVALID_TRADE_PARAMETERS 3 #define ERR_INVALID_PRICE_PARAM 4107
You should check values for all parameters of the OrderSend() and OrderModify(). Use debugger or simply print values.
Check error codes in help file.
This two you mentioned mean this:
You should check values for all parameters of the OrderSend() and OrderModify(). Use debugger or simply print values.
Thank you for your help. It gives invalid stop loss for OrderSend() function. Any reason from above why they would be invalid?
3 20:00:26 2015.02.02 15:39 Financial Freedom Bot EURUSD EURUSD: OrderSend error 3 0 20:00:26 2015.02.02 15:39 Financial Freedom Bot EURUSD EURUSD: Order Send failed, error # 3 3 20:00:26 2015.02.02 15:39 Financial Freedom Bot EURUSD EURUSD: invalid stoploss for OrderSend function 3 20:00:26 2015.02.02 15:39 Financial Freedom Bot EURUSD EURUSD: OrderSend error 4107 0 20:00:26 2015.02.02 15:39 Financial Freedom Bot EURUSD EURUSD: Order Send failed, error # 4107
DeanDeV: Any reason from above why they would be invalid?
| There are no mind readers here. You've been told to print your values twice. You won't provide simple information to help us help you. |
DeanDeV: Any reason from above why they would be invalid? | There are no mind readers here. You've been told to print your values twice. You won't provide simple information to help us help you. |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
I have coded an EA and it places perfectly on strategy tester but when it comes to placing on my live account it places occasionally (some days it will place on a currency pair and some days it won't)? Which leaves me frustrated. Do any of you wizards know what could be the problem?
Thanks in advance.