Please help me correct this function - page 2

To add comments, please log in or register
Petr Nosek
1553
Petr Nosek  
nicholi shen:
TimeCurrent doesn't count. It returns the last known trade server time which is only updated with a new tick. No tick, no time; thus it is necessary to use timelocal which fetches the PC clock time.
I expressed it in a wrong way. I know that TimeCurrent() doesn't count but it returns the last known server time. But the last server time isn't the same as the last Symbol's tick time. I'm not sure if TimeCurrent() "running" depends on all symbols in the market watch or only on connection to the server. But I'm sure that doesn't depend on chart symbol tick. You can try appended indicator on a "lazy" or closed symbol and you can see that server time is running without tick. But if the terminal looses connection then server time running stops.
#property indicator_chart_window
#property strict

int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   EventKillTimer();
   Comment("");
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }

void OnTimer()
  {
   Comment(StringFormat("Server time: %s\nLocal time: %s\nIs connected: %s",
      TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),
      TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS),
      string(bool(TerminalInfoInteger(TERMINAL_CONNECTED)))));
  }
Alain Verleyen
36693
Alain Verleyen  
Petr Nosek:

If you read OP's code carefully you'll realize I was right. There is ">" not ">="

:-p

Change nothing. We are talking about an additional delay due to the wrong usage of Minute() function. Minute() returns a value between 0 and 59, so the (additional) delay is between 0 and 59.

:-D

Alain Verleyen
36693
Alain Verleyen  
Petr Nosek:
I expressed it in a wrong way. I know that TimeCurrent() doesn't count but it returns the last known server time. But the last server time isn't the same as the last Symbol's tick time. I'm not sure if TimeCurrent() "running" depends on all symbols in the market watch or only on connection to the server. But I'm sure that doesn't depend on chart symbol tick. You can try appended indicator on a "lazy" or closed symbol and you can see that server time is running without tick. But if the terminal looses connection then server time running stops.

nicholishen is right on this one. If you want precision using a timer you need to use local time.

TimeCurrent() is updated (or not) on any symbol in the Market Watch. You can never know in this code if there is only current symbol or 100 symbols available to update TimeCurrent. A timer can run without any new tick, so TimeCurrent() can lag behind.

Petr Nosek
1553
Petr Nosek  
Alain Verleyen:
 

You can never know in this code if there is only current symbol or 100 symbols available to update TimeCurrent.

I absolutely agree with this but in my case I don't have to care about it (my TimeCurrent() runs really fluently)


But you should care about local time change by user. :-p        It was only a joke ;-)

Alain Verleyen
36693
Alain Verleyen  
Petr Nosek:

I absolutely agree with this but in my case I don't have to care about it (my TimeCurrent() runs really fluently)

Of course if you are sure about it, but it's not something to recommend on a public forum.

But you should care about local time change by user. :-p        It was only a joke ;-)

Well there is also the cosmetic ray danger, still searching a solution.
Brijesh Kuttan
68
Brijesh Kuttan  
Alain Verleyen:

Change nothing. We are talking about an additional delay due to the wrong usage of Minute() function. Minute() returns a value between 0 and 59, so the (additional) delay is between 0 and 59.

:-D

Just removed the Minute() .. Works like magic.

Thank You very much :-)

Brijesh Kuttan
68
Brijesh Kuttan  
Petr Nosek:

Why do you add the Minute()? You should use this condition:

But it isn't much reliable way to delete pending order. Why don't you use parameter "expiration" in the OrderSend function? If you need to use it this way you should check it in OnTimer instead of OnTick because of "lazy" Symbols.


Thank you for your help... But I run this program on EU during opening and close hours. So I am getting a tick easily in under 10 seconds. 

However I will try to use a function which doesn't trigger on a tick. 

Thank you once again

12
To add comments, please log in or register