that's my code:
FilterNewsTrading = input.bool(defval=false,title='Filter Newstrading')
no_trade_day_dec22 = (year == 2022) and (month == 12) and (dayofmonth == 13) or (dayofmonth == 14) or (dayofmonth == 2)// 13.12.2022 CPI // 14.12.2022 Interest Rate // 02.12.2022 NFP
no_trade_day_jan23 = (year == 2023) and (month == 01) and (dayofmonth == 12) or (dayofmonth == 06) // 12.01.23 CPI // 06.01.2023 NFP
no_trade_day_feb23 = (year == 2023) and (month == 02) and (dayofmonth == 01) or (dayofmonth == 03) // 01.02.23 Interest Rate // 03.02.2023 NFP
NewsExcluded = FilterNewsTrading ? not na(no_trade_day_dec22 and no_trade_day_jan23 and no_trade_day_feb23) : true
if (inDateRange and LongEntry and NewsExcluded)
strategy.entry("long", strategy.long, comment="entry long")
So the idea is to have an easy checkbox, where I can select, if the dates should be excluded or not to see, how my equity curve changes. Unfortunately it doesnt work. Does anyone know, where I made a mistake?
You are checking your "no trade day"s in a na()
function. That function is just to test if soemthing is na
or not.
What you should be doing is:
NewsExcluded = FilterNewsTrading ? (no_trade_day_dec22 or no_trade_day_jan23 or no_trade_day_feb23) : false
if (inDateRange and LongEntry and not NewsExcluded)
strategy.entry("long", strategy.long, comment="entry long")
I kinda reversed your logic.
Here, I or
'd your no trade conditions (no_trade_day_dec22 or no_trade_day_jan23 or no_trade_day_feb23)
. So, if the current bar is on any of those days, it will return true
.
If the checkbox is not enabled, NewsExcluded
will be false
due to : false
at the end.
Then in your if condition, I have changed it to not NewsExcluded
.
If the checkbox is enabled and if it is one of those days, NewsExcluded
will be true
and the statement not NewsExcluded
will be false
preventing the strategy.entry()
call.
If the checkbox is disabled, NewsExcluded
will be false
and the statement not NewsExcluded
will be true
. In that case, it is up to the other conditions (inDateRange and LongEntry
).