Issue with BUYSTOP and SELL STOP orders?

 

Hi guys,

Am trying to create a simple EA that sets pending buy/sell STOP orders at previous bar high & low. See below

 

extern bool       TradeOnClose = true;
extern int        MagicNo = 144500;
extern double     Lots = 0.01;
extern int        SL = 20;
extern int        TP = 60;


void OnTick()
{

   if(TradeOnClose==true)
   {
      if (New_Bar()==true)
      {  
            
        /*
        //LIMIT ORDERS BELOW WORK FINE
        ticket = OrderSend(Symbol(), OP_SELLLIMIT, Lots, High[1], 3, Bid + (SL * Point), Bid - (TP * Point), "HIGH- SELL LIMIT", MagicNo, TimeCurrent()+ (PERIOD_M15*60));
        Comment("PENDING HIGH- SELL LIMIT");
        ticket = OrderSend(Symbol(), OP_BUYLIMIT, Lots, Low[1], 3, Ask - (SL * Point), Ask + (TP * Point), "LOW- BUY LIMIT", MagicNo, TimeCurrent()+ (PERIOD_M15*60));
        Comment("PENDING LOW- BUY LIMIT");
        */
        
        
        //STOP ORDERS BELOWDO NOT WORK CORRECTLY... HELP- WHAT AM I DOING WRONG..?
        ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, High[1], 3, Ask - (SL * Point), Ask + (TP * Point), "HIGH- BUY STOP", TimeCurrent()+ (PERIOD_M15*60));
        Print("PENDING HIGH- BUY STOP");
               
        ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, Low[1], 3, Bid + (SL * Point), Bid - (TP * Point), "LOW- SELL STOP", TimeCurrent()+ (PERIOD_M15*60));
        Print("PENDING LOW- SELL STOP");
        
      }
   }
}  


//+------------------------------------------------------------------+
//| New_Bar() function                                               |
//|  - Checks for new bar                                            |
//+------------------------------------------------------------------+
bool New_Bar()
{
   static datetime New_Time = 0;
   
   if(New_Time!= Time[0])
   {
      New_Time = Time[0];
      return(true);
   }
   else 
      return(false);
}

 there are 2 issues I'm having:

 

1. OP_BUYSTOP order is placed but SL and TP are not correct (not 20 & 60 pips away, they're the other way around, very strange..?

2.  OP_SELLSTOP order is never placed. I get OrderSend Error130, cannot figure out why

 

Appreciate any help, sorry I'm a newbie! 

 
Maybe Stoploss is too low. You don't check the minimum stoploss of your broker. So try a higher Stoploss or check it with MarketInfo(Symbol(), MODE_STOPLEVEL)
 
rg144:

Hi guys,

Am trying to create a simple EA that sets pending buy/sell STOP orders at previous bar high & low. See below

 

 there are 2 issues I'm having:

 

1. OP_BUYSTOP order is placed but SL and TP are not correct (not 20 & 60 pips away, they're the other way around, very strange..?

Check your inputs, that's not possible from the code you posted.


2.  OP_SELLSTOP order is never placed. I get OrderSend Error130, cannot figure out why

 

Appreciate any help, sorry I'm a newbie! 

You have to check your prices : open price, stoploss & takeprofit. Open price must be below market for a SELL_STOP, where are you checking it ?

Also check stoplevel as suggested by "Top-SecreT".

Check this document for the rules to follow when placing an order :

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
 

Thanks guys for your replies.

Rather than use Bid & Ask for SL/TP levels, I am simply using the High[] & Low[] for TP/SL . This works as intended.

Thanks also Alain for reference to Trade Requirements & Limitations, very very handy.

Reason: