Jump to content

(req) Delaying buy/sell time


zoop

Recommended Posts

  • 3 months later...

Hey Zoop,

 

Try this:

 

//This will stop the EA trading for a specified number of candles after a trade is closed.
void DelayTrades()
{

  for(int i=0; i<OrdersHistoryTotal(); i++)
  {
     if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true) // Browses through the trade history
     {
        if(MagicNumber==OrderMagicNumber() && OrderType() == OP_BUY && OrderSymbol()==Symbol()) //If you dont have a magic number, remove the first part of this statement
        {
           datetime OrderTime = OrderCloseTime(); //Close time of the order
           datetime BarOpenTime = iTime(Symbol(),0,2); // This is the time that the candle opened. Change the final value of this function to the number of bars you want it to stop trading for. 
                                                       // Currently if the timeframe is M5 then the EA will stop trading long for 15 minutes.
           
           if(OrderTime>OpenTime)
           {
              StopTradingLong=true; //Declare this boolean at the top and add "&& StopTradingLong=false" to your long trade conditions
           }
           else
           {
              StopTradingLong=false;
           }
        }
        
        if(MagicNumber==OrderMagicNumber() && OrderType() == OP_SELL && OrderSymbol()==Symbol()) //If you dont have a magic number, remove the first part of this statement
        {
           datetime OrderTime2 = OrderCloseTime(); //Close time of the order
           datetime BarOpenTime2 = iTime(Symbol(),0,0); // This is the time that the bar opens. Change the final value of this function to the number of bars you want it to stop trading for
           
           if(OrderTime2>OpenTime2)
           {
              StopTradingShort=true; //Declare this boolean at the top and add "&& StopTradingShort=false" to your short trade conditions
           }
           else
           {
              StopTradingShort=false;
           }
        }
}

 

Take some time to read and understand the code. I have tried to comment the code as well as I can.

 

Chris :)

 

Edit: There seems to be a problem with the scrolling in the code tags so it has split long lines in half so it can fit on the screen. If you copy and paste the code then you may need to rejoin some of the lines

Edited by chrisbenjy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...