zoop Posted March 31, 2010 Report Share Posted March 31, 2010 is there a simple way to add delay time after each buy /sell close ? after close, sleep for X seconds thanks, zoop Quote Link to comment Share on other sites More sharing options...
chrisbenjy Posted July 30, 2010 Report Share Posted July 30, 2010 (edited) 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 July 30, 2010 by chrisbenjy zoop 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.