How to delay one candle for openning

 

Hello Guys,

I'm new to MT4 this big family and hope can get some help.

e.g. OCO order was triggered on candle A, if the entering condition fulfilled on candle B,i don't want to enter.If the entering condition still fulfilled on candle C then opening a position.

Could someone give me a help?

Thank you.

 
show us your code and we will try to help you
 

Hi,

Here is the code.

//+------------------------------------------------------------------+
//|                                                      MAuptrend.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

extern double Lots = 0.1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  double Ma20Current, Ma20Previous,Ma500Current, Ma500Previous;
  int cnt, ticket, total;
//----
   
//----
  Ma20Current=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1);
  Ma20Previous=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,2);
  Ma500Current=iMA(NULL,0,500,0,MODE_EMA,PRICE_CLOSE,1);
  Ma500Previous=iMA(NULL,0,500,0,MODE_EMA,PRICE_CLOSE,2);
  
  if(Volume[0]>1 ) return;
   total=OrdersTotal();
   if(total<1) 
     {
     if(Ma20Current>Ma20Previous &&
        Ma500Current>Ma500Previous)
  {
   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask*(1-0.0010),Ask*(1+0.0010),"",12345,0,Green); 
        }
       }
    return(0);   
      }  
  // the end. 
//+------------------------------------------------------------------+
 

first

Volume[0]

is not reliable use

Time[]

instead

second adjust for 4/5 digit & maybe consider to send the order without TP & SL & then use

OrderModify()

now u have to check if there is an open order & what time the order is execute & check the next candle ....

 
  1. int start(){
       static datetime candleB;
       if (Time[0] <= candleB) return;
       :
       ticket=OrderSend(...);
       datetime candleA = Time[0]; candleB = candleA + Period()*60;

  2. if(Volume[0]>1 ) return;
    Volume is unreliable, you can miss ticks. Bars is unreliable (max bars on chart) Always use time.
       static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];

  3.    total=OrdersTotal();
    This makes the EA incompatible with every other including itself on other charts and manual trading.
       total=0;
        for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){  total++; }
    

  4. ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask*(1-0.0010),Ask*(1+0.0010),"",12345,0,Green); 
    Always test return codes
    int ticket = OrderSend(...);
    if (ticket < 0) Alert("OrderSend Failed: ", GetLastError());

  5. EAs must adjust for 4/5 digit brokers, tp, sl, AND slippage. On ECN brokers you must open first and then set stops.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
         */
    }
    :
    ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-10*pips2dbl,Ask+10*pips2dbl,"",12345,0,Green); 

 

Hello nice Guys,

Thank you for your suggestion.But it looks very complex for me.If possible,could you please have a complete code?

Appreciate in advance.

 
sure, y not, here we go
 
MTraderboy:
Thank you for your suggestion.But it looks very complex for me.If possible,could you please have a complete code?
No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.