Trade First Available Tick at Time = 00:00:00

 
Please can anybody help

I would like to have the EA recognize the first available Tick at or after tiem 00:00:00, in backtesting al that is needed is
if (Hour()==0 && Minute()==0 && Seconds()>=00)
But in live trading if the tick does not have the tiem stamp of 00:00:00 this instruction is false
and I would like the first tick at or time stamp of 00:00:00

thanks
 
Please can anybody help

I would like to have the EA recognize the first available Tick at or after tiem 00:00:00, in backtesting al that is needed is
if (Hour()==0 && Minute()==0 && Seconds()>=00)
But in live trading if the tick does not have the tiem stamp of 00:00:00 this instruction is false
and I would like the first tick at or time stamp of 00:00:00

thanks

You are allowing only 60 second window within the 24 hours to get a tick.
That may or may not work since a tick may come in unpredictable time which may be more than 60 second.
So instead of creating a time window, I would rather synchronize time with a tick by saying: Any first tick after 00:00:00 is time stamped 00:00:00.
 
The other question is: Which time zone 00:00 ?

For example Metatrader Demo lives in GMT +2 (Central European Daylight Savings Time), some U.S. brokes have EST on their charts. When dealing with time you'll definitely need to adjust.

I wrote a Pivot indicator which does that, was quite a taks given the fact that there are missing bars, weekends, etc.

Anyway, I ended up looking backwards through all bars until DayOfWeek(Time[i]) changed. So you could do this basically on every timeframe below D1. Look backwards until the day changes and take the open of the bar as the first tick of the day.


Markus
 
Great, any suggestions as to the coding of such an instruction?
 
Something like this:


   int tzdiff= tzlocal,  // eg tzlocal= 2 for GMT +2
       tzdiffsec= tzdiff*3600, 
 
   datetime timet;
   

   //
   // search back from lastbar for the beginning of the day
   //
   strning tday= TimeToStr(Time[lastbar]-tzdiffsec, TIME_DATE);   
   for (  ; lastbar<Bars; lastbar++) {
      if (TimeToStr(Time[lastbar] - tzdiffsec, TIME_DATE)!=tday) {
         lastbar--;
         break;      
      }
   }   

   // lastbar now the first bar of the current day
   double firsttick= Open[lastbar];
 
Shidomax

Thanks again.

Alltough Im looking for something a little diferent, parhaps you can be so kind as to help


I would like my system to perform a given instruction at time 00:00:00 , and if there is no tick at that particular time
then at the first tick past time 00:00:00.


int start()
{
Print("TIEMPO = ",Hour(),":", Minute(),":", Seconds());
if (Hour()==0 && Minute()==0 && Seconds()==0)
{

UNO=LastTrade();
Print("UNO = ",UNO);
for(cnt=0;cnt<ototal;cnt++)
{
...etc

the problem I have here is that if there is no tick at the exact time then nothing will happen, and I want something to happen. So I need it to wait for the firts tick after time = 00:00:00 to perform UNO= LastTrade();

How can I do this?
 
int start()
{
    static string lastdate;
    int tzdiff= TimezoneLocal,  // e.g. tzlocal= 2 for GMT +2  or zero for chart time
        tzdiffsec= tzdiff*3600, 


    string bardate= TimeToStr(Time[0]-tzdiffsec, TIME_DATE);

    if (lastdate=="") {    // init it ... first time only
       lastdate= bardate;
    }

    if (bardate!=lastdate) {
        
        // this part executed on the first tick of the new day.



        // remember date for next tick
        lastdate= bardate;
    }



Start is called on every tick. Through the static string lastdate you'll have a variable that will remember the date from the current bar from the last call. So you can compare the current tick/bar time with the previous one and if the date changes you have a new bar of a new day.

The TimezoneLocal parameter is supposed to correct the server time (e.g. to GMT) when running on an European or U.S. server.



Markus

 
Shimodax

Wouldnt it be better to identify the open of the current D1 bar?
that would occur at the time of the first tick after time 00:00:00?

how can that be incorporated into the code above?

int start()
{
Print("TIEMPO = ",Hour(),":", Minute(),":", Seconds());
if (Hour()==0 && Minute()==0 && Seconds()==0)
{

UNO=LastTrade();
Print("UNO = ",UNO);
for(cnt=0;cnt<ototal;cnt++)
{
...etc


thanks
 
Or Maybe,

buy at open of next day, how can this be programed?
Reason: