完成交易并忽略任何新信号 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在发出新信号时检查您的头寸规模,如果您希望在进行新交易之前完成交易,请确保您没有进行交易。
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.