繁体   English   中英

当不再满足条件时,我的 pinescript 策略不会取消进入和退出订单

[英]My pinescript strategy does not cancel the entry & exit orders when the conditions are no longer met

我正在尝试创建一个简单的 inside bar 突破策略,它找到一个 inside bar,然后在 inside bar 的高点进入多头,并在 inside bar 之前的蜡烛的高点获利。 止损位于 inside bar 的低点。 问题是,如果紧随 inside bar 之后的 bar 没有触发入场(没有触及 inside bar 的高点),策略订单应该取消。 取而代之的是,在创建 inside bar 之后,该条目被激活了多个蜡烛,这使得交易过时了。 例子

这是我的代码片段:(我期望如果有超过 1 个蜡烛或条超过内部条条件,则取消所有订单的策略)

strategy("Inisde Bar Breakout", overlay=true, initial_capital=10000, default_qty_value=10, default_qty_type=strategy.percent_of_equity, calc_on_every_tick=true, process_orders_on_close=false)

LongCondition = high < high[1] and low > low[1]
BarsPast = ta.barssince(LongCondition)
timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)
if (timePeriod and LongCondition and BarsPast<2)
    strategy.entry("long", strategy.long, stop=high, limit=high)
    strategy.exit("exit", "long", stop=low, limit=high[1])
    if(BarsPast>1)
        strategy.cancel_all()

为了调用strategy.cancel_all() ,首先(timePeriod and LongCondition and BarsPast<2)必须为true ,然后(BarsPast>1)必须为true

您看,为了达到if(BarsPast>1)LongCondition必须为true

你想搬家

if(BarsPast>1)
        strategy.cancel_all()

在该父 if 块之外。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM