Hi Nicolas,
Trying to see if I can figure out what happens on weekend gaps? Battling to define the Friday close and Monday open. Want to use it in a hourly timeframe as a filter to either trade the Monday or not depending on the gap…
Timeframe(daily,updateonclose)
If dayofweek = 5 Then
gapclose = close
Elsif dayofweek = 1 Then
gapopen = open
Endif
If dayofweek = 1 Then
If (gapopen-gapclose)>100 Then
gapweekup=1
Else
gapweekup=0
Endif
Endif
Timeframe(default)
If gapweekup=1 and Average[5](close) crosses under Average[15](close) Then
Sellshort 1 contract at market
Endif
SET STOP pLOSS 100
SET TARGET pPROFIT 100
Strategy code is run at the close of a candle so with UPDATEONCLOSE your strategy cannot know until the close of a daily candle what the open value was for that candle – so you will need to use a faster time frame or DEFAULT if you want to catch the Monday opening price and place orders based on it at the market open.
Thanks Vonasi,
I tried the following on the hourly tf…but it does not register the Friday close and Monday open correctly any suggestions?
If dayofweek = 5 and time = 230000 Then
gapclose = close
Elsif dayofweek = 1 and time = 10000 Then
gapopen = open
Endif
If dayofweek = 1 and time = 10000 Then
If (gapopen-gapclose)>100 Then
gapweekup=1
Else
gapweekup=0
Endif
Endif
Not to worry figured it out should be 20000…
A candle can be identified by two reference times.
TIME = the closing time of the candle (which is also the same as the opening time of the following candle).
OPENTIME = the opening time of the candle (which is also the same as the closing time of the previous candle).
So the hourly candle that opens at 010000 will close at 020000 and can be referenced as either OPENTIME = 010000 or TIME = 020000
It is similar with OPENDAYOFWEEK and DAYOFWEEK.
Hi Vonasi, thought I had did but I just don’t seem to get it right for the code to take the close on a Friday at 230000 and compare it to the open on the Monday at 10000. Any suggestions either as a indicator or strategy on a hourly timeframe?
If you add this indicator to your chart it can help to clarify things:
return opendayofweek as "opendayofweek", dayofweek as "dayofweek", time as "time", opentime as "opentime"
It would appear that the candle that closes at 010000 is classified as opening at 000000 on Sunday. So you should be looking for dayofweek = 0 and time = 10000.