英文:
Need Help / How to open only one trade per session?
问题
我正在寻找解决方案,以解决我的策略问题。我想每个会话仅开立一次做多头寸和一次做空头寸。我的会话时间框架如下。
sessionZone = input.string("GMT+1", title="Session time zone")
inSession = InSession(sessionTime, sessionZone) and timeframe.isintraday
sessionStart = inSession and not inSession[1]
SessionEnd = inSession[1] and not inSession
因此,每天不应该有超过两次新的开仓(1做多头寸/1做空头寸)。有任何想法吗?
英文:
I'm looking for a solution to my strategy. I want to open only one strategy.entry long and one strategy.entry short per session. The timeframe of my session looks like this.
sessionTime = input.session("0015-2245", title="Session time")
sessionZone = input.string("GMT+1", title="Session time zone")
inSession = InSession(sessionTime, sessionZone) and timeframe.isintraday
sessionStart = inSession and not inSession[1]
SessionEnd = inSession[1] and not inSession
So there shouldn't be more than two new entries (1long Max/ 1Short Max) per day. Any ideas?
答案1
得分: 0
以下是翻译好的部分:
有几种方法可以实现这一点。
一个示例是使用 var
变量来检查您是否在同一个会话中已经输入。然后,当进入新会话时,应将其重置。
var entered_before = false
entered_before := sessionStart ? false : entered_before // 如果是新会话,则重置变量。否则保持其值
if (entry_condition and not entered_before)
strategy.entry()
entered_before := true
当然,您需要两个这样的变量(一个用于做多,一个用于做空)。
另一个想法是将最后一次交易的 strategy.opentrades.entry_bar_index
与 ta.barssince(sessionStart)
进行比较。如果 strategy.opentrades.entry_bar_index
小于 ta.barssince(sessionStart)
,那么您就知道该交易发生在当前会话中。
英文:
There are several ways of achieving this.
One example would be using a var
variable to check whether you have entered before in the same session. You should then reset this when it is a new session.
var entered_before = false
entered_before := sessionStart ? false : entered_before // If it is a new session, reset the variable. Keep its value otherwise
if (entry_condition and not entered_before)
strategy.entry()
entered_before := true
Of course, you need two of these variables (one for short and one for long).
Another idea would be to compare strategy.opentrades.entry_bar_index
of the last trade with ta.barssince(sessionStart)
. If strategy.opentrades.entry_bar_index
is less than ta.barssince(sessionStart)
, you would know that that entry took place in the current session.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论