如何在特定时间启动策略?
How to start a strategy at a specific time?
我正在尝试我的第一个 hello world pine 脚本,其中包含一个非常基本的策略测试:
在市场收盘时开单,在市场开盘时关闭订单。
我目前的尝试:
//@version=4
strategy(title = "Hour Purchasing", shorttitle = "HP",calc_on_every_tick=true, overlay = true, initial_capital = 20000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value = 0.025)
triggerLong = true
triggerStopLong = true
initialHour = 16
x = if (minute == 00 and hour == initialHour)
label = label.new(bar_index,high,text=tostring(hour)+":"+tostring(minute))
triggerLong := true
else
triggerLong := false
y = if (minute==00 and hour==8)
label2 = label.new(bar_index,high,text=tostring(hour)+":"+tostring(minute))
triggerStopLong := true
else
triggerStopLong := false
strategy.entry("Open Long", strategy.long, when = triggerLong)
strategy.close("Open Long", when =triggerStopLong,comment="Exit Long")
问题是,因为该策略是在蜡烛收盘时应用的,所以这只会在 下一个 蜡烛上打开策略(例如,如果我在第 5 分钟,它将在整点过 5 点打开它,如果我在 30 分钟,它会在预计时间过后 30 分钟打开。
我怎样才能让它在蜡烛开盘而不是蜡烛收盘时执行策略?
也许 strategy 中的 process_orders_on_close
可以提供帮助:
strategy(title = "Hour Purchasing", ..., process_orders_on_close = true ...)
我正在尝试我的第一个 hello world pine 脚本,其中包含一个非常基本的策略测试: 在市场收盘时开单,在市场开盘时关闭订单。
我目前的尝试:
//@version=4
strategy(title = "Hour Purchasing", shorttitle = "HP",calc_on_every_tick=true, overlay = true, initial_capital = 20000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value = 0.025)
triggerLong = true
triggerStopLong = true
initialHour = 16
x = if (minute == 00 and hour == initialHour)
label = label.new(bar_index,high,text=tostring(hour)+":"+tostring(minute))
triggerLong := true
else
triggerLong := false
y = if (minute==00 and hour==8)
label2 = label.new(bar_index,high,text=tostring(hour)+":"+tostring(minute))
triggerStopLong := true
else
triggerStopLong := false
strategy.entry("Open Long", strategy.long, when = triggerLong)
strategy.close("Open Long", when =triggerStopLong,comment="Exit Long")
问题是,因为该策略是在蜡烛收盘时应用的,所以这只会在 下一个 蜡烛上打开策略(例如,如果我在第 5 分钟,它将在整点过 5 点打开它,如果我在 30 分钟,它会在预计时间过后 30 分钟打开。
我怎样才能让它在蜡烛开盘而不是蜡烛收盘时执行策略?
也许 strategy 中的 process_orders_on_close
可以提供帮助:
strategy(title = "Hour Purchasing", ..., process_orders_on_close = true ...)