ordersend failed with error #130

To add comments, please log in or register
kumaillakhani
166
kumaillakhani  

Hello,

I am getting error # 130 while trying to OrderSend() in MQL4.


   LotSize        = 0.05;              // 0.05 Lot   
   SLPips         = 0.00030;           // 3 pips
   TpFirstOrder   = 0.00100;           // 10 pips
   TpSecondOrder  = 0.00150;           // 15 pips
   StopLossBuy    = Low[2] - SLPips;   // BUY Stop Loss
   StopLossSell   = High[2] + SLPips;  // SELL Stop Loss
   double AskPrice= MarketInfo(NULL,MODE_ASK);
   double BidPrice= MarketInfo(NULL,MODE_BID);

   Ticket1=OrderSend(Symbol(),OP_BUYSTOP,LotSize,AskPrice,3,StopLossBuy,AskPrice+TpFirstOrder,"Pending Order 1",12254,0,clrGreen);
   if(Ticket1<0)
     {
      Comment("OrderSend failed with error #",GetLastError());
     }
   else
     {
      Comment("OrderSend placed successfully");
     }

Experts please help me where I am making mistake?

whroeder1
17949
whroeder1  
  1. Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].

  2. You can't open a pending order at market prices. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

  3. Where do you check if StopLossBuy is below Bid by stop level?
kumaillakhani
166
kumaillakhani  
whroeder1:
  1. Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].

  2. You can't open a pending order at market prices. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

  3. Where do you check if StopLossBuy is below Bid by stop level?

Could please explain its really hard to understand:

  1. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
  2. You can't open a pending order at market prices. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.) 
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
    • I want to open a pending order at which price I can open a pending order?
  3. Where do you check if StopLossBuy is below Bid by stop level?
    • I will check it later. I mean right now I am just trying to open a pending order.
High - Predefined Variables - MQL4 Reference
High - Predefined Variables - MQL4 Reference
  • docs.mql4.com
High - Predefined Variables - MQL4 Reference
kumaillakhani
166
kumaillakhani  
whroeder1:
  1. Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].

  2. You can't open a pending order at market prices. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

  3. Where do you check if StopLossBuy is below Bid by stop level?
   LotSize        = 0.05;              // 0.05 Lot   
   SLPips         = 0.00030;           // 3 pips
   TpFirstOrder   = 0.00100;           // 10 pips
   TpSecondOrder  = 0.00150;           // 15 pips
   StopLossBuy    = Low[2] - SLPips;   // BUY Stop Loss
   StopLossSell   = High[2] + SLPips;  // SELL Stop Loss
   double AskPrice= MarketInfo(_Symbol,MODE_ASK);
   double BidPrice= MarketInfo(_Symbol,MODE_BID);
           
   Ticket1=OrderSend(Symbol(),OP_BUYSTOP,LotSize,AskPrice+0.00030,3,StopLossBuy,AskPrice+0.00030+TpFirstOrder,"Pending Order 1",12254,0,clrGreen);
   if(Ticket1<0)
     {
      Comment("OrderSend failed with error #",GetLastError());
     }
   else
     {
      Comment("OrderSend placed successfully");
     }

Is this code is okay?

Mohamad Zulhairi Baba
15837
Mohamad Zulhairi Baba  
kumaillakhani:

Is this code is okay?

  1. Don't hard code numbers (as @whroeder1 said)
  2. StopLossBuy (and TakeProfit) still didn't check against StopLevel.
    you will eventually still get error 130 (in the future) if you don't check.

   LotSize        = 0.05;              // 0.05 Lot   
   SLPips         = 0.00030;           // 3 pips
   TpFirstOrder   = 0.00100;           // 10 pips
   TpSecondOrder  = 0.00150;           // 15 pips
   StopLossBuy    = Low[2] - SLPips;   // BUY Stop Loss
   StopLossSell   = High[2] + SLPips;  // SELL Stop Loss
   double AskPrice= MarketInfo(_Symbol,MODE_ASK);
   double BidPrice= MarketInfo(_Symbol,MODE_BID);
           
   Ticket1=OrderSend(Symbol(),OP_BUYSTOP,LotSize,AskPrice+0.00030,3,StopLossBuy,AskPrice+0.00030+TpFirstOrder,"Pending Order 1",12254,0,clrGreen);
   if(Ticket1<0)
     {
      Comment("OrderSend failed with error #",GetLastError());
     }
   else
     {
      Comment("OrderSend placed successfully");
     }
To add comments, please log in or register