How to check 'Market is closed' befor opening a position? - page 2

 
Dominik Egert #:

Welcome.


here some Instructions on how to use the function:

But then… if trade will be allowed after above code… and the EA will open trades ONLY at newbar… if you miss first tick… it will not be a new bar anymore… I have the same issue with my EA… as I am only trading daily timeframe… so I can’t trade on newbar because market will not allow at 00:00… … so I use a timer I disabled the newbar function… and I use a timer start at 23:50 and stop at 23:52… the spreads after midnight are crazy anyway 
 

Forum on trading, automated trading systems and testing trading strategies

How to find the Friday's market closing time?

Alain Verleyen, 2016.12.22 18:44

And even the code I used :

   datetime from,to;
   uint session=0;

   while(SymbolInfoSessionQuote(_Symbol,FRIDAY,session,from,to))
     {
      printf("Quoting session %i start %02i:%02i to %02i:%02i",session,from/3600,(from%3600)/60,to/3600,(to%3600)/60);
      session++;
     }

   session=0;
   while(SymbolInfoSessionTrade(_Symbol,FRIDAY,session,from,to))
     {
      printf("Trading session %i start %02i:%02i to %02i:%02i",session,from/3600,(from%3600)/60,to/3600,(to%3600)/60);
      session++;
     }
So please don't come here talking about quality, when you have just posted rudeness and self-promoting.

A lot has already been asked and answered, please use the search engine before posting.

 
I suppose, after reading the other thread, the issue seems to be the shift between market times on chart and session hours given for 'a day' of the week.

There would need to be some sync between these two, most probable given by time zone.

Additionally, as far as I understand, the shift between the own Timezone to the Timezone of the opening of the Marktes.

Then there will be additionally an offset between the openings if forex as given by some timestamp on Sundays to Mondays, depending on where the broker resides and what he understands as a reference for the values they have configured on their symbol definition.

Carl Schreiber wrote a good article concerning market and session times.



 
Dominik Egert #:
I suppose, after reading the other thread, the issue seems to be the shift between market times on chart and session hours given for 'a day' of the week.

There would need to be some sync between these two, most probable given by time zone.

Additionally, as far as I understand, the shift between the own Timezone to the Timezone of the opening of the Marktes.

Then there will be additionally an offset between the openings if forex as given by some timestamp on Sundays to Mondays, depending on where the broker resides and what he understands as a reference for the values they have configured on their symbol definition.

Carl Schreiber wrote a good article concerning market and session times.



I don't get it. What issue about "the shift between market time on chart and session hours" ? There is no shift I am aware of.

I am using the code I posted above on production, on a bunch of brokers and there is no problem.

 
Yes. I mixed up the reference frame...

Reference is session times. There is a shift between the chart time, the tradeserver time (TimeCurrent), which are the same time zone. The opening times of the sessions of different exchanges, New York, London, Sydney, Hong Kong (Asia Session).

So that's what I meant. All in all, it is not safe to say the nightly spread hour will be at the same time on all charts. But they happen globally at the same Time-Point (although this given time window also floats).

So the overall timely allocation given to an EA is not defined inside the session times.

So you have a shift, to be precise, two. One between your location and the chart, and another between the chart and the reference time in UTC. While the UTC and local time are derived from the same source, this could be unreliable. (This was discussed in another thread).

Usually, time is queried inside an EA by the function TimeCurrent, this gives the time of the trading server. This time is directly related to the chart and the session times given by the functios SessionTimes....

This does not give the correlation to the session times of ie London or NY.

And it does not respect your local time.

As far as I understand, this all needs to be paired with the calendar values and their given time zone, to be able to react and exclude news events from your trading.

I notice how complicated these correlations are to handle inside an EA.


 
Dominik Egert #:
Yes. I mixed up the reference frame...

Reference is session times. There is a shift between the chart time, the tradeserver time (TimeCurrent), which are the same time zone. The opening times of the sessions of different exchanges, New York, London, Sydney, Hong Kong (Asia Session).

So that's what I meant. All in all, it is not safe to say the nightly spread hour will be at the same time on all charts. But they happen globally at the same Time-Point (although this given time window also floats).

So the overall timely allocation given to an EA is not defined inside the session times.

So you have a shift, to be precise, two. One between your location and the chart, and another between the chart and the reference time in UTC. While the UTC and local time are derived from the same source, this could be unreliable. (This was discussed in another thread).

Usually, time is queried inside an EA by the function TimeCurrent, this gives the time of the trading server. This time is directly related to the chart and the session times given by the functios SessionTimes....

This does not give the correlation to the session times of ie London or NY.

And it does not respect your local time.

As far as I understand, this all needs to be paired with the calendar values and their given time zone, to be able to react and exclude news events from your trading.

I notice how complicated these correlations are to handle inside an EA.


You are creating problems by yourself. The local time has nothing to do with all of that. The chart time, the server time, the session time (as reported by SymbolInfoSessionTrade) are all the same time. There is no problem.

I have no idea why you talk about Exchange sessions and calendar in this topic, but :

The chart/broker/server time is known, the London/New-York/Sydney are known, it's trivial to go from one to the other.

A calendar time is known, say GMT, it's not complicated to calculated it according to the GMT shift of the broker which is easy to calculate.

There is only one real difficulties it's when you need to place an event in history, because DST is at play and it's not possible to get DST by code, you need to know it broker by broker, server by server.

 
turfu22 #:

Sometimes the candle doesn't close when they said it would with SymbolInfoSessionTrade() .

During my backtesting I had a friday candle close at 18:47 but SymbolInfoSessionTrade() said 23:58 was the end of the session.

I only use server time TimeCurrent() in my code to get Datetime informations.

That's because there is no history data for sessions, the values you get with SymbolInfoSessionTrade() are the current ones, but the history data (OHLC or ticks) can have been recorded when the sessions were different.

If SymbolInfoSessionTrade() indicate an open market while it's actually closed as in your case, there is no problem as you will not have ticks.

If SymbolInfoSessionTrade() indicate a close market, then don't try to open trade even if there are ticks. If you try nonetheless, deal with it by processing the error.

TimeCurrent() doesn't say anything by itself.

 
Dominik Christian Egert #:

Here is my function to solve the issue:


I implemented your code into my EA and it works great - thank you. This code is only for long positions and I am struggling to implement it for short positions as well, can you please help with the code for short position as well. Will be much appreciated.

 

From and to time that we get through SymbolInfoSessionTrade is based on server-time or GMT.? 

Thanks

 
Daniel Cioca # if you miss first tick… it will not be a new bar anymore… I

Code it correctly.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 (2014)

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

Reason: