What code can be used to close orders at the end of the next bar period? New comment Jeysun 2010.09.16 08:05 I am trying to write an EA that will close open order at the end of the next bar and have tried the following for the 4hr period: -------------------------------------------------------------------- datetime a = TimeHour(OrderOpenTimeA); string closestringA; datetime closetimeA; if ( a >= 0 && a < 4 ) { closestringA = "7:59"; closetimeA = StrToTime(closestringA) + TimeDay(1); } closetimeA = StrToTime(closestringA); if ( TimeCurrent() >= closetimeA ) {CloseBasketA = True;} ---------------------------------------------------------------------- This code will return the date as a day before the order opens and does not work for any timeframe. There must be an easier/simpler way to code this for any timeframe. I would appreciate any suggestions. How to referrence first 4hr bars for every new day ? How to trigger order on the next bar open (or on current bar close) How to buy on beginning and sell at the end? qjol 2010.09.16 10:45 #1 int TotalBars = 0; //global var if (Bars > TotalBars) { // do......... } TotalBars = Bars; Jeysun 2010.09.19 09:45 #2 qjol: Thanks a bunch, you saved me a lot of time. New comment
I am trying to write an EA that will close open order at the end of the next bar and have tried the following for the 4hr period:
--------------------------------------------------------------------
datetime a = TimeHour(OrderOpenTimeA);
string closestringA;
datetime closetimeA;
if ( a >= 0 && a < 4 )
{
closestringA = "7:59";
closetimeA = StrToTime(closestringA) + TimeDay(1);
}
closetimeA = StrToTime(closestringA);
if ( TimeCurrent() >= closetimeA ) {CloseBasketA = True;}
----------------------------------------------------------------------
This code will return the date as a day before the order opens and does not work for any timeframe.
There must be an easier/simpler way to code this for any timeframe. I would appreciate any suggestions.