如何执行限时订单?
How do you implement a timed limit order?
我想到了这条管道:
1. condition to enter a trade becomes TRUE
2. opens a limit order at a pre-calculated price
3. wait 3 bar closes (or 3 hours, for example. variable.)
4. if the order has not filled, cancel the order
具体来说,步骤3-4如何实现?
您可以使用 built-in strategy.cancel() 函数取消挂起的限价单,检查 3 根柱前的多头条件是否为真并取消订单,以防它被执行 -不会受到影响。
下面的脚本将使用鼠标在图表上单击来触发做多的条件,并为限价单设置给定的 limitValue 并取消订单,以防在接下来的 3 个柱中不会执行:
//@version=5
strategy("My strategy", overlay=true)
itime = input.time(0, confirm = true)
limitValue = math.min(close[1], low[2])
longCondition = time == itime
if longCondition
strategy.entry("MyLong", strategy.long, limit = limitValue)
label.new(bar_index, limitValue, 'Entry Order')
strategy.cancel("MyLong", nz(longCondition[3]))
我想到了这条管道:
1. condition to enter a trade becomes TRUE
2. opens a limit order at a pre-calculated price
3. wait 3 bar closes (or 3 hours, for example. variable.)
4. if the order has not filled, cancel the order
具体来说,步骤3-4如何实现?
您可以使用 built-in strategy.cancel() 函数取消挂起的限价单,检查 3 根柱前的多头条件是否为真并取消订单,以防它被执行 -不会受到影响。
下面的脚本将使用鼠标在图表上单击来触发做多的条件,并为限价单设置给定的 limitValue 并取消订单,以防在接下来的 3 个柱中不会执行:
//@version=5
strategy("My strategy", overlay=true)
itime = input.time(0, confirm = true)
limitValue = math.min(close[1], low[2])
longCondition = time == itime
if longCondition
strategy.entry("MyLong", strategy.long, limit = limitValue)
label.new(bar_index, limitValue, 'Entry Order')
strategy.cancel("MyLong", nz(longCondition[3]))