How to start a strategy at a specific time?

女生的网名这么多〃 提交于 2021-01-07 06:34:56

问题


I am trying out my first hello world pine script, with a very basic strategy test: Open order on market close, close order on market open.

My current attempt:

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

The problem is that because the strategy is applied on candle close, this will only open the strategy on the next candle (e.g. if I'm on the 5 minute it will open it at 5 past the hour, if I'm on the 30 min it will open 30 minutes past the expected hour).

How can I make this execute the strategy on candle open rather than candle close?


回答1:


Maybe process_orders_on_close in the strategy can help:

strategy(title = "Hour Purchasing", ..., process_orders_on_close = true ...)


来源:https://stackoverflow.com/questions/64949433/how-to-start-a-strategy-at-a-specific-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!