help- keep getting OrderSend error 138

 
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

double lots = 0.01;
int takeprofit = 40;
int stoploss = 40;
int magic =33454;


int OnInit()

  {
   return(INIT_SUCCEEDED);
  }






void OnDeinit(const int reason)
  {
   
  }




void OnTick()
  {
   bool check = checkMA();
   if (check == True)
      openBuy();
      
      
   if (check == False)
      openSell();
      
  }
//+------------------------------------------------------------------+


bool checkMA()
{
  double ma = 0;
  ma = iMA(Symbol(),0,25,0,MODE_SMA,PRICE_CLOSE,0);
  
  if(Ask>ma) return(True);
  if(Ask<ma) return(False);
  return(EMPTY_VALUE);

}

void openBuy()
{
  OrderSend(Symbol(),OP_BUY,lots,Bid,3,Bid-stoploss*Point,Bid+takeprofit*Point,"buy Trade",magic, Blue);
}


void openSell()
{
  OrderSend(Symbol(),OP_SELL,lots,Ask,3,Ask+stoploss*Point,Ask-takeprofit*Point,"Sell Trade",magic, Red);
}

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. [[[help]]] keep getting OrderSend error...
 

Please use the insert code button (Alt + S) when posting code. I have edited it for you this time.

Your code will try to place a trade every tick, that is not good.

Buy orders are executed at Ask, Sells at Bid.

 
Keith Watford:

Please use the insert code button (Alt + S) when posting code. I have edited it for you this time.

Your code will try to place a trade every tick, that is not good.

Buy orders are executed at Ask, Sells at Bid.

thanks Watford, I  will use insert code next time, and use Buy at Ask, Sell at Bid, 

still, what's the problem of error 138, even I just do one ordersend, still got problem 138

 
zeeyeetee:

thanks Watford, I  will use insert code next time, and use Buy at Ask, Sell at Bid, 

still, what's the problem of error 138, even I just do one ordersend, still got problem 138

Please don't refer to me by my surname, it is not very polite

 
use  Ask  for OP buy
Bid  for OP sell
 
Keith Watford:

Please don't refer to me by my surname, it is not very polite

got it, thanks Keith

 
Bambang Sugianto:
use  Ask  for OP buy
Bid  for OP sell

I corrected it  as your instruction, but still get error 138