完成交易并忽略任何新信号 MTF

Complete trade and ignoring any new signals MTF

我一直在尝试构建回测策略。我怎样才能完成这笔交易并忽略任何新信号?

这是我基于 MTF 的代码

long = pos(cond1) == 1 and pos(cond2) == 1
short = pos(cond1) == 0 and pos(cond2) == 0

//////////////////////////////////////////////////////////////////////////////////////////////////

var S_sell = false
var S_buy = false

// Defines Trade Signals
buy = long and not S_sell
sell = short and not S_buy

// turning switches off/on after signal is generated 
if buy
    S_sell := true
    S_buy := false

if sell
    S_sell := false
    S_buy := true


if buy
    strategy.entry('Long Entry', strategy.long)

if sell
    strategy.entry('Short Entry', strategy.short)

///////////////////////////////////////////////////////////////

Long_Entry := buy ? close : Long_Entry[1]
Long_StopLoss := buy ? close - Long_Stop_atr : Long_StopLoss[1]
Long_TakeProfit := buy ? close + Long_Profit_atr : Long_TakeProfit[1]

Short_Entry := sell ? close : Short_Entry[1]
Short_StopLoss := sell ? close + Short_Stop_atr : Short_StopLoss[1]
Short_TakeProfit := sell ? close - Short_Profit_atr : Short_TakeProfit[1]

strategy.exit('Close', 'Long Entry', stop=Long_StopLoss, limit=Long_TakeProfit)
strategy.exit('Close', 'Short Entry', stop=Short_StopLoss, limit=Short_TakeProfit)

longEntry = strategy.position_size <= 0
shortEntry = strategy.position_size >= 0

我的 bakctest 策略是这样的:

您可以在给出新信号时检查您的头寸规模,如果您希望在进行新交易之前完成交易,请确保您没有进行交易。

if buy and strategy.position_size == 0 
    strategy.entry('Long Entry', strategy.long)

if sell and strategy.position_size == 0 
    strategy.entry('Short Entry', strategy.short)