1

我是 stackoverflow 的新手,并且有一些编码经验。我的交易算法在我的止损被击中后直接重新进入交易时遇到问题。我想添加一个变量来延迟一定数量的柱的交易重新进入,即使条件得到满足。我尝试了很多不同的事情,但我被困住了。任何帮助将不胜感激。

谢谢,罗伯

4

1 回答 1

0

此伪代码是如何延迟您的交易进入的示例。

//@version=5
indicator("Trade reentry", overlay=true)

var bool    canEnterNewTrade    = true
var bool    enterTradeCondition = true
var bool    stopLossHit         = true
var bool    tradeActive         = false
var int     stopLossBar         = 0
var int     delayInBars         = 20

canEnterNewTrade := not tradeActive and (bar_index - stopLossBar) >= delayInBars

if canEnterNewTrade and enterTradeCondition
    tradeActive := true // enter the trade

if stopLossHit
    stopLossBar := bar_index
    tradeActive := false // exit the trade

plot(na)
于 2022-01-15T16:55:26.377 回答