← Назад к списку файлов

gold smart money flow - cot enhanced.txt

Поиск по коду файла

indicator("Gold Smart Money Flow - COT Enhanced", overlay=false)

length = input.int(20, "Calculation Length", minval=1)
smoothing = input.int(5, "Smoothing Period", minval=1)
volThreshold = input.float(1.8, "Institutional Volume Threshold (Gold)", minval=0.5, step=0.1)
useCOT = input.bool(true, "Show COT Data (Futures Only)")

typicalPrice = hlc3
avgVolume = ta.sma(volume, length)

largeVolume = volume > (avgVolume * volThreshold)
priceChange = close - close[1]

institutionalFlow = 0.0
institutionalFlow := largeVolume ? institutionalFlow[1] + (priceChange * volume) : institutionalFlow[1] * 0.98

closePosition = (close - low) / math.max(high - low, 0.01)
institutionalMF = ta.ema(closePosition * volume * (largeVolume ? 2.5 : 1), length)
institutionalRaw = (institutionalMF - ta.sma(institutionalMF, length * 2)) / math.max(ta.stdev(institutionalMF, length), 1)
institutionalLine = ta.sma(institutionalRaw, smoothing)

rsi = ta.rsi(close, 14)
retailMomentum = (rsi - 50) / 50

retailVolume = volume > avgVolume * 1.2 and volume < avgVolume * volThreshold
retailFlow = 0.0
retailFlow := retailVolume ? retailFlow[1] + (priceChange * volume * 0.6) : retailFlow[1] * 0.95

macdLine = ta.ema(close, 12) - ta.ema(close, 26)
macdSignal = ta.ema(macdLine, 9)
retailMacd = (macdLine - macdSignal) / close * 10000

retailRaw = (retailMomentum + retailMacd) / 2
retailLine = ta.sma(retailRaw, smoothing)

cotCommercial = request.security("CFTC:088691_FO_L_ALL", "W", close, gaps=barmerge.gaps_on, ignore_invalid_symbol=true)
cotLargeSpec = request.security("CFTC:088691_F_L_ALL", "W", close, gaps=barmerge.gaps_on, ignore_invalid_symbol=true)
cotSmallSpec = request.security("CFTC:088691_FO_L_ALL_CR", "W", close, gaps=barmerge.gaps_on, ignore_invalid_symbol=true)

cotInstitutional = 0.0
cotRetail = 0.0

if useCOT
    if not na(cotCommercial)
        cotInstitutional := ta.sma((cotCommercial - ta.sma(cotCommercial, 52)) / math.max(ta.stdev(cotCommercial, 52), 1), 4)
    if not na(cotSmallSpec)
        cotRetail := ta.sma((cotSmallSpec - ta.sma(cotSmallSpec, 52)) / math.max(ta.stdev(cotSmallSpec, 52), 1), 4)

finalInstitutional = (useCOT and not na(cotInstitutional) and cotInstitutional != 0) ? (institutionalLine * 0.7 + cotInstitutional * 0.3) : institutionalLine
finalRetail = (useCOT and not na(cotRetail) and cotRetail != 0) ? (retailLine * 0.7 + cotRetail * 0.3) : retailLine

plot(finalInstitutional, "Institutional / Commercial", color=color.new(color.red, 0), linewidth=3)
plot(finalRetail, "Retail / Small Specs", color=color.new(#00CED1, 0), linewidth=3)

hline(0, "Zero", color=color.gray, linestyle=hline.style_solid, linewidth=2)
hline(1, "Strong Bullish", color=color.new(color.green, 70), linestyle=hline.style_dashed)
hline(-1, "Strong Bearish", color=color.new(color.red, 70), linestyle=hline.style_dashed)

bgColor = finalInstitutional > finalRetail ? color.new(color.red, 94) : color.new(#00CED1, 94)
bgcolor(bgColor, title="Dominant Money")

crossOver = ta.crossover(finalInstitutional, finalRetail)
crossUnder = ta.crossunder(finalInstitutional, finalRetail)

plotshape(crossOver, "Institutional Takeover", shape.triangleup, location.bottom, color.red, text="INST", size=size.small)
plotshape(crossUnder, "Retail Takeover", shape.triangledown, location.top, color.aqua, text="RETAIL", size=size.small)

extremeDivergence = (finalInstitutional > 1 and finalRetail < -0.5) or (finalInstitutional < -1 and finalRetail > 0.5)
plotshape(extremeDivergence, "Extreme Divergence", shape.diamond, location.absolute, color.yell

Показано первые 50% кода (символов: 6215)

Как получить полную версию?

Введите ваш email и нажмите кнопку, чтобы перейти к оплате.