谁能给我解释一下为什么这个策略.输入函数没有执行?



谁能给我解释一下为什么这个策略。输入函数没有执行?这是一个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松脚本,但我只发现基于指标购买的脚本。我只想每两周买一次。

您应该使用pinescript的版本5。要声明浮点数,必须使用值= 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

最新更新