Attachments forums

List of attachments posted on this forum.


All files on forums: 135724

Re: Simple Expert Advisors (EA's) for MT4

nickbyniel1541, Mon Nov 01, 2021 4:34 am

Good afternoon guys - plz see the above gif file. This is a simple EA I'm working on that places a pending order when price gets back into the BBands. If possible, can some explain to me what I am doing wrong. I want the pending trade placed without the SL and TP. Only when the trade becomes active do I want the trade to be modified and the stops added. mrtools or anyone else can you plz point me in the right direction....thanks very much in advance.

Here is the code for the pending function

Code: Select all

void TradeStart(int orderType){

   double candleHigh1 = iHigh(Symbol(), Period(), 1);
   double candleLow1 = iLow(Symbol(), Period(), 1);
   datetime candleExperation = iTime(Symbol(), Period(), 0)+PeriodSeconds() - 1;

   int i = 0;
   //---determine if we are buying or selling 
   double price = candleLow1 - 3*pips;
   double sl = 0, tp = 0;
   if(orderType == OP_BUYSTOP) price = candleHigh1 + 3*pips;
   
   int err = 0;
   int  TicketNumber = OrderSend(Symbol(),orderType,LotSize,price,Slippage,0,0," ",
                       MagicNumber,0,clrGreen);
   if(TicketNumber == -1)
   {
      err = GetLastError();
      Print("Could not place the order due to error ",err," ",ErrorDescription(err));
      if(err == ERR_TRADE_NOT_ALLOWED)Alert("YOU NEED TO ENABLE YOUR AUTOTRADING BUTTON!");
   }
   else//If we are able to select an order
   {   
      if(!OrderSelect(TicketNumber,SELECT_BY_TICKET))
      {
      err = GetLastError();
      Print("Could not select the order due to error ",err," ",ErrorDescription(err));
      }
      else//If we are able to select an order
      {
         double priceOpen = OrderOpenPrice();
         sl = priceOpen + (Stoploss*pips);
         tp = priceOpen - (Takeprofit*pips);
         if(OrderType() == OP_BUYSTOP){
            sl = priceOpen - (Stoploss*pips);
            tp = priceOpen + (Takeprofit*pips);   
         }
         if(!OrderModify(TicketNumber, price, sl, tp, 0, clrGreen))
         {
            err = GetLastError();
            Print("Could not modify the order due to error ",err," ",ErrorDescription(err));
         }         
      }
   }         
}
All files in topic