提问人:Peter 提问时间:11/15/2023 最后编辑:Peter 更新时间:11/15/2023 访问量:15
是否可以在strategy.exit之后立即进入?
Is is possible to entry after strategy.exit immediately?
问:
我想在达到止盈后实现这一点,strategy.exit 关闭当前仓位,并立即开立新仓位。这可能吗?
我尝试了几种不同的方法,但没有奏效。
你有什么建议吗,我该怎么做?
//@version=5 strategy('Test', overlay=true, initial_capital=10000, process_orders_on_close=true, calc_on_every_tick=true)
backtime = input(title='Period', defval=1)
overbought = input(title='RSI Overbought', defval=1)
oversold = input(title='RSI Oversold', defval=1)
takeProfit = input(title='Take Profit', defval=1)
stopLoss = input(title='Stop Loss', defval=1)
showDirection = input(title='Show Direction Trading In', defval=false)
var contract = "Test"
isOversold(k) => xyz
isOverbought(k) => xyz
plotshape(isOverbought(1) and isOverbought(0), style=shape.labeldown, location=location.abovebar, color=color.new(#ff0000, 0)) plotshape(isOversold(1) and isOversold(0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0))
var inOrder2 = false
var inOrder1 = false
if strategy.opentrades == 0
inOrder1 := false
inOrder2 := false
if isOverbought(1) and isOverbought(0) and not inOrder1
inOrder1 := true
inOrder2 := false
quantity = 1
takeProfitPrice = close + takeProfit
stopLossPrice = close - stopLoss
entryPriceToString = str.tostring(close)
quantityToString = str.tostring(quantity)
takeProfitPriceToString = str.tostring(takeProfitPrice)
stopLossPriceToString = str.tostring(stopLossPrice)
strategy.entry('buyOverBought', strategy.long)
strategy.exit('exit', 'buyOverBought', limit=takeProfitPrice, stop=stopLossPrice)
if isOversold(1) and isOversold(0) and not inOrder2
inOrder2 := true
inOrder1 := false
quantity = 1
takeProfitPrice = close - takeProfit
stopLossPrice = close + stopLoss
entryPriceToString = str.tostring(close)
quantityToString = str.tostring(quantity)
takeProfitPriceToString = str.tostring(takeProfitPrice)
stopLossPriceToString = str.tostring(stopLossPrice)
strategy.entry('sellOverSold', strategy.short)
strategy.exit('exit', 'sellOverSold', limit=takeProfitPrice, stop=stopLossPrice)
答:
评论