Preconditions
Testing SPY as initial ticker.
The goal is to have an indicator with greater profit than buy and hold for the testing period (01/Jan/2014 - 01/Jan/2024). The baseline is 65k at the end (40 k profit)
Initial capital is 25k.
The risk is 2%.
It is possible to create a strategy only for long positions.
Main Parameters of Testing
Aroon
//Insert indicator variables
Aroon_length = input.int(14, title="Aroon Length", minval=1)
Aroon_upper = 100 * (ta.highestbars(high, Aroon_length) + Aroon_length)/Aroon_length
Aroon_lower = 100 * (ta.lowestbars(low, Aroon_length) + Aroon_length)/Aroon_length
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(Aroon_upper, Aroon_lower)
C1_S_Trigger = ta.crossunder(Aroon_upper, Aroon_lower)
Daily
23 SL 1.5ATR
7 SL 1ATR
24 SL 1ATR
Weekly
14 ATR 1.7/1.6
SSL Channel
period = input.int(title="Period", defval=10)
len = input.int(title="Period", defval=10)
// Calculate simple moving averages
smaHigh = ta.sma(high, len)
smaLow = ta.sma(low, len)
// Initialize Hlv as a mutable variable with a default value of `na`
var float Hlv = na
// Update Hlv based on conditions
Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1]
// Calculate SSL lines
sslDown = Hlv < 0 ? smaHigh : smaLow
sslUp = Hlv < 0 ? smaLow : smaHigh
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(sslUp, sslDown)
C1_S_Trigger = ta.crossunder(sslUp, sslDown)
//Insert indicator conditions as Filter
C1_L_Filter = sslUp > sslDown
C1_S_Filter = sslUp < sslDown
Daily
8/8 1.5ATR
8/8 0.6ATR
13/13 1.5ATR
13/13 1.2ATR
Absolute Strength Histogram v2 jh
// Inputs
Length = input(9, title="Period of Evaluation")
Smooth = input(3, title="Period of Smoothing")
show_histo = input(true, title="Show Histogram")
src = input(close, title="Source")
Mode = input.string(title="Indicator Method", defval="RSI", options=["RSI", "STOCHASTIC", "ADX"])
ma_type = input.string(title="MA", defval="WMA", options=["ALMA", "EMA", "WMA", "SMA", "SMMA", "HMA"])
alma_offset = input.float(defval=0.85, title="* Arnaud Legoux (ALMA) Only - Offset Value", minval=0, step=0.01)
alma_sigma = input.float(defval=6, title="* Arnaud Legoux (ALMA) Only - Sigma Value", minval=0)
// Moving average function
ma(type, src, len) =>
float result = 0.0
switch type
"SMA" => result := ta.sma(src, len)
"EMA" => result := ta.ema(src, len)
"WMA" => result := ta.wma(src, len)
"SMMA" =>
float w = ta.wma(src, len)
result := na(w[1]) ? ta.sma(src, len) : (w[1] * (len - 1) + src) / len
"HMA" => result := ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
"ALMA" => result := ta.alma(src, len, alma_offset, alma_sigma)
result
// Calculations
Price = src
Price1 = ma("SMA", Price, 1)
Price2 = ma("SMA", Price[1], 1)
// RSI
Bulls0 = 0.5 * (math.abs(Price1 - Price2) + (Price1 - Price2))
Bears0 = 0.5 * (math.abs(Price1 - Price2) - (Price1 - Price2))
// Stochastic
Bulls1 = Price1 - ta.lowest(Price1, Length)
Bears1 = ta.highest(Price1, Length) - Price1
// ADX
Bulls2 = 0.5 * (math.abs(high - high[1]) + (high - high[1]))
Bears2 = 0.5 * (math.abs(low[1] - low) + (low[1] - low))
// Select bulls and bears based on the selected mode
Bulls = switch Mode
"RSI" => Bulls0
"STOCHASTIC" => Bulls1
=> Bulls2 // ADX
Bears = switch Mode
"RSI" => Bears0
"STOCHASTIC" => Bears1
=> Bears2 // ADX
AvgBulls = ma(ma_type, Bulls, Length)
AvgBears = ma(ma_type, Bears, Length)
// Smoothing
SmthBulls = ma(ma_type, AvgBulls, Smooth)
SmthBears = ma(ma_type, AvgBears, Smooth)
// Difference
difference = math.abs(SmthBulls - SmthBears)
// Colors
bull_trend_color = SmthBulls < SmthBulls[1] ? color.lime : color.green
bear_trend_color = SmthBears < SmthBears[1] ? color.orange : color.red
difference_color = difference > SmthBulls ? (SmthBears < SmthBears[1] ? color.orange : color.red) :
difference > SmthBears ? (SmthBulls < SmthBulls[1] ? color.lime : color.green) : color.gray
// Plots
plot(difference, style=plot.style_histogram, linewidth=3, color=show_histo ? difference_color : na, transp=45, title="Strength")
A = plot(SmthBulls, color=bull_trend_color, linewidth=4, transp=0)
B = plot(SmthBears, color=bear_trend_color, linewidth=4, transp=0)
// fill(A, B, color=trend == 1 ? color.aqua : color.fuchsia, transp=80) // Uncomment and define 'trend' logic to use this
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(SmthBulls, SmthBears)
C1_S_Trigger = ta.crossunder(SmthBulls, SmthBears)
Daily
18/3/close/rsi/wma 1.5ATR
18/3/close/rsi/wma 1.1ATR
6/3/close/adx/wma 0.1ATR
Didi Index Improved with QQE | jh
src = input.source(title="Source", defval=close)
curtaLen = input.int(title="Curta (Short) Length", defval=3)
mediaLen = input.int(title="Media (Medium) Length", defval=8)
longaLen = input.int(title="Longa (Long) Length", defval=20) //20
ma_type = input.string(title="Didi Index MA", defval="SMA", options=["ALMA", "EMA", "WMA", "SMA", "SMMA", "HMA"])
alma_offset = input.float(defval=0.85, title="* Arnaud Legoux (ALMA) Only - Offset Value", minval=0, step=0.01)
alma_sigma = input.float(defval=6, title="* Arnaud Legoux (ALMA) Only - Sigma Value", minval=0)
show_filling = input.bool(true, title="Show Filling")
//QQE Trend Line
useQQE = input.int(title="QQE 1 or 2", defval=1, options=[1,2])
signal_len = input.int(defval=14, title="Signal Length")
smoothening = input.int(defval=5, title="Smoothening Length")
qqe_factor = input.float(defval=4.236, title="QQE Factor")
ma(type, src, len) =>
float result = na
if type == "SMA"
result := ta.sma(src, len)
if type == "EMA"
result := ta.ema(src, len)
if type == "WMA"
result := ta.wma(src, len)
if type == "SMMA"
w = ta.wma(src, len)
result := na(w[1]) ? ta.sma(src, len) : (w[1] * (len - 1) + src) / len
if type == "HMA"
result := ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
if type == "ALMA"
result := ta.alma(src, len, alma_offset, alma_sigma)
result
//Credits to Shizaru
qqeLine(src, len, sf, qqe) =>
wildersper = len * 2 - 1
rsima = ta.ema(src, sf)
atr = math.abs(rsima[1] - rsima)
maatrrsi = ta.ema(atr, wildersper)
dar = ta.ema(maatrrsi, wildersper) * qqe
trr = 0.0
trr := rsima > nz(trr[1]) ? ((rsima - dar) < trr[1] ? trr[1] : (rsima - dar)) : ((rsima + dar) > trr[1] ? trr[1] : (rsima + dar))
//Credits to Glaz
qqeLine2(src, len, sf, qqe) =>
Wilders_Period = len * 2 - 1
RsiMa = ta.ema(src, sf)
AtrRsi = math.abs(RsiMa[1] - RsiMa)
MaAtrRsi = ta.ema(AtrRsi, Wilders_Period)
dar = ta.ema(MaAtrRsi, Wilders_Period) * qqe
longband = 0.0
shortband = 0.0
trend = 0
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
trend := ta.crossover(RSIndex, shortband[1]) ? 1 : ta.crossover(longband[1], RSIndex) ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband
FastAtrRsiTL_plot = FastAtrRsiTL
media = ma(ma_type, src, mediaLen)
curta = ma(ma_type, src, curtaLen) - media
longa = ma(ma_type, src, longaLen) - media
plot(0, title="Media", color=color.gray, transp=0)
A = plot(curta, title="Curta", color=color.green, transp=0, linewidth=1)
B = plot(longa, title="Longa", color=color.red, transp=0, linewidth=1)
trendColor = show_filling ? (curta > longa ? color.lime : color.orange) : na
fill(A, B, color=trendColor, transp=80)
qqe_line = useQQE == 1 ? qqeLine(curta, signal_len, smoothening, qqe_factor) : qqeLine2(curta, signal_len, smoothening, qqe_factor)
qqeColor = qqe_line > 0 ? color.lime : color.orange
plot(qqe_line, color=qqeColor, linewidth=2, transp=20, style=plot.style_cross)
c_qqeline_cross_Long = ta.crossover(curta, qqe_line)
c_qqeline_cross_Short = ta.crossover(qqe_line, curta)
//Signals based on crossover
c_cross_Long = ta.crossover(curta, longa)
c_cross_Short = ta.crossover(longa, curta)
//Signals based on signal position
c_trend_Long = curta > longa ? 1 : 0
c_trend_Short = longa > curta ? 1 : 0
confirm_Long = c_cross_Long
confirm_Short = c_cross_Short
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(curta, longa)
C1_S_Trigger = ta.crossover(longa, curta)
Daily
close/3/10/26/HMA 0.1ATR
Schaff Trend Cycle
// Inputs
fastLength = input.int(title="MACD Fast Length", defval=23)
slowLength = input.int(title="MACD Slow Length", defval=50)
cycleLength = input.int(title="Cycle Length", defval=10)
d1Length = input.int(title="1st %D Length", defval=3)
d2Length = input.int(title="2nd %D Length", defval=3)
src = input.source(title="Source", defval=close)
upper = input.int(title="Upper Band", defval=75)
lower = input.int(title="Lower Band", defval=25)
highlightBreakouts = input.bool(title="Highlight Breakouts ?", defval=true)
macd = ta.ema(src, fastLength) - ta.ema(src, slowLength)
k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
d = ta.ema(k, d1Length)
kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
stc = ta.ema(kd, d2Length)
stc := math.min(math.max(stc, 0), 100)
stcColor1 = stc > stc[1] ? color.green : color.red
stcColor2 = stc > upper ? color.green : stc <= lower ? color.red : color.orange
stcColor = highlightBreakouts ? stcColor2 : stcColor1
stcPlot = plot(stc, title="STC", color=stcColor, transp=0)
upperLevel = plot(upper, title="Upper", color=color.gray)
hline(50, title="Middle", linestyle=hline.style_dotted)
lowerLevel = plot(lower, title="Lower", color=color.gray)
upperFillColor = stc > upper and highlightBreakouts ? color.green : na
lowerFillColor = stc < lower and highlightBreakouts ? color.red : na
buySignal = ta.crossover(stc, lower)
sellSignal = ta.crossunder(stc, upper)
upperCrossover = ta.crossover(stc, upper)
upperCrossunder = ta.crossunder(stc, upper)
lowerCrossover = ta.crossover(stc, lower)
lowerCrossunder = ta.crossunder(stc, lower)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(stc, lower)
C1_S_Trigger = ta.crossunder(stc, upper)
Daily
8/39/4/4/4/close/83/20 1.5ATR
8/39/4/4/4/close/83/20 0.6ATR
Bulls v Bears
// Input settings
len = input.int(title="BvB Period", defval=14, minval=1)
bars_back = input.int(title="Normalized Bars Back", defval=120, minval=1)
tline = input.int(80, title="Line Height")
// Calculation
ma = ta.ema(close, len)
bulls = high - ma
bears = ma - low
// Normalize the values between -100 and 100
min_bulls = ta.lowest(bulls, bars_back)
max_bulls = ta.highest(bulls, bars_back)
norm_bulls = ((bulls - min_bulls) / (max_bulls - min_bulls) - 0.5) * 100
min_bears = ta.lowest(bears, bars_back)
max_bears = ta.highest(bears, bars_back)
norm_bears = ((bears - min_bears) / (max_bears - min_bears) - 0.5) * 100
// Calculate the total and add signals
total = norm_bulls - norm_bears
bullish_o = total > tline
bearish_o = total < -tline
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(total, 0)
C1_S_Trigger = ta.crossunder(total, 0)
Daily
3/165/80 1.5АТР
3/165/80 0.5АТР
Kalman Hull
Do not work great as 1st Confirm. Possible 2nd
// Input settings
series float pricesource = input.source(close, "Kalman Price Source", group = "Calculation")
simple float measurementNoise = input.float(3.0, title="Measurement Noise", group = "Calculation", tooltip = "Lookback Period/ Calculation Length", step = 1.0)
simple float processNoise = input.float(0.01, title="Process Noise", step = 0.01, group = "Calculation")
simple int atrPeriod = input.int(12, "ATR Period", group = "Supertrend", inline = "ST")
simple float factor = input.float(1.7, "Factor", group = "Supertrend", inline = "ST", step = 0.01)
simple bool showkalman = input.bool(true, "Show Supertrend on chart?", group = "UI Settings")
simple bool paintCandles = input.bool(true, "Paint candles according to Trend?", group = "UI Settings")
simple bool showlongshort = input.bool(true, "Show Long and Short Signals {𝕃 + 𝕊}", group = "UI Settings")
color longColor = input.color(#33ff00, "Long Color", group = "UI Settings", inline = "Col")
color shortColor = input.color(#ff0000, "Short Color", group = "UI Settings", inline = "Col")
/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Kalman Price Filter Function
N = 5
var float[] stateEstimate = array.new_float(N, na)
var float[] errorCovariance = array.new_float(N, 100.0)
f_init(series float pricesource) =>
if na(array.get(stateEstimate, 0))
for i = 0 to N-1
array.set(stateEstimate, i, pricesource)
array.set(errorCovariance, i, 1.0)
f_kalman(series float pricesource, float measurementNoise) =>
// Prediction Step
predictedStateEstimate = array.new_float(N)
predictedErrorCovariance = array.new_float(N)
for i = 0 to N-1
array.set(predictedStateEstimate, i, array.get(stateEstimate, i)) // Simplified prediction
array.set(predictedErrorCovariance, i, array.get(errorCovariance, i) + processNoise)
kalmanGain = array.new_float(N)
for i = 0 to N-1
kg = array.get(predictedErrorCovariance, i) / (array.get(predictedErrorCovariance, i) + measurementNoise)
array.set(kalmanGain, i, kg)
array.set(stateEstimate, i, array.get(predictedStateEstimate, i) + kg * (pricesource - array.get(predictedStateEstimate, i)))
array.set(errorCovariance, i, (1 - kg) * array.get(predictedErrorCovariance, i))
array.get(stateEstimate, 0)
f_init(pricesource)
kalmanFilteredPrice = f_kalman(pricesource, measurementNoise)
/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Hull Moving Average Function with Kalman instead of Weighted Moving Average
KHMA(_src, _length) =>
f_kalman(2 * f_kalman(_src, _length / 2) - f_kalman(_src, _length), math.round(math.sqrt(_length)))
// Return
kalmanHMA = KHMA(pricesource, measurementNoise)
/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Supertrend Function
supertrend(factor, atrPeriod, src) =>
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// Call Function with Inputs
[superTrend, direction] = supertrend(factor, atrPeriod, kalmanHMA)
/////////////////////////////////////////////////////////////// © BackQuant ///////////////////////////////////////////////////////////////
// Conditional Trend
SupertrendLong = ta.crossunder(direction, 0)
SupertrendShort = ta.crossover(direction, 0)
var Trend = 0
if SupertrendLong and not SupertrendShort
Trend := 1
if SupertrendShort
Trend := -1
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossunder(direction, 0)
C1_S_Trigger = ta.crossover(direction, 0)
Vortex
//Insert indicator variables
period_ = input.int(14, title="Length", minval=2)
VMP = math.sum( math.abs( high - low[1]), period_ )
VMM = math.sum( math.abs( low - high[1]), period_ )
STR = math.sum( ta.atr(1), period_ )
VIP = VMP / STR
VIM = VMM / STR
plot(VIP, title="VI +", color=#2962FF)
plot(VIM, title="VI -", color=#E91E63)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(VIP, VIM)
C1_S_Trigger = ta.crossover(VIM, VIP)
Daily
19 1.5ATR
11 1.5ATR
FantailVMA
//Insert indicator variables
ADX_Length = input.int(2, minval=1, title="ADX_Length")
Weighting = input.float(10.0, minval=1, title="Weighting")
MA_Length = input.int(6, minval=1, title="MA_Length") // This must be =1 so that the VMA base line does not get averaged.
var VMA = close
var VarMA = close
var MA = close
var STR = high - low
var sPDI = 0.0
var sMDI = 0.0
var ADX = 0.0
Hi = high
Hi1 = high[1]
Lo = low
Lo1 = low[1]
Close1 = close[1]
Bulls1 = 0.5 * (math.abs(Hi - Hi1) + (Hi - Hi1))
Bears1 = 0.5 * (math.abs(Lo1 - Lo) + (Lo1 - Lo))
Bears = Bulls1 > Bears1 ? 0 : (Bulls1 == Bears1 ? 0 : Bears1)
Bulls = Bulls1 < Bears1 ? 0 : (Bulls1 == Bears1 ? 0 : Bulls1)
if (bar_index > 0)
sPDI := (Weighting * sPDI[1] + Bulls) / (Weighting + 1) // ma weighting
sMDI := (Weighting * sMDI[1] + Bears) / (Weighting + 1) // ma weighting
TR = math.max(Hi - Lo, Hi - Close1)
if (bar_index > 0)
STR := (Weighting * STR[1] + TR) / (Weighting + 1)
PDI = STR > 0 ? sPDI / STR : 0
MDI = STR > 0 ? sMDI / STR : 0
DX = (PDI + MDI) > 0 ? math.abs(PDI - MDI) / (PDI + MDI) : 0
if (bar_index > 0)
ADX := (Weighting * ADX[1] + DX) / (Weighting + 1)
vADX = ADX
adxlow = ta.lowest(ADX, ADX_Length)
adxmax = ta.highest(ADX, ADX_Length)
ADXmin = math.min(1000000.0, adxlow)
ADXmax = math.max(-1.0, adxmax)
Diff = ADXmax - ADXmin
Const = Diff > 0 ? (vADX - ADXmin) / Diff : 0
if (bar_index > 0)
VarMA := ((2 - Const) * VarMA[1] + Const * close) / 2
MA := ta.sma(VarMA, MA_Length)
plot(MA, color=color.white, title="Bixord FVMA")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(close, MA)
C1_S_Trigger = ta.crossover(MA, close)
Daily 4/16/15
Recursive Median Filter
//Insert indicator variables
medianLength = input.int(title="Median Length", defval=5, minval=1)
lowpassLength = input.int(title="Lowpass Length", defval=12, minval=1)
highlightMovements = input.bool(title="Highlight Movements ?", defval=true)
src = input.source(title="Source", defval=close)
median(src, length) =>
ta.percentile_nearest_rank(src, length, 50)
PI = 2 * math.asin(1)
alphaArg = 2 * PI / lowpassLength
alpha = 0.0
alpha := math.cos(alphaArg) != 0
? (math.cos(alphaArg) + math.sin(alphaArg) - 1) / math.cos(alphaArg)
: nz(alpha[1])
rmf = 0.0
rmf := alpha * median(src, medianLength) + (1 - alpha) * nz(rmf[1])
rmfColor = highlightMovements ? (rmf > rmf[1] ? color.green : color.red) : color.new(#6d1e7f, 0)
plot(rmf, title="RMF", linewidth=2, color=rmfColor)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(rmf, rmf[1]) and rmf > rmf[1] // Switch from red to green
C1_S_Trigger = ta.crossunder(rmf, rmf[1]) and rmf < rmf[1] // Switch from green to red
DAily 7/18 1.5ATR
Trend Direction Force Index - TDFI [wm] - A very good candidate for secondary indi
//Insert indicator variables
lookback = input.int(13, title="Lookback")
filterHigh = input.float(0.05, title="Filter High")
filterLow = input.float(-0.05, title="Filter Low")
price = input.source(close, title="Period")
mma = ta.ema(price * 1000, lookback)
smma = ta.ema(mma, lookback)
impetmma = mma - mma[1]
impetsmma = smma - smma[1]
divma = math.abs(mma - smma)
averimpet = (impetmma + impetsmma) / 2
number = averimpet
pow = 3
var float result = na
// Calculate the power of the 'number'
for i = 1 to pow - 1
if i == 1
result := number
result := result * number
tdf = divma * result
ntdf = tdf / ta.highest(math.abs(tdf), lookback * 3)
c = ntdf > filterHigh ? color.green : ntdf < filterLow ? color.red : color.gray
plot(ntdf, linewidth=2, color=c)
hline(filterHigh, color=color.black)
hline(filterLow, color=color.black)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(ntdf, filterHigh)
C1_S_Trigger = ta.crossunder(ntdf, filterLow)
DiNapoli MACD [LazyBear] - A very good candidate for secondary indi
//Insert indicator variables
lc = input.float(17.5185, title="Long Cycle")
sc = input.float(8.3896, title="Short Cycle")
sp = input.float(9.0503, title="Signal Length")
src = input.source(close, title="Source")
// Variables to store the intermediate calculations
var float fs = na
var float ss = na
var float r = na
var float s = na
// Fast and slow EMA calculations
fs := na(fs[1]) ? src : fs[1] + 2.0 / (1.0 + sc) * (src - fs[1])
ss := na(ss[1]) ? src : ss[1] + 2.0 / (1.0 + lc) * (src - ss[1])
// MACD line
r := fs - ss
// Signal line
s := na(s[1]) ? r : s[1] + 2.0 / (1.0 + sp) * (r - s[1])
// Plotting the histogram and signal line
plot(r, style=plot.style_columns, color=r > 0 ? color.green : color.red, transp=80, title="Histo")
plot(s, color=color.teal, linewidth=2, title="Dinapoli MACD")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(r, 0)
C1_S_Trigger = ta.crossunder(r, 0)
//==============================================================================
//INSERT - EXIT INDICATOR
//==============================================================================
//Insert indicator variables
//Using indicator 1 as exit indicator - no additional indicators to be inserted
//in this example. If you wish to use another indicator, insert indicator here.
//Insert indicator conditions as exit trigger - in this example, using C1 as
//exit indicator. If you wish to use another indicator, insert indicator above,
//and provide trigger (either crossover or crossunder) conditions here.
Exit_L = C1_S_Trigger
Exit_S = C1_L_Trigger
ADX and DI by BeikabuOyaji
//Insert indicator variables
len = input.int(14, title="Length")
th = input.float(20, title="Threshold")
// True Range Calculation
TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
// Directional Movement Calculation
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0
// Smoothed True Range and Directional Movements
var float SmoothedTrueRange = na
SmoothedTrueRange := na(SmoothedTrueRange[1]) ? TrueRange : SmoothedTrueRange[1] - (SmoothedTrueRange[1] / len) + TrueRange
var float SmoothedDirectionalMovementPlus = na
SmoothedDirectionalMovementPlus := na(SmoothedDirectionalMovementPlus[1]) ? DirectionalMovementPlus : SmoothedDirectionalMovementPlus[1] - (SmoothedDirectionalMovementPlus[1] / len) + DirectionalMovementPlus
var float SmoothedDirectionalMovementMinus = na
SmoothedDirectionalMovementMinus := na(SmoothedDirectionalMovementMinus[1]) ? DirectionalMovementMinus : SmoothedDirectionalMovementMinus[1] - (SmoothedDirectionalMovementMinus[1] / len) + DirectionalMovementMinus
// Directional Indicators (DI)
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
// Directional Movement Index (DX)
DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
// Average Directional Index (ADX)
ADX = ta.sma(DX, len)
// Plotting
plot(DIPlus, color=color.green, title="DI+")
plot(DIMinus, color=color.red, title="DI-")
plot(ADX, color=color.navy, title="ADX")
// Threshold Line
hline(th, color=color.black, title="Threshold")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(DIPlus, DIMinus)
C1_S_Trigger = ta.crossunder(DIPlus, DIMinus)
Daily
13/20 1.5ATR
9/20 1.5ATR
6/20 1.5ATR
Klinger Oscillator
//Insert indicator variables
signalLength = input(17, title="Period Signal Line")
shortLength = input(36, title="Period Short Length")
longLength = input(54, title="Period Long Length")
src = input(close, title="Source")
var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
runtime.error("No volume is provided by the data vendor.")
sv = ta.change(src) >= 0 ? volume : -volume
kvo = ta.ema(sv, shortLength) - ta.ema(sv, longLength)
sig = ta.ema(kvo, signalLength)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(kvo, sig)
C1_S_Trigger = ta.crossunder(kvo, sig)
Jurik Trend Strength
length = input(14)
phase = input.int(title="Phase", defval=0)
smoothLength = input.int(title="Smooth Length", defval=5)
power = input.int(title="Power", defval=2)
src = input.source(close, title="Source")
highlightMovements = input.bool(title="Highlight Movements?", defval=true)
phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (smoothLength - 1) / (0.45 * (smoothLength - 1) + 2)
alpha = math.pow(beta, power)
var float jma = na
var float e0 = na
var float e1 = na
var float e2 = na
e0 := (1 - alpha) * src + alpha * nz(e0[1], src)
e1 := (src - e0) * (1 - beta) + beta * nz(e1[1], 0)
e2 := (e0 + phaseRatio * e1 - nz(jma[1], src)) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1], 0)
jma := e2 + nz(jma[1], src)
var float f90_ = na
var float f88 = na
var float f28 = na
var float f30 = na
var float f38 = na
var float f40 = na
var float f48 = na
var float f50 = na
var float f58 = na
var float f60 = na
var float f68 = na
var float f70 = na
var float f78 = na
var float f80 = na
var float f90 = na
f90_ := (nz(f90_, 0) == 0) ? 1.0 : (nz(f88, 5) <= f90_) ? f88 + 1 : f90_ + 1
f88 := (nz(f90_, 0) == 0) and (length - 1 >= 5) ? length - 1.0 : 5.0
f8 = 100.0 * (jma)
f18 = 3.0 / (length + 2.0)
f20 = 1.0 - f18
f10 = nz(f8[1], f8)
v8 = f8 - f10
f28 := f20 * nz(f28, 0) + f18 * v8
f30 := f18 * f28 + f20 * nz(f30, 0)
vC = f28 * 1.5 - f30 * 0.5
f38 := f20 * nz(f38, 0) + f18 * vC
f40 := f18 * f38 + f20 * nz(f40, 0)
v10 = f38 * 1.5 - f40 * 0.5
f48 := f20 * nz(f48, 0) + f18 * v10
f50 := f18 * f48 + f20 * nz(f50, 0)
v14 = f48 * 1.5 - f50 * 0.5
f58 := f20 * nz(f58, 0) + f18 * math.abs(v8)
f60 := f18 * f58 + f20 * nz(f60, 0)
v18 = f58 * 1.5 - f60 * 0.5
f68 := f20 * nz(f68, 0) + f18 * v18
f70 := f18 * f68 + f20 * nz(f70, 0)
v1C = f68 * 1.5 - f70 * 0.5
f78 := f20 * nz(f78, 0) + f18 * v1C
f80 := f18 * f78 + f20 * nz(f80, 0)
v20 = f78 * 1.5 - f80 * 0.5
f0 = ((f88 >= f90_) and (f8 != f10)) ? 1.0 : 0.0
f90 := ((f88 == f90_) and (f0 == 0.0)) ? 0.0 : f90_
v4_ = ((f88 < f90) and (v20 > 0.0000000001)) ? (v14 / v20 + 1.0) * 50.0 : 50.0
rsx = math.max(0, math.min(100, v4_))
jmaColor = highlightMovements ? (rsx > rsx[1] ? color.green : (rsx < rsx[1] ? color.red : color.yellow)) : color.new(#6d1e7f, 0)
plot(rsx, color=jmaColor, linewidth=2, title="RSXC")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(rsx, rsx[1]) and rsx > rsx[1] // Switch from red to green
C1_S_Trigger = ta.crossunder(rsx, rsx[1]) and rsx < rsx[1] // Switch from green to red