I really need help!

 
I'm new to this whole thing and I don't know about your first EA but mine has been exhausting so far but I keep learning new stuff so it's kind of fun. Here is the deal as simply as I can put: If the sell condition is met I'd like to sell and then close all buy orders and vice versa. I keep getting orderClose error 138. Now I know what this errors means, I've read the book but since I've got the newbie syndrome I don't know what to do about it in my code. People in this forum have been very helpful to me so far and I'm sure you can help so thanks in advance!
Here is my code:
  if (sellCondition && check!=Low[1]+Close[2] )                                           
  {
  send=OrderSend(Symb,OP_SELL,lots,Bid,2,Ask+600*Point,Ask-2000*Point);
  if (send)
  {
 check=Low[1]+Close[2];   // this prevents the repetition of the orderSend and close for every tick
  
    for(i= OrdersTotal() - 1; i>=0; i--)       
   {
   if(OrderSelect(i,SELECT_BY_POS)==true)
   {
   Tip=OrderType();                
   if (Tip==0)
   {
   Ticket_Buy=OrderTicket();
  double lot=OrderLots();
    RefreshRates();
    Ans=OrderClose(Ticket_Buy,lot,Bid,2);
     }
   }
   }
  }
}
if (buyCondition && check!=Low[1]+Close[2] )                                           
  {
  send=OrderSend(Symb,OP_BUY,lots,Ask,2,Bid-600*Point,Bid+2000*Point);
  if (send)
  {
  check=Low[1]+Close[2];
    for(i= OrdersTotal() - 1; i>=0; i--)       
   {
   if(OrderSelect(i,SELECT_BY_POS)==true)
   {
   Tip=OrderType();                
   if (Tip==0)
   {
   Ticket_Sell=OrderTicket();
  lot=OrderLots();
    RefreshRates();
   Ans=OrderClose(Ticket_Sell,lot,Ask,2);
      }
   }
   }
  }
  }
 
FH
I'm guessing this is a sub-pip account and your Slippage is too small, so try 30 instead of 2 for Slippage
Good Luck
-BB-
 
BarrowBoy:

FH
I'm guessing this is a sub-pip account and your Slippage is too small, so try 30 instead of 2 for Slippage
Good Luck
-BB-


That's exactly what was wrong! Never could have guessed it on my own. Thanks a lot!
 
Tip=OrderType();                
   if (Tip==0) {//...
On your Buy logic, you open a buy, then the above code close all buys. OP_BUY is defined as zero. Get rid of plain constants and use OP_BUY/OP_SELL.

 send=OrderSend(Symb,OP_BUY,lots,Ask,2,Bid-600*Point,Bid+2000*Point); 
On a 5 digit broker a pip is NOT a Point. Your TP/SL should be external int SL.pips=600, Slippage.pips=2 and the EA should adjust:
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int init() {
    if (Digits == 5 || Digits == 3) {   // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
Reason: