Я пытаюсь преобразовать эту стратегию в оповещение, чтобы автоматизировать стратегию с 3 запятыми через оповещения.
Я пытался преобразовать стратегию в исследование, но получил ошибку, так как условие включает в себя Strategy.closetrades, которые не допускаются в исследовании.Я не уверен, как это сделать альтернативным способом.
strategy(shorttitle = "Squeeze MOM", title="Squeeze Momentum on Reversal Strategy", overlay=false)
len = input(title="Length", type=integer, defval=14)
th = input(title="threshold", type=integer, defval=20)
TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)
length = input(30, title="BB Length")
mult = input(3.0,title="BB MultFactor")
lengthKC=input(30, title="KC Length")
multKC = input(1.0, title="KC MultFactor")
strength = input(0.0018, title="Reversal Strength")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = ema(source, lengthKC)
range = atr(length)
rangema = ema(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) or (upperBB > upperKC)
highest = highest(high, lengthKC)
lowest = lowest(low, lengthKC)
lastsma = ema(close,lengthKC)
valin = linreg(source - avg(avg(highest, lowest), lastsma), lengthKC,0)
bcolor = iff( valin > 0, iff( valin > nz(valin[1]), lime, green), iff( valin < nz(valin[1]), red, maroon))
scolor = sqzOn ? black : gray
plot(valin, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=circles, linewidth=2)
longcondition = valin > strength and valin > nz(valin[1]) and DIPlus > DIMinus and DX > 15 and strategy.closedtrades < 1000 and (sqzOn[1] or sqzOn[2]or sqzOn[3] or sqzOn[4]) // line become maroon
shortcondition = valin < strength and valin < nz(valin[1]) and DIPlus < DIMinus and DX > 15 and strategy.closedtrades < 1000 and (sqzOn[1] or sqzOn[2]or sqzOn[3] or sqzOn[4]) // line become green
exitlong = valin < nz(valin[1]) and strategy.closedtrades < 1000
exitshort = valin > nz(valin[1]) and strategy.closedtrades < 1000
if(longcondition)
strategy.entry("BUY", strategy.long, qty = (strategy.equity/(close*1.01)))
strategy.exit("BUY TO COV", "BUY", trail_price = strategy.position_avg_price, trail_offset = (.8*range*100))
strategy.close("BUY", when = exitlong)
if(shortcondition)
strategy.entry("SELL", strategy.short, qty = (strategy.equity/(close*1.01)))
strategy.exit("SELL TO COV", "SELL", trail_price = strategy.position_avg_price, trail_offset = (.8*range*100))
strategy.close("SELL", when = exitshort)