trading on specific days of the month
Forums › ProRealTime English forum › ProOrder support › trading on specific days of the month
- This topic has 12 replies, 5 voices, and was last updated 6 years ago by
Bel.
-
-
07/30/2019 at 10:00 AM #103770
Hi everyone.
I would kindly ask you for a suggestion to set up trading only on certain dates or days of the week.
I already know and use the “Dayofweek” function and I know how to set the system to operate, for example, only on Friday.
But I would like to ask you how to set up trading only on the first Friday of the month and not on every Friday of the month, especially to have a report of the operations relative only to the first Friday of each month.
Thank you so much for your kind help.GRAZIE, CIAO !
07/30/2019 at 10:28 AM #103775You should use a flag, say TradeOn, and clear it when first launched and when OnMarket.
Add TradeOn to your conditions.
When you spot a month change, Month<>Month[1], set TradeOn.
As soon as you detect Thursday enter your trade and clear TradeOn.
07/30/2019 at 10:31 AM #103776Something a bit like this?
Choose the number of the day of the week you want and the number of the week you want with ChosenDay and ChosenWeek variables.
It’s an indicator but can easily be adapted into a strategy.
12345678910111213141516171819202122chosenday = 5chosenweek = 2if openmonth <> openmonth[1] thennewmonth = 1daytotrade = 0weekflag = 0endifif newmonth and opendayofweek = chosenday thenweekflag = weekflag + 1endifif weekflag = chosenweek and opendayofweek = chosenday thendaytotrade = 1endifif opendayofweek <> chosenday thendaytotrade = 0endifreturn daytotrade07/30/2019 at 11:34 AM #103785I’ve been doing some testing and as an indicator the above works just fine as it uses OPENDAYOFWEEK which is great in an indicator as we are working on the fly with the current forming candle. In a strategy however you have to decide the day before whether to trade tomorrow at the open of the candle so we are supposed to use DAYOFWEEK which returns tomorrows day number. However I was testing on a daily time frame and there are major issues due to PRT’s data switching from 5 day weeks to 6 day weeks at some point around the beginning of 2007. This means that prior to the 2007 data change on a Friday the DAYOFWEEK returns a value of 6 and the next day is a Monday but after the 2007 data change the 6 opens a trade on a Sunday.
It should be simple to code round this with a date filter but the change is not a clean one and there are even some rogue DAYOFWEEK values pre 2007!
We must be careful when using DAYOFWEEK when backtesting if it is involved in any strategy decisions!
07/30/2019 at 11:53 AM #103788It gets even more difficult to understand what a DAYOFWEEK value actually means. If you use it in an indicator then it has the same data problem with the switch from 5 day weeks to 6 day weeks but also returns different values and it can’t decide whether a value of 5 tells us that tomorrow is a Friday or a Sunday or even a Monday if pre 2007!
07/30/2019 at 12:20 PM #10379607/30/2019 at 1:34 PM #103801Hello everyone and thank you so much for your answers.
I also tried some very simple solutions to program and use and reading the PRT manual maybe I found a solution that I would like to share with you and know what you think.
if the month starts right on Friday the “DAY” function will be equal to 1.
if the month starts instead with Saturday the “DAY” function will tell me that the first Friday of the month will be as maximum equal to 7.
in any of these two cases the first Friday of the month must always have a “DAY” value of less than 8.
so if I connect the “DAY” function and the “DAYofWEEK” function I can get:
IF (Day < 8 AND DayOfWeek = 5) THAN ….
if these two conditions are true I will have the indication that it is the first Friday of the month.
what do you think ? can it work?Ciao GRAZIE !07/30/2019 at 1:54 PM #103804This will only buy the first Friday of any month (not tested):
12345678910Once TradeOn = 0If TradeOn = 0 and Not OnMarket ThenIf openmonth <> openmonth[1] ThenTradeOn = 1EndifEndifIf TradeOn and opendayofweek = 4 and MyConditions ThenBuy 1 contract at marketTradeOn = 0Endifedit Tested on DAX 1min and it works as expected, replace 4 with 1 to 5 as needed
07/30/2019 at 1:55 PM #103805You will need to add TP & SL to make it exit.
07/30/2019 at 2:26 PM #103806This will only buy the first Friday of any month
Days Wednesday Thursday and Friday can all be easily coded by checking the previous days OPENDAYOFWEEK value but Monday is a difficult one due to the unclean data due to changes from 5 day to 6 day weeks. In a strategy the OPENDAYOFWEEK before a Monday was 5 when we had 5 day weeks and 7 when we had 6 day weeks but there is also the odd value of 6 thrown in during the change over! The change over seemed to be introduced and then withdrawn and then reintroduced. For Tuesdays there is the issue of holidays – if you are looking for a Tuesday and there was no Monday candle then the OPENDAYOFWEEK for the previous day will be the Friday value of 5.
Far too complicated and makes coding strategies with selective trading days virtually impossible.
The difference between indicator values compared to strategy values also makes everything a bit of a nightmare!
The image shows strategy values for OPENDAYOFWEEK at the top and indicator values for OPENDAYOFWEEK at the bottom during the 2007 switch from 5 day to 6 day weeks.
07/30/2019 at 5:52 PM #103825I coded the following to calculate the exact day of the week using the key value method. I wanted to compare the day calculated from OPENDATE to the OPENDAYOFWEEK returned day. It was a bit of a futile exercise as it just confirmed that the numbers returned by indicators are totally different to those returned by strategies. If we had a crystal ball and could know what the next candle date is going to be on our chart then we could use it to calculate the correct day of the week. I guess We will just have to wait and see if PRT fix the different values between strategies and indicators and see if they can do something about the fact that DAYOFWEEK is pretty useless for auto-trading as it currently is unless you are backtesting on a limited history.
I post the code here just in case anyone wants to know what day their birthday will be on in 2050!! Mine’s a Sunday so that will be nice. 0 = Sunday 1 = Monday, 2 = Tuesday and so on.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061mydate = opendate //or whatever date you want to look forY = round((myDate / 10000) - 0.5)MM = round((myDate - ((Y * 10000))-0.5) /100)DD = round(mydate - (Y * 10000) - (MM * 100)-0.5)C = round((y / 100) - 0.5)YY = y - (c *100)a = round((yy / 4)-0.5)b = a + DDif mm = 1 or mm = 10 thenb = b + 1endifif mm = 2 or mm = 3 or mm = 11 thenb = b + 4endifif mm = 5 thenb = b + 2endifif mm = 6 thenb = b + 5endifif mm = 8 thenb = b + 3endifif mm = 9 or mm = 12 thenb = b + 6endifLeapYear = 0If y mod 4 = 0 thenIf y mod 100 = 0 thenIf y mod 400 = 0 thenLeapYear = 1EndifElseLeapYear = 1EndifEndifif (mm = 1 or mm = 2) and leapyear thenb = b - 1endifif y > 2000 thenb = b + 6endifb = b + yyresult = b mod 7myday = result - 1return myday as "Day of Week"11/28/2019 at 12:35 PM #113836Great insight Vonasi, thanks👍🏽
Also how about buying on specific days lets say on the 11th each month? If Day=11 works but once 11th falls into weekend it stops working. Doing If Day=11 Or Day=12 will open 2 trades on the following days instead of 1 on either day which is not the weekend:/
Regards,
Bel.
11/28/2019 at 12:57 PM #113843 -
AuthorPosts
Find exclusive trading pro-tools on