0% found this document useful (0 votes)
13 views2 pages

Barcolor Superb

Uploaded by

originspica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Barcolor Superb

Uploaded by

originspica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//@version=5

indicator("QQE SMART2 Enhanced with Invisible Baseline", overlay=true)

// Initialize trade variables


var float entryPrice = na
var float exitPrice = na
var float profitLoss = na
var bool inTrade = false
var string tradeSignal = ""

// Input parameters
RSI_Period = input.int(14, title='RSI Length')
SF = input.int(14, title='RSI Smoothing')
QQE = input.float(4.618, title='Fast QQE Factor')
ThreshHold = input.float(3, title="Thresh-hold")

// Invisible value line parameters


lookBackPeriod = input.int(20, title="Lookback Period for Invisible Line") // User-
defined lookback period
invisibleValueLine = close - ta.sma(close, lookBackPeriod)

// Plot color options


showColoring = input.bool(true, title="Enable Coloring")

// Define MA function
ma(type, src, len) =>
switch type
"SMA" => ta.sma(src, len)
"EMA" => ta.ema(src, len)
"DEMA" =>
e = ta.ema(src, len)
2 * e - ta.ema(e, len)
"TEMA" =>
e = ta.ema(src, len)
3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)
"WMA" => ta.wma(src, len)
"VWMA" => ta.vwma(src, len)

// Calculate QQE
src = close
Wilders_Period = RSI_Period * 2 - 1
Rsi = ta.rsi(src, RSI_Period)
RsiMa = ma("EMA", Rsi, SF)
AtrRsi = math.abs(RsiMa[1] - RsiMa)
MaAtrRsi = ma("EMA", AtrRsi, Wilders_Period)
dar = ma("EMA", MaAtrRsi, Wilders_Period) * QQE

// Initialize longband and shortband


var float longband = na
var float shortband = na
var int trend = na

DeltaFastAtrRsi = dar
RSIndex = RsiMa
newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi

longband := (RSIndex[1] > longband[1] and RSIndex > longband[1]) ?


math.max(longband[1], newlongband) : newlongband
shortband := (RSIndex[1] < shortband[1] and RSIndex < shortband[1]) ?
math.min(shortband[1], newshortband) : newshortband

// Calculate cross values


cross_1 = ta.cross(longband[1], RSIndex)
cross_to_shortband = ta.cross(RSIndex, shortband[1])

// Assign values to trend


trend := na(trend[1]) ? na : (cross_to_shortband ? 1 : (cross_1 ? -1 : trend[1]))

FastAtrRsiTL = trend == 1 ? longband : shortband

// Define buy/sell conditions using invisible value line


buyCondition = ta.cross(RsiMa, longband) and trend == -1 and invisibleValueLine > 0
sellCondition = ta.cross(shortband, RSIndex) and trend == 1 and invisibleValueLine
< 0

// Track trades and calculate profit/loss


if (buyCondition and not inTrade)
entryPrice := close
inTrade := true
tradeSignal := "BUY"
exitPrice := na
profitLoss := na

if (sellCondition and inTrade)


exitPrice := close
profitLoss := exitPrice - entryPrice
inTrade := false
tradeSignal := "SELL"

// Plot buy/sell signals


plotshape(series=buyCondition ? close : na, location=location.belowbar,
color=color.fuchsia, style=shape.triangleup, size=size.small, title="Buy Signal")
plotshape(series=sellCondition ? close : na, location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.small, title="Sell Signal")

// Create a small chart for trade results


var table tradeTable = table.new(position.bottom_right, 1, 3, border_width=1)

// Update table with trade details


if (not na(entryPrice) and not inTrade)
table.cell(tradeTable, 0, 0, text="Buy Price: " + str.tostring(entryPrice),
bgcolor=color.green, text_color=color.white)
table.cell(tradeTable, 0, 1, text="Sell Price: " + str.tostring(exitPrice),
bgcolor=color.red, text_color=color.white)
table.cell(tradeTable, 0, 2, text="Profit/Loss: " + str.tostring(profitLoss),
bgcolor=profitLoss >= 0 ? color.green : color.red, text_color=color.white)

// Bar Color Logic


bgc = RsiMa - 50 > ThreshHold ? color.green : RsiMa - 50 < 0 - ThreshHold ?
color.red : color.orange
barcolor(bgc)

// Plot Invisible Value Line for Debugging


plot(invisibleValueLine, color=color.new(color.blue, 100), title="Invisible Value
Line") // Adjust transparency to make it invisible

You might also like