簡體   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