0% found this document useful (0 votes)
434 views5 pages

QQE SMART2 Trading Indicator Script

The document is a Pine Script code for a trading indicator called 'QQE SMART2 Enhanced' that utilizes the RSI and QQE methodologies to generate buy and sell signals. It includes customizable parameters for RSI length, smoothing, and color options for visual representation on trading charts. The script tracks trades, calculates profit/loss, and provides visual cues for trading decisions through plotted shapes and lines.

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
434 views5 pages

QQE SMART2 Trading Indicator Script

The document is a Pine Script code for a trading indicator called 'QQE SMART2 Enhanced' that utilizes the RSI and QQE methodologies to generate buy and sell signals. It includes customizable parameters for RSI length, smoothing, and color options for visual representation on trading charts. The script tracks trades, calculates profit/loss, and provides visual cues for trading decisions through plotted shapes and lines.

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 DOCX, PDF, TXT or read online on Scribd

//@version=5

indicator("QQE SMART2 Enhanced", 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 = [Link](14, title='RSI Length')
SF = [Link](5, title='RSI Smoothing')
QQE = [Link](4.238, title='Fast QQE Factor')
ThreshHold = [Link](10, title="Thresh-hold")

// Plot color options


showColoring = [Link](true, title="Enable Coloring")
colorAboveRising = [Link]([Link], title="Above Zero Rising
Color")
colorAboveFalling = [Link]([Link], title="Above Zero Falling
Color")
colorBelowRising = [Link]([Link], title="Below Zero Rising
Color")
colorBelowFalling = [Link]([Link], title="Below Zero Falling
Color")

// Define real-time color customization inputs


plot1ColorRising = [Link]([Link], title="Plot 1 Rising Color")
plot1ColorFalling = [Link]([Link], title="Plot 1 Falling Color")
plot2ColorRising = [Link]([Link], title="Plot 2 Rising Color")
plot2ColorFalling = [Link]([Link], title="Plot 2 Falling
Color")
plot3ColorRising = [Link]([Link], title="Plot 3 Rising
Color")
plot3ColorFalling = [Link]([Link], title="Plot 3 Falling
Color")

// Fill options
enableFillBelow = [Link](true, title="Enable Fill Below Zero")
colorFillBelowRising = [Link]([Link]([Link], 90),
title="Fill Below Rising Color")
colorFillBelowFalling = [Link]([Link]([Link], 90),
title="Fill Below Falling Color")

enableFillAbove = [Link](true, title="Enable Fill Above Zero")


colorFillAboveRising = [Link]([Link]([Link], 90),
title="Fill Above Rising Color")
colorFillAboveFalling = [Link]([Link]([Link], 90),
title="Fill Above Falling Color")

// Bar Color Option


inpDrawBars = [Link](true, title="Color Bars Based on Indicator") //
Declare inpDrawBars

// Define MA function
ma(type, src, len) =>
switch type
"SMA" => [Link](src, len)
"EMA" => [Link](src, len)
"DEMA" =>
e = [Link](src, len)
2 * e - [Link](e, len)
"TEMA" =>
e = [Link](src, len)
3 * (e - [Link](e, len)) + [Link]([Link](e, len), len)
"WMA" => [Link](src, len)
"VWMA" => [Link](src, len)
"SMMA" =>
w = [Link](src, len)
sma_w = [Link](src, len) // Calculate SMA here
na(w[1]) ? sma_w : (w[1] * (len - 1) + src) / len
"HMA" =>
[Link](2 * [Link](src, len / 2) - [Link](src, len),
[Link]([Link](len)))
"LSMA" => [Link](src, len, 0)
"ALMA" => [Link](src, len, 0.85, 6)
"PEMA" =>
ema1 = [Link](src, len)
ema2 = [Link](ema1, len)
ema3 = [Link](ema2, len)
ema4 = [Link](ema3, len)
ema5 = [Link](ema4, len)
ema6 = [Link](ema5, len)
ema7 = [Link](ema6, len)
ema8 = [Link](ema7, len)
8 * ema1 - 28 * ema2 + 56 * ema3 - 70 * ema4 + 56 * ema5 -
28 * ema6 + 8 * ema7 - ema8

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

// Initialize longband and shortband with type


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]) ?


[Link](longband[1], newlongband) : newlongband
shortband := (RSIndex[1] < shortband[1] and RSIndex < shortband[1]) ?
[Link](shortband[1], newshortband) : newshortband

// Calculate cross values separately


cross_1 = [Link](longband[1], RSIndex)
cross_to_shortband = [Link](RSIndex, shortband[1])

// Correctly assign values to trend with integer type


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

FastAtrRsiTL = trend == 1 ? longband : shortband


// Define buy/sell conditions
buyCondition = [Link](RsiMa, longband) and trend == -1
sellCondition = [Link](shortband, RSIndex) and trend == 1

// 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"
// Optionally, handle the trade closure and record results
// Plot buy/sell signals
plotshape(series=buyCondition ? close : na, location=[Link],
color=[Link], style=[Link], size=[Link], title="Buy
Signal")
plotshape(series=sellCondition ? close : na, location=[Link],
color=[Link], style=[Link], size=[Link], title="Sell
Signal")

// Plot lines connecting buy and sell signals


var line buyLine = na
var line sellLine = na

if (buyCondition and not na(entryPrice))


if (not na(buyLine))
[Link](buyLine)
buyLine := [Link](x1=bar_index, y1=entryPrice, x2=bar_index,
y2=entryPrice, color=[Link], width=2)

if (sellCondition and not na(entryPrice))


if (not na(sellLine))
[Link](sellLine)
sellLine := [Link](x1=bar_index, y1=entryPrice, x2=bar_index,
y2=close, color=[Link], width=2)
// Create a small chart for trade results
var table tradeTable = [Link](position.bottom_right, 1, 3,
border_width=1)

// Update table with trade details


if (not na(entryPrice) and not inTrade)
[Link](tradeTable, 0, 0, text="Buy Price: " +
[Link](entryPrice), bgcolor=[Link], text_color=[Link])
[Link](tradeTable, 0, 1, text="Sell Price: " +
[Link](exitPrice), bgcolor=[Link], text_color=[Link])
[Link](tradeTable, 0, 2, text="Profit/Loss: " +
[Link](profitLoss), bgcolor=profitLoss >= 0 ? [Link] :
[Link], text_color=[Link])
// Define error handling
if (buyCondition and sellCondition)
var bool codeRedIssued = false
if (not codeRedIssued)
[Link](bar_index, high, "Code Red: Possible Trade Error",
color=[Link], textcolor=[Link], size=[Link])
codeRedIssued := true

// Define color logic function


getColor(val, prevVal, risingColor, fallingColor) =>
if val >= 0
val > prevVal ? risingColor : fallingColor
else
val > prevVal ? risingColor : fallingColor

// Define plot variables


plot1 = RsiMa - 50
plot2 = FastAtrRsiTL - 50
plot3 = RsiMa - 50 // Change this if a different third plot is used

// Plot lines with conditional color


p1 = plot(plot1, color=[Link](getColor(plot1, plot1[1],
plot1ColorRising, plot1ColorFalling), 0), title="Plot 1")
p2 = plot(plot2, color=[Link](getColor(plot2, plot2[1],
plot2ColorRising, plot2ColorFalling), 0), title="Plot 2")
p3 = plot(plot3, color=[Link](getColor(plot3, plot3[1],
plot3ColorRising, plot3ColorFalling), 0), title="Plot 3")

// Define fill colors based on conditions


colorFillBelow = (plot1 > plot2) ? colorFillBelowRising :
colorFillBelowFalling
colorFillAbove = (plot2 > plot3) ? colorFillAboveRising :
colorFillAboveFalling

// Apply fills only when plots are properly defined


fill(p1, p2, color=enableFillBelow ? colorFillBelow : na, title="Fill
Below")
fill(p2, p3, color=enableFillAbove ? colorFillAbove : na, title="Fill
Above")

// Plot Threshold Channels


hZero = hline(0, color=[Link], linestyle=hline.style_dashed,
linewidth=1)
hUpper = hline(ThreshHold, color=[Link],
linestyle=hline.style_dashed, linewidth=2)
hLower = hline(0 - ThreshHold, color=[Link],
linestyle=hline.style_dashed, linewidth=2)
fill(hUpper, hLower, color=[Link]([Link], 80))

// Bar Color
bgc = RsiMa - 50 > ThreshHold ? [Link] : RsiMa - 50 < 0 -
ThreshHold ? [Link] : [Link]
barcolor(inpDrawBars ? bgc : na)

Common questions

Powered by AI

Wilders_Period is a derived period calculated as 'RSI_Period * 2 - 1', which is used to smooth the Average True Range (ATR) calculation . This period affects the accuracy and smoothness of the Average True Range of the smoothed RSI (RsiMa), directly impacting the calculation of ATR thresholds for the QQE bands, which then influence the buy and sell signals .

The threshold is defined by a variable 'ThreshHold', which is set to 10 by default . It establishes critical levels for generating trade signals based on the Relative Strength Index Moving Average (RsiMa). When the 'RsiMa - 50' crosses above or below this threshold, it triggers either a buy or sell condition, thus influencing the trading signals .

Color-coding in plots is integral to visualizing trade signals and trends. Rising and falling conditions in indicators are differentiated through colors specified by the user, like green for rising and red for falling . Color fills are used to highlight areas between plots, where colors change depending on the values relative to each other. This visual distinction helps quickly understand market conditions and trade signals .

The 'fill' option visually connects two plots by coloring the area between them based on their relative positions and dynamic settings . For instance, enabling 'fill' above or below zero aids in distinguishing between positive or negative areas of market movement, thereby enhancing clarity in interpreting trends and potential reversals modeled by the QQE output .

The integration of trade signals with graphical elements in QQE SMART2 Enhanced is highly effective in conveying trading strategies. Buy and sell signals are visually represented as shapes over the price chart, with connecting lines improving traceability of trading events . The graphical use of colors for rising and falling trends, along with fills, enhances comprehension of complex strategies at a glance, offering traders a more intuitive understanding . Despite its complexity, this integration leverages visual tools to simplify decision-making, making the indicator user-friendly for various expertise levels.

The risk management strategy is encoded by the buy/sell conditional logic and tracking of trade states with 'inTrade', 'entryPrice', and 'exitPrice' variables . It ensures only one active trade at a time and manages entries/exits after certain criteria are met, helping to systematize and control trading activities. The 'profitLoss' is calculated upon each trade closure signifying the outcome quantitatively for decision support .

Several types of moving averages are included, such as SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HMA, LSMA, ALMA, and PEMA, covering a wide spectrum of moving average algorithms . These averages help smooth various data inputs like price or RSI values to reduce noise and identify trends more clearly. Each type offers different levels of sensitivity and smoothness for specific analytical needs within the indicator .

The background color setting, 'bgc', is employed based on threshold checks of RsiMa values adjusted by 50 . If 'RsiMa - 50' exceeds the threshold (10), green is shown, indicating a positive signal; below negative threshold (-10), red appears. If not crossing either threshold, then orange is used. This color scheme provides immediate insight into the market momentum relative to QQE thresholds .

Trend changes are determined by evaluating cross conditions between the RSIndex and longband/shortband values. Specifically, a trend is set to 1 when 'RSIndex' crosses to the shortband, indicating an uptrend, and to -1 when there's a cross with the longband, indicating a downtrend . These changes help in setting the fast ATR RSI trend line (FastAtrRsiTL) to guide trade signals .

The buy condition arises when the smoothed RSI ('RsiMa') crosses above the longband while the trend is -1, indicating a potential market reversal, while the sell condition occurs when the RSIndex crosses below the shortband during an uptrend (trend = 1). Upon satisfying these conditions, trade signals result in entering or exiting a trade, transitioning the status of 'inTrade' variable, and recording entry or exit price to manage trades efficiently .

You might also like