Working on SuperTrend Fusion Pro — Trend + Momentum + VWAP + CVD and I am getting red error on this Part of the code .............................def vwapVal = vwap("time frame" = VWAPPeriod); can someone help?
Code:
##########################################################
# SuperTrend Fusion Pro — Trend + Momentum + VWAP + CVD
# Author: Adapted for TOS
##########################################################
declare upper;
############################
# INPUTS
############################
input atrLength = 10;
input factor = 3.0;
input emaLength = 34;
input useEMAFilter = yes;
input chopLength = 14;
input chopThreshold = 50;
input useChop = yes;
input cvdLength = 14;
input cvdSmooth = 8;
input useCVDFilter = yes;
input VWAPPeriod = AggregationPeriod.DAY;
input useVWAPFilter = yes;
############################
# PRICE
############################
def hl2 = (high + low) / 2;
############################
# EMA
############################
def ema = ExpAverage(close, emaLength);
############################
# SUPERTREND
############################
def atr = Average(TrueRange(high, close, low), atrLength);
def upperBasic = hl2 + factor * atr;
def lowerBasic = hl2 - factor * atr;
def upperBand = CompoundValue(1,
if upperBasic < upperBand[1] or close[1] > upperBand[1]
then upperBasic
else upperBand[1],
upperBasic);
def lowerBand = CompoundValue(1,
if lowerBasic > lowerBand[1] or close[1] < lowerBand[1]
then lowerBasic
else lowerBand[1],
lowerBasic);
def trend = CompoundValue(1,
if close > upperBand[1] then 1
else if close < lowerBand[1] then -1
else trend[1],
1);
def superTrend = if trend == 1 then lowerBand else upperBand;
def rawLongFlip = trend == 1 and trend[1] == -1;
def rawShortFlip = trend == -1 and trend[1] == 1;
############################
# CHOPPINESS INDEX
############################
def highestChop = Highest(high, chopLength);
def lowestChop = Lowest(low, chopLength);
def rangeChop = highestChop - lowestChop;
def trSum = Sum(TrueRange(high, close, low), chopLength);
def chop =
if rangeChop != 0
then 100 * Log(trSum / rangeChop) / Log(chopLength)
else 100;
def marketTrending = chop < chopThreshold;
############################
# CUMULATIVE VOLUME DELTA (CVD)
############################
def upperWick = if close > open then high - close else high - open;
def lowerWick = if close > open then open - low else close - low;
def spread = high - low;
def bodyLen = spread - (upperWick + lowerWick);
def buyingVol = if close > open then (bodyLen + (upperWick + lowerWick) / 2) * volume else ((upperWick + lowerWick) / 2) * volume;
def sellingVol = if close < open then (bodyLen + (upperWick + lowerWick) / 2) * volume else ((upperWick + lowerWick) / 2) * volume;
def cumBuying = ExpAverage(buyingVol, cvdLength);
def cumSelling = ExpAverage(sellingVol, cvdLength);
def cvdEMA = ExpAverage(cumBuying - cumSelling, cvdSmooth);
def cvdBull = cvdEMA > cvdEMA[1];
def cvdBear = cvdEMA < cvdEMA[1];
############################
# DAILY VWAP
############################
def vwapVal = vwap("time frame" = VWAPPeriod);
def vwapBull = close > vwapVal;
def vwapBear = close < vwapVal;
############################
# FINAL SIGNALS
############################
def longCondition =
rawLongFlip and
(!useEMAFilter or close > ema) and
(!useVWAPFilter or vwapBull) and
(!useChop or marketTrending) and
(!useCVDFilter or cvdBull);
def shortCondition =
rawShortFlip and
(!useEMAFilter or close < ema) and
(!useVWAPFilter or vwapBear) and
(!useChop or marketTrending) and
(!useCVDFilter or cvdBear);
############################
# PLOTS
############################
plot ST = superTrend;
ST.AssignValueColor(if trend == 1 then Color.CYAN else Color.ORANGE);
ST.SetLineWeight(2);
plot BuyArrow = if longCondition then low - 2 * TickSize() else Double.NaN;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.CYAN);
BuyArrow.SetLineWeight(3);
plot SellArrow = if shortCondition then high + 2 * TickSize() else Double.NaN;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.ORANGE);
SellArrow.SetLineWeight(3);
AssignPriceColor(
if longCondition then Color.CYAN
else if shortCondition then Color.ORANGE
else Color.GRAY
);
=======================================
Converting from ;
https://www.tradingview.com/script/Qe9aWBlF-SuperTrend-Fusion-Trend-Momentum-Volatility-Filter/
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoTrade_Pro
// This script includes an adapted Average Force function originally published as open-source on TradingView by its author - racer8
//@version=6
indicator("SuperTrend Fusion — ATP", overlay = true, timeframe = "", timeframe_gaps = true)
//──────────────────────────
// INPUTS
//──────────────────────────
// 1) SuperTrend – Trend component
var g_trend = "SuperTrend – Trend"
atrPeriod = input.int(10, "ATR Length", minval = 1, group = g_trend)
factor = input.float(3, "Factor", minval = 0.01, step = 0.01, group = g_trend)
// 2) Average Force – Momentum filter
var g_mom = "Average Force – Momentum"
useAfFilter = input.bool(true, "Use AF Filter", group = g_mom)
afPeriod = input.int(18, "AF Period", minval = 1, group = g_mom)
afSmooth = input.int(6, "AF Smooth", minval = 1, group = g_mom)
// 3) Choppiness Index – Volatility / trend filter
var g_chop = "Choppiness Index – Volatility"
useChopFilter = input.bool(true, "Use Chop Filter", group = g_chop)
chopLength = input.int(14, "Chop Length", minval = 1, group = g_chop)
chopThreshold = input.int(50, "Chop Threshold", minval = 1, maxval = 100, group = g_chop)
//──────────────────────────
// CORE CALCULATIONS
//──────────────────────────
// 1) SuperTrend base
[stValue, stDirection] = ta.supertrend(factor, atrPeriod)
isUpTrend = stDirection < 0
isDownTrend = stDirection > 0
// 2) Average Force function
af(src, hi, lo, length, postSmooth) =>
p = math.max(1, int(length))
highestHi = ta.highest(hi, p)
lowestLo = ta.lowest(lo, p)
ranges = highestHi - lowestLo
raw = ranges == 0.0 ? 0.0 : (src - lowestLo) / ranges - 0.5
ta.sma(raw, math.max(1, int(postSmooth)))
afValue = af(close, high, low, afPeriod, afSmooth)
// 3) Choppiness Index
highestHiChop = ta.highest(high, chopLength)
lowestLoChop = ta.lowest(low, chopLength)
rangeChop = highestHiChop - lowestLoChop
choppiness = rangeChop != 0 ? 100 * math.log10(math.sum(ta.atr(1), chopLength) / rangeChop) / math.log10(chopLength) : 100
//──────────────────────────
// FUSION LOGIC
//──────────────────────────
bullMomentum = afValue > 0
bearMomentum = afValue < 0
marketTrending = choppiness < chopThreshold
bullFilterOk = (not useAfFilter or bullMomentum) and (not useChopFilter or marketTrending)
bearFilterOk = (not useAfFilter or bearMomentum) and (not useChopFilter or marketTrending)
rawLongFlip = ta.change(stDirection) < 0
rawShortFlip = ta.change(stDirection) > 0
longCondition = rawLongFlip and bullFilterOk
shortCondition = rawShortFlip and bearFilterOk
rawLongFlipFiltered = rawLongFlip and not longCondition
rawShortFlipFiltered = rawShortFlip and not shortCondition
//──────────────────────────
// VISUAL OUTPUT — SINGLE LINES
//──────────────────────────
// Premium signal colors
longColor = color.new(color.aqua, 0)
shortColor = color.new(color.orange, 0)
// Fusion SuperTrend (bold)
plot(longCondition or shortCondition ? stValue : na, "Fusion Trend",
color = longCondition ? longColor : shortCondition ? shortColor : na,
linewidth = 3, style = plot.style_linebr)
// Base SuperTrend with colors
plot(stValue, "Base SuperTrend",
color = isUpTrend ? color.new(color.aqua, 0) : color.new(color.orange, 0),
style = plot.style_linebr, linewidth = 2)
// Bar colors
barcolor(longCondition ? color.new(longColor, 70) : shortCondition ? color.new(shortColor, 70) : na)
// Choppy background
bgcolor(useChopFilter and not marketTrending ? color.new(color.orange, 92) : na, force_overlay = true)
// Entry markers (WHITE text color, more pro wording)
plotshape(longCondition, "Fusion Long Entry",
style = shape.triangleup, location = location.belowbar,
size = size.small, color = longColor)
plotshape(shortCondition, "Fusion Short Entry",
style = shape.triangledown, location = location.abovebar,
size = size.small, color = shortColor)
// Filtered signals (X marks)
plotshape(rawLongFlipFiltered, "Filtered Long Flip",
style = shape.xcross, location = location.belowbar,
size = size.tiny, color = color.new(color.orange, 0))
plotshape(rawShortFlipFiltered, "Filtered Short Flip",
style = shape.xcross, location = location.abovebar,
size = size.tiny, color = color.new(color.orange, 0))
//──────────────────────────
// ALERTS
//──────────────────────────
alertcondition(longCondition, title = "Fusion Long", message = "SuperTrend Fusion — Long signal")
alertcondition(shortCondition, title = "Fusion Short", message = "SuperTrend Fusion — Short signal")
Last edited by a moderator: