通过input.bool排除新闻交易日。

huangapple go评论56阅读模式
英文:

Exclude Newstrading Days via input.bool

问题

这是我的代码:

FilterNewsTrading = input.bool(defval=false,title='过滤新闻交易')

no_trade_day_dec22 = (year == 2022) and (month == 12) and (dayofmonth == 13) or (dayofmonth == 14) or (dayofmonth == 2)// 13.12.2022 消费者价格指数 // 14.12.2022 利率 // 02.12.2022 非农就业人口统计
no_trade_day_jan23 = (year == 2023) and (month == 01) and (dayofmonth == 12) or (dayofmonth == 06) // 12.01.23 消费者价格指数 // 06.01.2023 非农就业人口统计
no_trade_day_feb23 = (year == 2023) and (month == 02) and (dayofmonth == 01) or (dayofmonth == 03) // 01.02.23 利率 // 03.02.2023 非农就业人口统计
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="进入多头")

所以,这个想法是有一个简单的复选框,您可以选择是否排除日期,以查看我的权益曲线如何变化。不幸的是,它没有起作用。有人知道我犯了什么错误吗?

英文:

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?

答案1

得分: 0

你正在检查你的“非交易日”在一个na()函数中。该函数仅用于测试某些东西是否为na

你应该这样做:

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")

我有点颠倒了你的逻辑。

在这里,我使用了or操作符将你的不交易条件(no_trade_day_dec22 or no_trade_day_jan23 or no_trade_day_feb23)连接起来。因此,如果当前柱子在这些日期中的任何一个上,它将返回true

如果复选框未启用,由于末尾的: falseNewsExcluded将为false

然后在你的if条件中,我已经改成了not NewsExcluded

如果复选框启用并且某一天是这些日期中的一天,NewsExcluded将为true,并且语句not NewsExcluded将为false,防止strategy.entry()调用。

如果复选框未启用,NewsExcluded将为false,并且语句not NewsExcluded将为true。在这种情况下,取决于其他条件(inDateRange and LongEntry)。

英文:

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).

huangapple
  • 本文由 发表于 2023年2月8日 22:51:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定