Hi everybody,
after the big short candle of today due to the CPI data, I’d like to add in my strategies some lines to avoid any new trade in the period around the news.
For Jobless data it’s easy because the news is always on Thursday all weeks.
But for other news (Payrolls or CPI or RetailSales) that are, for example, only on the 2nd Tuesday of the month what do I have to write?
Which are the instructions to let it know to avoid ONLY the second Tuesday ?
Many thanks for your help
Hi MaoRai,
You could make some sort of loop which traces backwards (to) the 1st day of the month (Month <> Month[1]) and then looks forward for the 2nd Tuesday, starting 1 day further than what you found tracing backwards.
More easy could be to just hard code the dates (see below for a list already there – you can extend it yourself of course).
Regards,
Peter
Hi,
many thanks for your prompt reply.
I’m unable to write the loop. I hope at Roberto or Nicolas will help me in that.
Where did you get the sheet with the various dates of news ?
Hi
You could calculate wich tuesday it is with this code:
if month = month[1] and dayofweek=2 then
numtuesday = 1 + numtuesday
elsif month = month[1] and dayofweek<>2 then
numtuesday = numtuesday
else
numtuesday = 0
endif
I shall be honest … I have been trying for 45 minutes or so, and couldn’t do it in that time.
Then I saw your post, Iván, tried that, but unfortunately that doesn’t do a job either. Now 15 minutes later with your code as a base, I am going to give up and have a beer instead. 😜
To let it work, (please) show a fully working snippet and point (Graph) at the 2nd Tuesdays of the month. Do you need a TimeFrame command, then inject that too.
A strange beast this is !
Hi Ivan,
thanks for your code but I don’t think it’s my request.
I need a code that:
- if the dayofweek=2 and (it is the second Tuesday of the month) and (hour=>14 and hour<=15) THENNoTrade=1
Else
NoTrade=0
ENDIF
- // where notrade=1 means not opening any trade in that day and hours
Hi,
if opendayofweek=2 and openday>=8 and openday<=14 and openhour=14 then
notrade=1
else
notrade=0
endif
return notrade
Sorry, for the hourly part I looked at it as not trading for one hour between 14h and 15h, but it seems you actually meant for 2 hours, not one. Although depending if you used hour in its PRT meaning of candle closing time, or as a word, I am not sure if you meant no trade between 13h and 15h, or between 14h and 16h.
If from 13h to 15h, please replace “and openhour=14 then” in line 1 by “and (openhour=13 or openhour=14) then“
If from 14h to 16h, please replace “and openhour=14 then” in line 1 by “and (openhour=14 or openhour=15) then“
Hi JC – I am sure this is perfect. Very well done. No trading in the hour of PCI data (which comes in at 15:30).
For MaoRai : don’t forget about the Daylight Savings difference between Europe (the area you imply) and the USA (which designates the PCI report at 08:30).
Just in case, about the Daylight Saving :
DLS = 0 // 0 = Normal. 1 = Autumn. 2 = Spring.
If Date >= 20221031 and Date <= 20221104 then
DLS = 1 // Autumn. USA is one hour early.
elsif Date >= 20230312 and Date <= 20230326 then
DLS = 2 // Spring. USA is one hour early.
endif
// Justadd a group for convenience (no difficult If/Else stuff).
// And the above can even be used for more history backtesting.
If Date >= 20231029 and Date <= 20231105 then
DLS = 1 // Autumn. USA is one hour early.
elsif Date >= 20240310 and Date <= 20240331 then
DLS = 2 // Spring. USA is one hour early.
endif
No trading in the hour of PCI data (which comes in at 15:30).
No PeterSt … that is 14:30.