Need help with OrderSend()

 

Hi,

    I'm trying to place order using the code given below. Please tell whats wrong with it. I thought there is a problem with Ask, so I used NormalizeDouble(Ask,4)

MqlTick last_tick;
         SymbolInfoTick(_Symbol,last_tick);
         double Ask = last_tick.ask;
         double Bid = last_tick.bid;
         MqlTradeRequest request;
         MqlTradeResult result;
         int Total_Trades = 1;
         double TakeProfit = 0.01;
         i++;
         request.action = TRADE_ACTION_DEAL;
         request.magic = 1;
         request.order = i;
         request.price = NormalizeDouble(Ask,4);
         request.sl = 0.0;
         request.tp = NormalizeDouble(Ask+TakeProfit,4);
         request.deviation = 3;
         request.type = ORDER_TYPE_BUY;
         request.type_filling = ORDER_FILLING_RETURN;
         request.comment = "First_Order";
         Print("Entry = ",request.price, ", TP = ", request.tp, ", SL =",request.sl);
         if(OrderSend(request, result)) Print("OrderSent");
         if(result.retcode==10009 || result.retcode==10008)
         {
               i++;
               Print("This is First Buy Order");
         }
                        else
                                {
                                        Print("OrderSend failed with error #",GetLastError());
                                        //return(0);
                                }

2013.07.01 19:47:43 test (EURUSD,H1) OrderSend failed with error #4752

2013.07.01 19:47:43 test (EURUSD,H1) Entry = 1.3032, TP = 1.3132, SL =0.0

 
krishna_gopal_2:

Hi,

    I'm trying to place order using the code given below. Please tell whats wrong with it. I thought there is a problem with Ask, so I used NormalizeDouble(Ask,4)

Hi,

the answer is in this post.

https://www.mql5.com/en/forum/8643 

re error 4752
re error 4752
  • www.mql5.com
"the sell order request could not be completed".
 
launic:

Hi,

the answer is in this post.

https://www.mql5.com/en/forum/8643 

They have discussed about the ERROR #4752.  But now I'm getting ERROR #4756

2013.07.01 20:12:41     test (EURUSD,H1)        OrderSend failed with error #4756
2013.07.01 20:12:41     test (EURUSD,H1)        Entry = 1.3029, TP = 1.3129, SL =0.0

 Please help.

 
krishna_gopal_2:

They have discussed about the ERROR #4752.  But now I'm getting ERROR #4756

 Please help.

https://www.mql5.com/en/search#!keyword=4756
 
After reading some articles I removed the SL and TP. But still I am getting same error #4756. 
          MqlTick last_tick;
         SymbolInfoTick(_Symbol,last_tick);
         double Ask = last_tick.ask;
         double Bid = last_tick.bid;
         MqlTradeRequest request;
         MqlTradeResult result;
         int Total_Trades = 1;
         double TakeProfit = 0.01;
         i++;
         request.action = TRADE_ACTION_DEAL;
         request.magic = 1;
         request.order = i;
         request.price = NormalizeDouble(Ask,4);
         //request.sl = 0;//NormalizeDouble(Ask-0.02,4);
         //request.tp = 0;//NormalizeDouble(Ask+TakeProfit,4);
         request.deviation = 3;
         request.type = ORDER_TYPE_BUY;
         request.type_filling = ORDER_FILLING_RETURN;
         request.comment = "First_Order";
         Print("Entry = ",request.price, ", TP = ", request.tp, ", SL =",request.sl);
         if(OrderSend(request, result)) Print("OrderSent");
 
krishna_gopal_2:
After reading some articles I removed the SL and TP. But still I am getting same error #4756. 
  • You don't have to set request.order for a BUY. Not sure if it's your problem.
  • Can you print the result.retcode when you have an error :
{
        Print("OrderSend failed with error #",GetLastError(), " Retcode = ", result.retcode);
        //return(0);
}
  • If you can provide code that compiles, it would be more easy to help you.
MQL5.community - User Memo
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
angevoyageur:
  • You don't have to set request.order for a BUY. Not sure if it's your problem.
  • Can you print the result.retcode when you have an error :
  • If you can provide code that compiles, it would be more easy to help you.
2013.07.02 15:30:38 test (EURUSD,H1) OrderSend failed with error #4756 Retcode = 10013

2013.07.02 15:30:38 test (EURUSD,H1) Entry = 1.3028, TP = 1.3128, SL =1.2828, Volume = 1.0

I checked volume too. 


 
ulong i =1;
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason){}
void OnTick()
  {
if(i==1)
{
         MqlTick last_tick;
         SymbolInfoTick(_Symbol,last_tick);
         double Ask = last_tick.ask;
         double Bid = last_tick.bid;
         MqlTradeRequest request;
         MqlTradeResult result;
         int Total_Trades = 1;
         double TakeProfit = 0.01;
         i++;
         request.symbol = _Symbol;
         request.action = TRADE_ACTION_DEAL;
         request.magic = 1;
         request.order = i;
         request.price = NormalizeDouble(Ask,4);
         request.sl = NormalizeDouble(Ask-0.02,4);
         request.tp = NormalizeDouble(Ask+TakeProfit,4);
         request.volume = 1;
         request.deviation = 3;
         request.type = ORDER_TYPE_BUY;
         request.type_filling = ORDER_FILLING_RETURN;
         request.comment = "First_Order";
         Print("Symbol = ",_Symbol," Entry = ",request.price, ", TP = ", request.tp, ", SL =",request.sl,", Volume = ",request.volume);
         if(OrderSend(request, result)) Print("OrderSent");
         if(result.retcode==10009 || result.retcode==10008)
         {
               i++;
               Print("This is First Buy Order");
         }
                        else
                                {
                                        Print("OrderSend failed with error #",GetLastError(), " Retcode = ", result.retcode);
                        
                                }
}               
}
Please check the code.
 
krishna_gopal_2:
Please check the code.

You have to modify this line :

      MqlTradeRequest request;

to

      MqlTradeRequest request = {0};
 
angevoyageur:

You have to modify this line :

to

2013.07.02 15:51:56 test (EURUSD,H1) OrderSend failed with error #4756 Retcode = 10030
2013.07.02 15:51:56 test (EURUSD,H1) Symbol = EURUSD Entry = 1.3025, TP = 1.3125, SL =1.2825, Volume = 1.0

Same error after modifying  MqlTradeRequest.


Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
 
krishna_gopal_2:
2013.07.02 15:51:56 test (EURUSD,H1) OrderSend failed with error #4756 Retcode = 10030
2013.07.02 15:51:56 test (EURUSD,H1) Symbol = EURUSD Entry = 1.3025, TP = 1.3125, SL =1.2825, Volume = 1.0

Same error after modifying  MqlTradeRequest.


Check the Symbol information first to see if the Filling mode you are trying to use is valid or not . . .  https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#symbol_filling_mode
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5