[英]can anyone explain to me why the strategy.entry function is not executed?
谁能向我解释为什么 strategy.entry function 没有被执行? 这旨在成为一个 pine 脚本,每隔一周购买一次资产并跟踪该资产的积累。 我有以下脚本不会产生任何错误,但它不会输入任何交易或实际保存累积变量。 累积变量在 0 和 1 之间切换,它不会递增。
// This strategy buys the asset displayed on the active chart every
other week.
strategy("Dollar Cost Averaging")
// Set the amount of USD to buy the asset.
investment_amount = 75
// Variable to track accumulation.
float accumulation = 0
// Buy the asset every other week.
if (weekofyear(time) % 2 == 1.0) and (dayofweek(time) == 2.0) and
(hour(time) == 12.0) and (minute(time) == 0.0)
// Buy.
strategy.entry(id = "Buy", direction = strategy.long,
qty=float(investment_amount/close))
// Alternative way of keeping track of the accumulation.
accumulation += float(investment_amount/close)
我尝试查找简单的 DCA 松脚本,但我只找到了基于指标购买的脚本。 我只想每两周购买一次。
您应该使用第 5 版的 pinescript。 要声明一个浮点数,您必须使用值= 0.0,而不是= 0。然后您必须使用'var'来声明并仅在第一次给出一个值。 在您的代码中,您使用:
float accumulation = 0
每个新柱将累积值重置为 0
这是代码:
//@version=5
strategy("Dollar Cost Averaging")
// Set the amount of USD to buy the asset.
investment_amount = 75.0
// Variable to track accumulation.
var accumulation = 0.0
// Buy the asset every other week.
weektoinvest = (weekofyear(time) % 2 == 1) and (dayofweek(time) == 2) and (hour(time) == 12) and (minute(time) == 0)
if weektoinvest
// Buy.
strategy.entry(id = "Buy", direction = strategy.long, qty= investment_amount/close)
// Alternative way of keeping track of the accumulation.
accumulation += investment_amount/close
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.