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

发布于 2025-01-13 20:09:16 字数 1494 浏览 3 评论 0原文

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

这是我基于 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 策略如下所示: 输入图片此处描述

I've been trying for the build backtest strategy. How can i complete this trade and ignoring any new signals?

This my code based on 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

My bakctest strategy looks like this:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2025-01-20 20:09:16

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

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)

You can check your position size when a new signal is given and make sure you are not in a trade if you wish for a trade to finish before taking a new one.

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文