如何在特定时间启动策略? [英] How to start a strategy at a specific time?

查看:50
本文介绍了如何在特定时间启动策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试我的第一个 hello world pine 脚本,并进行了一个非常基本的策略测试:开市平仓单,开市平仓单.

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.

我目前的尝试:

//@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 分钟).

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?

推荐答案

也许 process_orders_on_close策略 可以提供帮助:

Maybe process_orders_on_close in the strategy can help:

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

这篇关于如何在特定时间启动策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆