10. Testing 1st confirm for fixed TP (JNJ) - idavidov13/Pine-Script GitHub Wiki
Preconditions
Testing JNJ as initial ticker. The goal is to have an indicator with greater profit than buy and hold for the testing period (01/Jan/2019 - 01/Jan/2024). The baseline is 40k at the end (15 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
- 16 - TP = 1xATR
- 15 - TP = 1.5xATR
- 12 - TP = 2.0xATR
- 13 - TP = 2.5xATR
- 12 - TP = 3.0xATR
- 11 - TP = 3.5xATR
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
- 6/6 - TP = 1xATR
- 6/6 - TP = 1.5xATR
- 10/10 - TP = 2xATR
- 9/9 - TP = 2.5xATR
- 6/6 - TP = 3xATR
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
- 22/3/close/rsi/ema - TP = 1xATR
- 21/5/close/rsi/smma - TP = 1xATR
- 16/4/close/rsi/sma - TP = 1xATR
- 21/5/close/rsi/ema - TP = 1.5xATR
- 25/4/close/rsi/ema - TP = 1.5xATR
- 21/2/close/rsi/ema - TP = 1.5xATR
- 35/1/close/rsi/wma - TP = 1.5xATR
- 30/5/close/rsi/wma - TP = 1.5xATR
- 28/4/close/rsi/smma - TP = 1.5xATR
- 32/1/close/rsi/alma/0.85/6 - TP = 1.5xATR
- 23/3/close/rsi/ema - TP = 2.0xATR
- 13/3/close/rsi/ema - TP = 2.5xATR
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/7/8/16/sma - TP = 1xATR
- close/3/8/22/ema- TP = 1xATR
- close/6/8/42/wma- TP = 1xATR
- close/6/8/40/wma- TP = 1.5xATR
- close/7/8/42/wma- TP = 2.5xATR
- close/6/8/40/wma- TP = 3.0xATR
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
- 20/240/80 - TP = 1xATR
- 22/280/80 - TP = 1xATR
- 23/297/80 - TP = 1xATR
- 20/240/80 - TP = 1.5xATR
- 22/350/80 - TP = 1.5xATR
- 25/280/80 - TP = 1.5xATR
- 23/380/80 - TP = 2.0xATR
- 25/380/80 - TP = 2.0xATR
- 23/380/80 - TP = 2.5xATR
Kalman Hull
// 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)
Daily
- close/2/0.01/12/1.7 - TP = 2.5xATR
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
- 8 - TP = 1xATR
- 8 - TP = 2.5xATR
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
- 10/11/close - TP = 1xATR
- 10/10/close - TP = 1xATR
- 10/9/close - TP = 1xATR
- 10/8/close - TP = 1xATR
- 10/9/close - TP = 2.0xATR
- 10/8/close - TP = 2.5xATR
Trend Direction Force Index - TDFI [wm]
//Insert indicator variables
lookback = input.int(13, title="Lookback")
filterHigh = input.float(0.05, title="Filter High", step=0.01)
filterLow = input.float(-0.05, title="Filter Low", step=0.01)
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)
Daily
- 7/0.03/-0.03/close - TP = 1xATR
- 7/0.02/-0.02/close - TP = 1xATR
- 7/0.02/-0.02/close - TP = 1.5xATR
- 7/0.02/-0.02/close - TP = 2.0xATR
- 7/0.02/-0.02/close - TP = 2.5xATR
DiNapoli MACD [LazyBear]
//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)
Daily
- 16/8/9/close - TP = 1xATR
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)
Daily
- 15/36/54 - TP = 1xATR
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
Daily
- 6/0/5/5/hlc3 - TP = 2.5xATR
- 35/0/5/5/hlc3 - TP = 2.5xATR
Twiggs Money Flow
// Function for calculating the WiMA (Weighted Moving Average)
WiMA(src, length) =>
var MA_s = 0.0
MA_s := (src + nz(MA_s[1]) * (length - 1)) / length
MA_s
// Inputs
length = input.int(21, title="Period")
// Calculating values for Twiggs Money Flow
tr_h = math.max(close[1], high)
tr_l = math.min(close[1], low)
tr_c = tr_h - tr_l
adv = volume * ((close - tr_l) - (tr_h - close)) / (tr_c == 0 ? 9999999 : tr_c)
wv = volume + volume[1]
wmV = WiMA(wv, length)
wmA = WiMA(adv, length)
tmf = wmV == 0 ? 0 : wmA / wmV
tmff = tmf > 0.2499 ? tmf : 0
tmfm = tmf < -0.2499 ? tmf : 0
// Plotting
plot(tmf, color=color.aqua, style=plot.style_area)
plot(tmff, color=color.green, style=plot.style_area)
plot(tmfm, color=color.red, style=plot.style_area)
// Horizontal line at zero
hline(0, "Zero Line", color=color.gray)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(tmf, 0)
C1_S_Trigger = ta.crossunder(tmf, 0)
Daily
- 12 - TP = 2.5xATR
- 57 - TP = 2.5xATR
Basic Polychromatic Momentum Indicator
// User inputs
src = input(close, title="Source")
len = input.int(14, title="Length", minval=1)
enable_alert = input.bool(title="Enable Alert?", defval=true)
// Calculation of Polychromatic Momentum Indicator
mom = src - src[len]
pmi = mom - (mom - mom[len]) / len
// Smoothed PMI
smoothing = input.int(2, title="Smoothing", minval=1)
sm_pmi = ta.sma(pmi, smoothing)
// Alert condition
alertLevel = input.float(title="Alert Level", defval=0)
alertMessage = "PMI is crossing the alert level " + str.tostring(alertLevel)
if enable_alert and ta.sma(pmi, 1)[1] < alertLevel and ta.sma(pmi, 1) > alertLevel
alert(alertMessage)
// Plotting
plot(sm_pmi, title="PMI", color=color.blue, linewidth=2, transp=0)
hline(0, title="Zero Line", color=color.gray, linestyle=hline.style_dotted)
bgcolor(sm_pmi > 0 ? color.new(color.green, 90) : color.new(color.red, 90))
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(sm_pmi, 0)
C1_S_Trigger = ta.crossunder(sm_pmi, 0)
Daily
- close/26/2 - TP = 1xATR
- close/41/2 - TP = 1xATR
- close/22/1 - TP = 1xATR
Detrended Price Oscillator
// User inputs
period_ = input.int(21, title="Length", minval=1)
isCentered = input(false, title="Centered")
barsback = period_/2 + 1
ma = ta.sma(close, period_)
dpo = isCentered ? close[barsback] - ma : close - ma[barsback]
plot(dpo, offset = isCentered ? -barsback : 0, title="Detrended Price Oscillator", color=#43A047)
hline(0, title="Zero Line", color = #787B86)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(dpo, 0)
C1_S_Trigger = ta.crossunder(dpo, 0)
Daily
- 25 - TP = 1xATR
- 16 - TP = 2.0xATR
- 14 - TP = 2.5xATR
Trendilo
// User inputs
src = input(close, title='Source')
smooth = input.int(1, title='Smoothing', minval=1)
length = input.int(50, title='Lookback', minval=1)
offset = input.float(0.85, title='ALMA Offset', step=0.01)
sigma = input.int(6, title='ALMA Sigma', minval=0)
bmult = input(1.0, 'Band Multiplier')
cblen = input(false, 'Custom Band Length ? (Else same as Lookback)')
blen = input(20, 'Custom Band Length')
highlight = input(true)
fill = input(true)
barcol = input(false, 'Bar Color')
pch = ta.change(src, smooth) / src * 100
avpch = ta.alma(pch, length, offset, sigma)
blength = cblen ? blen : length
rms = bmult * math.sqrt(math.sum(avpch * avpch, blength) / blength)
cdir = avpch > rms ? 1 : avpch < -rms ? -1 : 0
col = cdir == 1 ? color.lime : cdir == -1 ? color.red : color.gray
fplot = plot(avpch, color=highlight ? col : color.blue, linewidth=2)
posrms = plot(rms, color=color.new(color.purple, 0))
negrms = plot(-rms, color=color.new(color.purple, 0))
fill(fplot, posrms, color=fill and cdir > 0 ? col : na, transp=50)
fill(fplot, negrms, color=fill and cdir < 0 ? col : na, transp=50)
barcolor(color=barcol ? col : na)
hline(0)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(avpch, 0)
C1_S_Trigger = ta.crossunder(avpch, 0)
Daily
- close/3/37/0.85/6 - TP = 1xATR
- close/4/37/0.85/6 - TP = 1xATR
- close/5/29/0.85/6 - TP = 1xATR
- ohlc4/3/32/0.85/6 - TP = 2.5xATR
- hlcc4/4/34/0.85/6 - TP = 2.5xATR
Chande Momentum Oscillator
// Input settings
length = input.int(9, minval=1)
src = input(close, "Source")
momm = ta.change(src)
f1(m) => m >= 0.0 ? m : 0.0
f2(m) => m >= 0.0 ? 0.0 : -m
m1 = f1(momm)
m2 = f2(momm)
sm1 = math.sum(m1, length)
sm2 = math.sum(m2, length)
percent(nom, div) => 100 * nom / div
chandeMO = percent(sm1-sm2, sm1+sm2)
plot(chandeMO, "Chande MO", color=#2962FF)
hline(0, color=#787B86, linestyle=hline.style_dashed, title="Zero Line")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(chandeMO, 0)
C1_S_Trigger = ta.crossunder(chandeMO, 0)
Daily
- 22/close - TP = 1xATR
- 22/close - TP = 1.5xATR
- 22/close - TP = 2.0xATR
- 22/close - TP = 2.5xATR
- 27/ohlc4- TP = 1xATR
Jurik Volty Adaptive
// Input settings
import loxx/loxxexpandedsourcetypes/4
greencolor = #2DD204
redcolor = #D2042D
specema(src, per) =>
float ema = src
ema := na(ema[1]) ? src : (src - nz(ema[1])) * (2 / (per + 1)) + nz(ema[1])
ema
tema(src, len) =>
float ema1 = specema(src, len)
float ema2 = specema(ema1, len)
float ema3 = specema(ema2, len)
float out = 3 * (ema1 - ema2) + ema3
out
stdFilter(float src, int len, float filter)=>
float price = src
float filtdev = filter * ta.stdev(src, len)
price := math.abs(price - nz(price[1])) < filtdev ? nz(price[1]) : price
price
volty(float src, int len) =>
int avgLen = 65
float volty = 0.0
float voltya = 0.0
float bsmax = src
float bsmin = src
float vsum = 0
float len1 = math.max(math.log(math.sqrt(0.5 * (len-1))) / math.log(2.0) + 2.0, 0)
float pow1 = math.max(len1 - 2.0, 0.5)
float del1 = src - nz(bsmax[1])
float del2 = src - nz(bsmin[1])
volty := bar_index > 9 ? math.abs(del1) > math.abs(del2) ? math.abs(del1) : math.abs(del2) : voltya
vsum := nz(vsum[1]) + 0.1 * (volty - nz(volty[10]))
avg = ta.sma(vsum, avgLen)
float avolty = avg
float dVolty = avolty > 0 ? voltya / avolty : 0
if dVolty > math.pow(len1, 1.0/pow1)
dVolty := math.pow(len1, 1.0/pow1)
if dVolty < 1
dVolty := 1.0
float pow2 = math.pow(dVolty, pow1)
float len2 = math.sqrt(0.5*(len-1)) * len1
float Kv = math.pow(len2/(len2+1), math.sqrt(pow2))
if del1 > 0
bsmax := src
else
bsmax := src - Kv * del1
if del2 < 0
bsmin := src
else
bsmin := src - Kv * del2
float temp = vsum != 0 ? avolty / vsum : 1
temp
smthtype = input.string("Kaufman", "HAB Calc Type", options = ["AMA", "T3", "Kaufman"], group='Basic Settings')
srcin = input.string("Close", "Source",
options =
["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)",
"HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)",
"HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"],
group='Basic Settings')
len = input.int(27, "EMA Length", group = "Basic Settings")
filterop = input.string("Both", "Filter Options", options = ["Price", "Jurik Volty Adaptive TEMA", "Both", "None"], group= "Filter Settings")
filter = input.float(1, "Filter Devaitions", minval = 0, group= "Filter Settings")
filterperiod = input.int(10, "Filter Period", minval = 0, group= "Filter Settings")
colorbars = input.bool(true, title='Color bars', group = "UI Options")
showSigs = input.bool(true, title='Show signals', group = "UI Options")
kfl = input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")
ksl = input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")
amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")
amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")
t3hot = input.float(.7, "* T3 Only - T3 Hot", group = "Moving Average Inputs")
t3swt = input.string("T3 New", "* T3 Only - T3 Type", options = ["T3 New", "T3 Original"], group = "Moving Average Inputs")
haclose = ohlc4
haopen = float(na)
haopen := na(haopen[1]) ? (open + close) / 2 : (nz(haopen[1]) + nz(haclose[1])) / 2
hahigh =math.max(high, math.max(haopen, haclose))
halow = math.min(low, math.min(haopen, haclose))
hamedian = (hahigh + halow) / 2
hatypical = (hahigh + halow + haclose) / 3
haweighted = (hahigh + halow + haclose + haclose)/4
haaverage = (haopen + hahigh + halow + haclose)/4
sourceout(smthtype, srcin)=>
src = switch srcin
"Close" => close
"Open" => open
"High" => high
"Low" => low
"Median" => hl2
"Typical" => hlc3
"Weighted" => hlcc4
"Average" => ohlc4
"Average Median Body" => (open + close)/2
"Trend Biased" => loxxexpandedsourcetypes.rtrendb()
"Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext()
"HA Close" => loxxexpandedsourcetypes.haclose(haclose)
"HA Open" => loxxexpandedsourcetypes.haopen(haopen)
"HA High" => loxxexpandedsourcetypes.hahigh(hahigh)
"HA Low" => loxxexpandedsourcetypes.halow(halow)
"HA Median" => loxxexpandedsourcetypes.hamedian(hamedian)
"HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical)
"HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted)
"HA Average" => loxxexpandedsourcetypes.haaverage(haaverage)
"HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)
"HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)
"HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)
"HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)
"HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)
"HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)
"HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)
"HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)
"HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)
"HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)
"HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)
"HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)
=> close
src = sourceout(smthtype, srcin)
src := filterop == "Both" or filterop == "Price" and filter > 0 ? stdFilter(src, filterperiod, filter) : src
out = tema(src, len * volty(src, len))
out := filterop == "Both" or filterop == "Jurik Volty Adaptive TEMA" and filter > 0 ? stdFilter(out, filterperiod, filter) : out
sig = out[1]
state = out > sig ? 1 : out < sig ? -1 : 0
pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]))
pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]))
contsw = 0
contsw := nz(contsw[1])
contsw := pregoLong ? 1 : pregoShort ? -1 : nz(contsw[1])
goLong = pregoLong and nz(contsw[1]) == -1
goShort = pregoShort and nz(contsw[1]) == 1
var color colorout = na
colorout := state == -1 ? redcolor : state == 1 ? greencolor : nz(colorout[1])
plot(out, "Jurik Volty Adaptive TEMA", color = colorout, linewidth = 3)
barcolor(colorbars ? colorout : na)
plotshape(showSigs and goLong, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.belowbar, size = size.tiny)
plotshape(showSigs and goShort, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.abovebar, size = size.tiny)
alertcondition(goLong, title = "Long", message = "STD-Filtered Jurik Volty Adaptive TEMA [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(goShort, title = "Short", message = "STD-Filtered Jurik Volty Adaptive TEMA [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")
//Insert indicator conditions as Trigger
C1_L_Trigger = goLong
C1_S_Trigger = goShort
Daily
- kaufman/close/22 - TP = 2.5xATR
- kaufman/weighted/22 - TP = 2.5xATR
- ama/closed/20 - TP = 2.5xATR
Prevailing Trend
// Input settings
//==============================================================================
// Function: Calculate a given type of moving average
//==============================================================================
get_ma_out(type, src, len, alma_offset, alma_sigma, kama_fastLength, kama_slowLength, vama_vol_len, vama_do_smth, vama_smth, mf_beta, mf_feedback, mf_z, eit_alpha, ssma_pow, ssma_smooth, rsrma_pw, svama_method, svama_vol_or_volatility, wrma_smooth, aarma_gamma) =>
float baseline = 0.0
if type == "SMA | Simple MA"
baseline := ta.sma(src, len)
else if type == "EMA | Exponential MA"
baseline := ta.ema(src, len)
else if type == "DEMA | Double Exponential MA"
e = ta.ema(src, len)
baseline := 2 * e - ta.ema(e, len)
else if type == "TEMA | Triple Exponential MA"
e = ta.ema(src, len)
baseline := 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)
else if type == "TMA | Triangular MA" // by everget
baseline := ta.sma(ta.sma(src, math.ceil(len / 2)), math.floor(len / 2) + 1)
else if type == "WMA | Weighted MA"
baseline := ta.wma(src, len)
else if type == "VWMA | Volume-Weighted MA"
baseline := ta.vwma(src, len)
else if type == "SMMA | Smoothed MA"
w = ta.wma(src, len)
baseline := na(w[1]) ? ta.sma(src, len) : (w[1] * (len - 1) + src) / len
else if type == "RMA | Rolling MA"
baseline := ta.rma(src, len)
else if type == "HMA | Hull MA"
baseline := ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
else if type == "LSMA | Least Squares MA"
baseline := ta.linreg(src, len, 0)
else if type == "Kijun" //Kijun-sen
kijun = math.avg(ta.lowest(len), ta.highest(len))
baseline := kijun
else if type == "MD | McGinley Dynamic"
mg = 0.0
mg := na(mg[1]) ? ta.ema(src, len) : mg[1] + (src - mg[1]) / (len * math.pow(src / mg[1], 4))
baseline := mg
else if type == "JMA | Jurik MA" // by everget
DEMAe1 = ta.ema(src, len)
DEMAe2 = ta.ema(DEMAe1, len)
baseline := 2 * DEMAe1 - DEMAe2
else if type == "ALMA | Arnaud Legoux MA"
baseline := ta.alma(src, len, alma_offset, alma_sigma)
else if type == "VAR | Vector Autoregression MA"
valpha = 2 / (len+1)
vud1 = (src > src[1]) ? (src - src[1]) : 0
vdd1 = (src < src[1]) ? (src[1] - src) : 0
vUD = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz( (vUD - vDD) / (vUD + vDD) )
baseline := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(baseline[1])
else if type == "ZLEMA | Zero-Lag Exponential MA" // by HPotter
xLag = (len) / 2
xEMAData = (src + (src - src[xLag]))
baseline := ta.ema(xEMAData, len)
else if type == "AHMA | Ahrens Moving Average" // by everget
baseline := nz(baseline[1]) + (src - (nz(baseline[1]) + nz(baseline[len])) / 2) / len
else if type == "EVWMA | Elastic Volume Weighted MA"
volumeSum = math.sum(volume, len)
baseline := ( (volumeSum - volume) * nz(baseline[1]) + volume * src ) / volumeSum
else if type == "SWMA | Sine Weighted MA" // by everget
sum = 0.0
weightSum = 0.0
for i = 0 to len - 1
weight = math.sin(i * math.pi / (len + 1))
sum := sum + nz(src[i]) * weight
weightSum := weightSum + weight
baseline := sum / weightSum
else if type == "LMA | Leo MA"
baseline := 2 * ta.wma(src, len) - ta.sma(src, len)
else if type == "VIDYA | Variable Index Dynamic Average" // by KivancOzbilgic
mom = ta.change(src)
upSum = math.sum(math.max(mom, 0), len)
downSum = math.sum(-math.min(mom, 0), len)
out = (upSum - downSum) / (upSum + downSum)
cmo = math.abs(out)
alpha = 2 / (len + 1)
baseline := src * alpha * cmo + nz(baseline[1]) * (1 - alpha * cmo)
else if type == "FRAMA | Fractal Adaptive MA"
length2 = math.floor(len / 2)
hh2 = ta.highest(length2)
ll2 = ta.lowest(length2)
N1 = (hh2 - ll2) / length2
N2 = (hh2[length2] - ll2[length2]) / length2
N3 = (ta.highest(len) - ta.lowest(len)) / len
D = (math.log(N1 + N2) - math.log(N3)) / math.log(2)
factor = math.exp(-4.6 * (D - 1))
baseline := factor * src + (1 - factor) * nz(baseline[1])
else if type == "VMA | Variable MA" // by LazyBear
k = 1.0/len
pdm = math.max((src - src[1]), 0)
mdm = math.max((src[1] - src), 0)
pdmS = float(0.0)
mdmS = float(0.0)
pdmS := ((1 - k)*nz(pdmS[1]) + k*pdm)
mdmS := ((1 - k)*nz(mdmS[1]) + k*mdm)
s = pdmS + mdmS
pdi = pdmS/s
mdi = mdmS/s
pdiS = float(0.0)
mdiS = float(0.0)
pdiS := ((1 - k)*nz(pdiS[1]) + k*pdi)
mdiS := ((1 - k)*nz(mdiS[1]) + k*mdi)
d = math.abs(pdiS - mdiS)
s1 = pdiS + mdiS
iS = float(0.0)
iS := ((1 - k)*nz(iS[1]) + k*d/s1)
hhv = ta.highest(iS, len)
llv = ta.lowest(iS, len)
d1 = hhv - llv
vI = (iS - llv)/d1
baseline := (1 - k*vI)*nz(baseline[1]) + k*vI*src
else if type == "GMMA | Geometric Mean MA"
lmean = math.log(src)
smean = math.sum(lmean, len)
baseline := math.exp(smean / len)
else if type == "CMA | Corrective MA" // by everget
sma = ta.sma(src, len)
baseline := sma
v1 = ta.variance(src, len)
v2 = math.pow(nz(baseline[1], baseline) - baseline, 2)
v3 = v1 == 0 or v2 == 0 ? 1 : v2 / (v1 + v2)
var tolerance = math.pow(10, -5)
float err = 1
// Gain Factor
float kPrev = 1
float k = 1
for i = 0 to 5000 by 1
if err > tolerance
k := v3 * kPrev * (2 - kPrev)
err := kPrev - k
kPrev := k
kPrev
baseline := nz(baseline[1], src) + k * (sma - nz(baseline[1], src))
else if type == "MM | Moving Median" // by everget
baseline := ta.percentile_nearest_rank(src, len, 50)
else if type == "QMA | Quick MA" // by everget
peak = len / 3
num = 0.0
denom = 0.0
for i = 1 to len + 1
mult = 0.0
if i <= peak
mult := i / peak
else
mult := (len + 1 - i) / (len + 1 - peak)
num := num + src[i - 1] * mult
denom := denom + mult
baseline := (denom != 0.0) ? (num / denom) : src
else if type == "KAMA | Kaufman Adaptive MA" // by everget
mom = math.abs(ta.change(src, len))
volatility = math.sum(math.abs(ta.change(src)), len)
// Efficiency Ratio
er = volatility != 0 ? mom / volatility : 0
fastAlpha = 2 / (kama_fastLength + 1)
slowAlpha = 2 / (kama_slowLength + 1)
alpha = math.pow(er * (fastAlpha - slowAlpha) + slowAlpha, 2)
baseline := alpha * src + (1 - alpha) * nz(baseline[1], src)
else if type == "VAMA | Volatility Adjusted MA" // by Joris Duyck (JD)
mid = ta.ema(src, len)
dev = src - mid
vol_up = ta.highest(dev, vama_vol_len)
vol_down = ta.lowest(dev, vama_vol_len)
vama = mid + math.avg(vol_up, vol_down)
baseline := vama_do_smth ? ta.wma(vama, vama_smth) : vama
else if type == "Modular Filter" // by alexgrover
//----
b = 0.0, c = 0.0, os = 0.0, ts = 0.0
//----
alpha = 2/(len+1)
a = mf_feedback ? mf_z*src + (1-mf_z)*nz(baseline[1],src) : src
//----
b := a > alpha*a+(1-alpha)*nz(b[1],a) ? a : alpha*a+(1-alpha)*nz(b[1],a)
c := a < alpha*a+(1-alpha)*nz(c[1],a) ? a : alpha*a+(1-alpha)*nz(c[1],a)
os := a == b ? 1 : a == c ? 0 : os[1]
//----
upper = mf_beta*b+(1-mf_beta)*c
lower = mf_beta*c+(1-mf_beta)*b
baseline := os*upper+(1-os)*lower
else if type == "EIT | Ehlers Instantaneous Trendline" // by Franklin Moormann (cheatcountry)
baseline := bar_index < 7 ? (src + (2 * nz(src[1])) + nz(src[2])) / 4 : ((eit_alpha - (math.pow(eit_alpha, 2) / 4)) * src) + (0.5 * math.pow(eit_alpha, 2) * nz(src[1])) -
((eit_alpha - (0.75 * math.pow(eit_alpha, 2))) * nz(src[2])) + (2 * (1 - eit_alpha) * nz(baseline[1])) - (math.pow(1 - eit_alpha, 2) * nz(baseline[2]))
else if type == "ESD | Ehlers Simple Decycler" // by everget
// High-pass Filter
alphaArg = 2 * math.pi / (len * math.sqrt(2))
alpha = 0.0
alpha := math.cos(alphaArg) != 0
? (math.cos(alphaArg) + math.sin(alphaArg) - 1) / math.cos(alphaArg)
: nz(alpha[1])
hp = 0.0
hp := math.pow(1 - (alpha / 2), 2) * (src - 2 * nz(src[1]) + nz(src[2])) + 2 * (1 - alpha) * nz(hp[1]) - math.pow(1 - alpha, 2) * nz(hp[2])
baseline := src - hp
else if type == "SSMA | Shapeshifting MA" // by alexgrover
//----
ssma_sum = 0.0
ssma_sumw = 0.0
alpha = ssma_smooth ? 2 : 1
power = ssma_smooth ? ssma_pow - ssma_pow % 2 : ssma_pow
//----
for i = 0 to len-1
x = i/(len-1)
n = ssma_smooth ? -1 + x*2 : x
w = 1 - 2*math.pow(n,alpha)/(math.pow(n,power) + 1)
ssma_sumw := ssma_sumw + w
ssma_sum := ssma_sum + src[i] * w
baseline := ssma_sum/ssma_sumw
//----
else if type == "RSRMA | Right Sided Ricker MA" // by alexgrover
//----
rsrma_sum = 0.0
rsrma_sumw = 0.0
rsrma_width = rsrma_pw/100*len
for i = 0 to len-1
w = (1 - math.pow(i/rsrma_width,2))*math.exp(-(i*i/(2*math.pow(rsrma_width,2))))
rsrma_sumw := rsrma_sumw + w
rsrma_sum := rsrma_sum + src[i] * w
baseline := rsrma_sum/rsrma_sumw
//----
else if type == "DSWF | Damped Sine Wave Weighted Filter" // by alexgrover
//----
dswf_sum = 0.0
dswf_sumw = 0.0
for i = 1 to len
w = math.sin(2.0*math.pi*i/len)/i
dswf_sumw := dswf_sumw + w
dswf_sum := dswf_sum + w*src[i-1]
//----
baseline := dswf_sum/dswf_sumw
else if type == "BMF | Blackman Filter" // by alexgrover
//----
bmf_sum = 0.0
bmf_sumw = 0.0
for i = 0 to len-1
k = i/len
w = 0.42 - 0.5 * math.cos(2 * math.pi * k) + 0.08 * math.cos(4 * math.pi * k)
bmf_sumw := bmf_sumw + w
bmf_sum := bmf_sum + w*src[i]
//----
baseline := bmf_sum/bmf_sumw
else if type == "HCF | Hybrid Convolution Filter" // by alexgrover
//----
sum = 0.
for i = 1 to len
sgn = .5*(1 - math.cos((i/len)*math.pi))
sum := sum + (sgn*(nz(baseline[1],src)) + (1 - sgn)*src[i-1]) * ( (.5*(1 - math.cos((i/len)*math.pi))) - (.5*(1 - math.cos(((i-1)/len)*math.pi))) )
baseline := sum
//----
else if type == "FIR | Finite Response Filter" // by alexgrover
//----
var b = array.new_float(0)
if barstate.isfirst
for i = 0 to len-1
w = len-i
array.push(b,w)
den = array.sum(b)
//----
sum = 0.0
for i = 0 to len-1
sum := sum + src[i]*array.get(b,i)
baseline := sum/den
else if type == "FLSMA | Fisher Least Squares MA" // by alexgrover
//----
b = 0.0
//----
e = ta.sma(math.abs(src - nz(b[1])),len)
z = ta.sma(src - nz(b[1],src),len)/e
r = (math.exp(2*z) - 1)/(math.exp(2*z) + 1)
a = (bar_index - ta.sma(bar_index,len))/ta.stdev(bar_index,len) * r
b := ta.sma(src,len) + a*ta.stdev(src,len)
baseline := b
else if type == "SVAMA | Non-Parametric Volume Adjusted MA" // by alexgrover and bjr117
//----
h = 0.0
l = 0.0
c = 0.0
//----
a = svama_vol_or_volatility == "Volume" ? volume : ta.tr
h := a > nz(h[1], a) ? a : nz(h[1], a)
l := a < nz(l[1], a) ? a : nz(l[1], a)
//----
b = svama_method == "Max" ? a / h : l / a
c := b * close + (1 - b) * nz(c[1], close)
baseline := c
else if type == "RPMA | Repulsion MA" // by alexgrover
baseline := ta.sma(close, len*3) + ta.sma(close, len*2) - ta.sma(close, len)
else if type == "WRMA | Well Rounded MA" // by alexgrover
//----
alpha = 2/(len+1)
p1 = wrma_smooth ? len/4 : 1
p2 = wrma_smooth ? len/4 : len/2
//----
a = float(0.0)
b = float(0.0)
y = ta.ema(a + b,p1)
A = src - y
B = src - ta.ema(y,p2)
a := nz(a[1]) + alpha*nz(A[1])
b := nz(b[1]) + alpha*nz(B[1])
baseline := y
else if type == "HLT | HiLo Trend"
// Getting the highest highs / lowest lows in the user-inputted slowLength period and fastLength period
hlt_high = ta.highest(src, len)
hlt_low = ta.lowest(src, len)
// Calculate the HLT Line
// If the source (close, hl2, ...) value is greater than the previous HLT line, let the next HLT line value be the source value.
baseline := (src > baseline[1]) ? hlt_low : hlt_high
else if type == "T3 | Tillson T3" // by HPotter
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 21/05/2014
// This indicator plots the moving average described in the January, 1998 issue
// of S&C, p.57, "Smoothing Techniques for More Accurate Signals", by Tim Tillson.
// This indicator plots T3 moving average presented in Figure 4 in the article.
// T3 indicator is a moving average which is calculated according to formula:
// T3(n) = GD(GD(GD(n))),
// where GD - generalized DEMA (Double EMA) and calculating according to this:
// GD(n,v) = EMA(n) * (1+v)-EMA(EMA(n)) * v,
// where "v" is volume factor, which determines how hot the moving average’s response
// to linear trends will be. The author advises to use v=0.7.
// When v = 0, GD = EMA, and when v = 1, GD = DEMA. In between, GD is a less aggressive
// version of DEMA. By using a value for v less than1, trader cure the multiple DEMA
// overshoot problem but at the cost of accepting some additional phase delay.
// In filter theory terminology, T3 is a six-pole nonlinear Kalman filter. Kalman
// filters are ones that use the error — in this case, (time series - EMA(n)) —
// to correct themselves. In the realm of technical analysis, these are called adaptive
// moving averages; they track the time series more aggres-sively when it is making large
// moves. Tim Tillson is a software project manager at Hewlett-Packard, with degrees in
// mathematics and computer science. He has privately traded options and equities for 15 years.
////////////////////////////////////////////////////////////
xe1 = ta.ema(src, len)
xe2 = ta.ema(xe1, len)
xe3 = ta.ema(xe2, len)
xe4 = ta.ema(xe3, len)
xe5 = ta.ema(xe4, len)
xe6 = ta.ema(xe5, len)
b = 0.7
c1 = -b*b*b
c2 = 3*b*b+3*b*b*b
c3 = -6*b*b-3*b-3*b*b*b
c4 = 1+3*b+b*b*b+3*b*b
baseline := c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3
else if type == "ADEMA | Alpha-Decreasing EMA" // by everget
alpha = 2 / (int(bar_index) + 1)
ema = close
ema := alpha * ema + (1 - alpha) * nz(ema[1], ema)
baseline := ema
else if type == "AARMA | Adaptive Autonomous Recursive MA" // by alexgrover
// Calculate an AMA
aarma_d = ta.cum(math.abs(src - nz(baseline[1], src))) / bar_index * aarma_gamma
er = math.abs(ta.change(src, len)) / math.sum(math.abs(ta.change(src)), len)
ama1_constant = src > nz(baseline[1], src) + aarma_d ? src + aarma_d : src < nz(baseline[1], src) - aarma_d ? src - aarma_d : nz(baseline[1], src)
ama1 = float(0.0)
ama1 := er * ama1_constant + (1 - er) * nz(ama1[1], ama1_constant)
//Calculate the AMA of the previous AMA
ama2_constant = ama1
ama2 = float(0.0)
ama2 := er * ama2_constant + (1 - er) * nz(ama2[1], ama2_constant)
// Return the AMA of the first AMA, which is the AARMA
baseline := ama2
baseline
//==============================================================================
//==============================================================================
// Inputs
//==============================================================================
// Main indicator inputs
pt_length = input.int(title = "Length", defval = 10, minval = 0, group = "Main Settings")
pt_src = input.source(title = "Source", defval = close, group = "Main Settings")
pt_ma_type = input.string("SMA | Simple MA", "MA Type", options=[ "EMA | Exponential MA", "SMA | Simple MA",
"WMA | Weighted MA", "DEMA | Double Exponential MA",
"TEMA | Triple Exponential MA", "TMA | Triangular MA",
"VWMA | Volume-Weighted MA", "SMMA | Smoothed MA",
"HMA | Hull MA", "LSMA | Least Squares MA",
"Kijun", "MD | McGinley Dynamic",
"RMA | Rolling MA", "JMA | Jurik MA",
"ALMA | Arnaud Legoux MA", "VAR | Vector Autoregression MA",
"ZLEMA | Zero-Lag Exponential MA", "T3 | Tillson T3",
"AHMA | Ahrens Moving Average", "EVWMA | Elastic Volume Weighted MA",
"SWMA | Sine Weighted MA", "LMA | Leo MA",
"VIDYA | Variable Index Dynamic Average", "FRAMA | Fractal Adaptive MA",
"VMA | Variable MA", "GMMA | Geometric Mean MA",
"CMA | Corrective MA", "MM | Moving Median",
"QMA | Quick MA", "KAMA | Kaufman Adaptive MA",
"VAMA | Volatility Adjusted MA", "Modular Filter",
"EIT | Ehlers Instantaneous Trendline", "ESD | Ehlers Simple Decycler",
"SSMA | Shapeshifting MA", "RSRMA | Right Sided Ricker MA",
"DSWF | Damped Sine Wave Weighted Filter", "BMF | Blackman Filter",
"HCF | Hybrid Convolution Filter", "FIR | Finite Response Filter",
"FLSMA | Fisher Least Squares MA", "SVAMA | Non-Parametric Volume Adjusted MA",
"RPMA | Repulsion MA", "WRMA | Well Rounded MA",
"HLT | HiLo Trend", "ADEMA | Alpha-Decreasing EMA",
"AARMA | Adaptive Autonomous Recursive MA"
], group = "Main Settings")
// Display settings
pt_show_sigs = input.bool(title = "Show signals?", defval = false, group = "Display Settings")
pt_color_bars = input.bool(title = "Color bars?", defval = false, group = "Display Settings")
// Specific nuanced settings for different types of moving averages
pt_alma_offset = input.float(title = "Offset", defval = 0.85, step = 0.05, group = "ALMA Settings")
pt_alma_sigma = input.int(title = "Sigma", defval = 6, group = "ALMA Settings")
pt_kama_fastLength = input(title = "Fast EMA Length", defval=2, group = "KAMA Settings")
pt_kama_slowLength = input(title = "Slow EMA Length", defval=30, group = "KAMA Settings")
pt_vama_vol_len = input.int(title = "Volatality Length", defval = 51, group = "VAMA Settings")
pt_vama_do_smth = input.bool(title = "Do Smoothing?", defval = false, group = "VAMA Settings")
pt_vama_smth = input.int(title = "Smoothing length", defval = 5, minval = 1, group = "VAMA Settings")
pt_mf_beta = input.float(title = "Beta", defval = 0.8, step = 0.1, minval = 0, maxval=1, group = "Modular Filter Settings")
pt_mf_feedback = input.bool(title = "Feedback?", defval = false, group = "Modular Filter Settings")
pt_mf_z = input.float(title = "Feedback Weighting", defval = 0.5, step = 0.1, minval = 0, maxval = 1, group = "Modular Filter Settings")
pt_eit_alpha = input.float(title = "Alpha", defval = 0.07, step = 0.01, minval = 0.0, group = "Ehlers Instantaneous Trendline Settings")
pt_ssma_pow = input.float(title = "Power", defval = 4.0, step = 0.5, minval = 0.0, group = "SSMA Settings")
pt_ssma_smooth = input.bool(title = "Smooth", defval = false, group = "SSMA Settings")
pt_rsrma_pw = input.float(title = "Percent Width", defval = 60.0, step = 10.0, minval = 0.0, maxval = 100.0, group = "RSRMA Settings")
pt_svama_method = input.string(title = "Max", options = ["Max", "Min"], defval = "Max", group = "SVAMA Settings")
pt_svama_vol_or_volatility = input.string(title = "Use Volume or Volatility?", options = ["Volume", "Volatility"], defval = "Volatility", group = "SVAMA Settings")
pt_wrma_smooth = input.bool(title = "Extra Smoothing?", defval = false, group = "WRMA Settings")
pt_aarma_gamma = input.float(title = "Gamma", defval = 3.0, minval = 0.0, step = 0.25, group = "AARMA Settings")
//==============================================================================
//==============================================================================
// Calculating Prevailing Trend Upper and Lower lines
//==============================================================================
bullish_candle_range = float(0.0)
bearish_candle_range = float(0.0)
if pt_src > open
bullish_candle_range := pt_src - open
bearish_candle_range := 0.0
else if pt_src < open
bearish_candle_range := open - pt_src
bullish_candle_range := 0.0
else
bullish_candle_range := 0.0
bearish_candle_range := 0.0
pt_up = get_ma_out(pt_ma_type, bullish_candle_range, pt_length, pt_alma_offset, pt_alma_sigma, pt_kama_fastLength, pt_kama_slowLength, pt_vama_vol_len, pt_vama_do_smth, pt_vama_smth, pt_mf_beta, pt_mf_feedback, pt_mf_z, pt_eit_alpha, pt_ssma_pow, pt_ssma_smooth, pt_rsrma_pw, pt_svama_method, pt_svama_vol_or_volatility, pt_wrma_smooth, pt_aarma_gamma)
pt_dn = get_ma_out(pt_ma_type, bearish_candle_range, pt_length, pt_alma_offset, pt_alma_sigma, pt_kama_fastLength, pt_kama_slowLength, pt_vama_vol_len, pt_vama_do_smth, pt_vama_smth, pt_mf_beta, pt_mf_feedback, pt_mf_z, pt_eit_alpha, pt_ssma_pow, pt_ssma_smooth, pt_rsrma_pw, pt_svama_method, pt_svama_vol_or_volatility, pt_wrma_smooth, pt_aarma_gamma)
//==============================================================================
//==============================================================================
// Calculating Prevailing Trend Upper and Lower signals
//==============================================================================
// Only true on the candle that the upper and lower lines cross bullishly, false otherwise
pt_L_trig = ta.crossover(pt_up, pt_dn)
// Only true on the candle that the upper and lower lines cross bearishly, false otherwise
pt_S_trig = ta.crossunder(pt_up, pt_dn)
// True if the upper line is above the lower line
pt_L_conf = pt_up > pt_dn
// True if the lower line is above the upper line
pt_S_conf = pt_up < pt_dn
//==============================================================================
//==============================================================================
// Plotting Prevailing Trend Upper and Lower lines
//==============================================================================
plot(pt_up, title = "Prevailing Trend Upper Line", color = color.blue)
plot(pt_dn, title = "Prevailing Trend Lower Line", color = color.red)
//==============================================================================
//==============================================================================
// Plotting Prevailing Trend signals and coloring bars
//==============================================================================
plotshape(pt_L_trig and pt_show_sigs ? pt_up : na, title = "Prevailing Trend Long Signal", location = location.top, style = shape.triangleup, size = size.tiny, color = color.new(color.green, 30), textcolor = color.new(color.black, 0))
plotshape(pt_S_trig and pt_show_sigs ? pt_up : na, title = "Prevailing Trend Short Signal", location = location.top, style = shape.triangledown, size = size.tiny, color = color.new(color.red, 30), textcolor = color.new(color.black, 0))
pt_barcolor = pt_L_conf ? color.blue : pt_S_conf ? color.red : color.gray
barcolor(pt_color_bars ? pt_barcolor : na, title = "Prevailing Trend Bar Color")
//==============================================================================
//==============================================================================
// Setting up user-activated alerts for Prevailing Trend buy/sell signals
//==============================================================================
alertcondition(pt_L_trig, title = "Prevailing Trend Long Signal", message = "{{ticker}}: Prevailing Trend Indicator signaled to go long at {{time}}.")
alertcondition(pt_S_trig, title = "Prevailing Trend Short Signal", message = "{{ticker}}: Prevailing Trend Indicator signaled to go short at {{time}}.")
//==============================================================================
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(pt_up, pt_dn)
C1_S_Trigger = ta.crossunder(pt_up, pt_dn)
Daily
- 15/close/sma - TP = 1xATR
- 15/close/sma - TP = 2.5xATR
- 9/close/vwma - TP = 1xATR
- 9/close/vwma - TP = 2.0xATR
- 6/close/mm - TP = 1xATR
- 6/close/mm - TP = 2.5xATR
- 21/close/ESD - TP = 2.5xATR
- 31/close/DSWF - TP = 2.5xATR
- 4/close/HCF - TP = 2.5xATR
InteliTrend
// Input settings
// ≡≡≡≡≡≡≡≡ INPUTS & SETTINGS ≡≡≡≡≡≡≡≡
int cci_len = input.int(34, "CCI Length", group = "Commodity Channel Index")
cci_src = input(hlc3, "CCI Source", group = "Commodity Channel Index")
// weighting and smoothing
float c1 = input.float(0.5, title = "c1", group = "Weights & Smoothing")
float c2 = input.float(0.5, title = "c2", group = "Weights & Smoothing")
float c3 = input.float(0.5, title = "c3", group = "Weights & Smoothing")
int p = input.int(6, title = "Smoothing 'p'", group = "Weights & Smoothing")
// moving averages
int ma_len = input(61, title = "MA Length", group = "Moving Averages")
string ma_type = input.string("SMA"
, title = "MA Type"
, options = ["SMA", "SMMA", "EMA", "HMA", "LVMA", "Alma"]
, group = "Moving Averages")
int lvma_wt = input.int(6
, title = "LVMA Weight"
, group = "Moving Averages"
, tooltip = "Only used if LVMA is selected")
float alma_os = input.float(0.86
, title = "Alma Offset"
, maxval = 1
, minval = 0
, group = "Moving Averages"
, tooltip = "Only used if Alma is selected. Lower is smoother, higher is more responsive.")
int alma_sig = input.int(6
, title = "Alma Sigma"
, group = "Moving Averages"
, tooltip = "Only used if Alma is selected. Higher is smoother, lower is more responsive.")
// visual settings
color sfx_css = input.color(defval = color.new(color.orange, 0)
, title = "StableFX"
, group = "Visuals"
, inline = "color")
color ma_css = input.color(defval = color.new(color.red, 0)
, title = "Moving Average"
, group = "Visuals"
, inline = "color")
// ≡≡≡≡≡≡≡≡ FUNCTIONS ≡≡≡≡≡≡≡≡
// calculate linear weighted moving average
get_lwma(src, period, weight) =>
price = src
sub = weight / period - 1
float per = na
float wt = na
float sum = 0
float divider = 0
for i = 0 to period - 1 by 1
per := price[i] * (weight - i - sub)
wt := weight - i - sub
sum += per
divider += wt
divider
sum / divider
// select moving average type
select_ma(src, len, ma_type) =>
switch ma_type
"SMA" => ta.sma(src, len)
"SMMA" => ta.rma(src, len)
"EMA" => ta.ema(src, len)
"HMA" => ta.hma(src, len)
"LVMA" => get_lwma(src, len, lvma_wt)
"Alma" => ta.alma(src, len, alma_os, alma_sig)
// ≡≡≡≡≡≡≡≡ CALCULATIONS ≡≡≡≡≡≡≡≡
// calculate commodity channel index
float cci_val = ta.cci(cci_src, cci_len)
// apply weights to the CCI and store to an array
wts = array.new_float(0, p)
for i = 0 to p - 1
a = cci_val[i] * c1 + cci_val[i] * c2 - cci_val[i] * c3 + cci_val[i] * c2 - cci_val[i] * c3 + cci_val[i] * c2 - cci_val[i] * c3 + cci_val[i] * c2 - cci_val[i] * c3 + cci_val[i] * c2 - cci_val[i] * c3
array.push(wts, a)
// sum the max and min values in the array
cci_wt = array.max(wts) + array.min(wts)
// calculate the moving average
ma = select_ma(cci_wt, ma_len, ma_type)
plot(cci_wt, title = "StableFX", color = sfx_css, editable = false)
plot(ma, title = "Moving Average", color = ma_css, editable = false)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(cci_wt, ma)
C1_S_Trigger = ta.crossunder(cci_wt, ma)
Daily
- 15/close/0.5/0.5/0.5/7/47/ema - TP = 1xATR
Average Sentiment Oscillator
// User inputs
length = input.int(10, title="Period", minval=1, maxval=100)
mode = input.int(0, title="Calculation Method", minval=0, maxval=2)
// Calculation of ranges
intrarange = high - low
grouplow = ta.lowest(low, length)
grouphigh = ta.highest(high, length)
groupopen = open[length - 1]
grouprange = grouphigh - grouplow
// Safeguards for division by zero
K1 = intrarange == 0 ? 1 : intrarange
K2 = grouprange == 0 ? 1 : grouprange
// Bulls and bears calculations
intrabarbulls = ((((close - low) + (high - open)) / 2) * 100) / K1
groupbulls = ((((close - grouplow) + (grouphigh - groupopen)) / 2) * 100) / K2
intrabarbears = ((((high - close) + (open - low)) / 2) * 100) / K1
groupbears = ((((grouphigh - close) + (groupopen - grouplow)) / 2) * 100) / K2
// Mode logic for Bulls and Bears
TempBufferBulls = mode == 0 ? (intrabarbulls + groupbulls) / 2 : mode == 1 ? intrabarbulls : groupbulls
TempBufferBears = mode == 0 ? (intrabarbears + groupbears) / 2 : mode == 1 ? intrabarbears : groupbears
// Simple Moving Averages for Bulls and Bears
ASOBulls = ta.sma(TempBufferBulls, length)
ASOBears = ta.sma(TempBufferBears, length)
// Plotting
plot(ASOBulls, color=color.blue, linewidth=2, title="ASO Bulls")
plot(ASOBears, color=color.red, linewidth=2, title="ASO Bears")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(ASOBulls, ASOBears)
C1_S_Trigger = ta.crossunder(ASOBulls, ASOBears)
Daily
- 7/2 - TP = 1xATR
- 7/2 - TP = 2.5xATR
Correlation Trend
/ User inputs
bgcolor(color.new(#000000,15), title="Dark Background")
cti(Series_1, Period) => // Correlation Trend Function
period = math.max(2, int(Period))
Ex = 0.0, Ey = 0.0, Ex2 = 0.0, Ey2 = 0.0, Exy = 0.0
for i=0 to period-1
X = nz(Series_1[i])
Y = -i
Ex := Ex + X
Ex2 := Ex2 + X * X
Exy := Exy + X * Y
Ey2 := Ey2 + Y * Y
Ey := Ey + Y
denominator = (period * Ex2 - Ex * Ex) * (period * Ey2 - Ey * Ey)
denominator==0.0 or bar_index==0 ? 0.0 : (period * Exy - Ex * Ey) / math.sqrt(denominator)
// Input parameters
source = input.source(close, "Source")
period = input.float(20, "Period", minval=2)
upperLevel = input.float(0.5, "Upper Level", minval=0.05, maxval=1.0, step=0.05)
lowerLevel = input.float(-0.5, "Lower Level", minval=-1.0, maxval=-0.05, step=0.05)
lineThickness = input.int(2, "--- Line Thickness ---", options=[1, 2, 3])
correlationTrend = cti(close, period)
// ===== Levels
hline(upperLevel, color=#FF0000ff, editable=false)
plot( 0.0, color=#FFFF0022, editable=false, linewidth=7, title="Zero")
hline( 0.0, color=#FFFFFFff, editable=false)
hline(lowerLevel, color=#00FF00ff, editable=false)
plot(correlationTrend, color=#0080FF , title="Area", style=plot.style_area, transp=80)
plot(correlationTrend, color=#0080FFff, title= "CT", linewidth=lineThickness)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(correlationTrend, 0)
C1_S_Trigger = ta.crossunder(correlationTrend, 0)
Daily
- close/18/0.5/-0.5 - TP = 1xATR
Trend Intensity Index
// Input parameters
majorLength = input.int(title="Major Length", defval=60)
minorLength = input.int(title="Minor Length", defval=30)
upperLevel = input.int(title="Upper Level", defval=80)
lowerLevel = input.int(title="Lower Level", defval=20)
highlightBreakouts = input.bool(title="Highlight Overbought/Oversold Breakouts?", defval=true)
src = input.source(close, title="Source")
sma = ta.sma(src, majorLength)
positiveSum = 0.0
negativeSum = 0.0
for i = 0 to minorLength - 1
price = nz(src[i])
avg = nz(sma[i])
positiveSum := positiveSum + (price > avg ? price - avg : 0)
negativeSum := negativeSum + (price > avg ? 0 : avg - price)
tii = 100 * positiveSum / (positiveSum + negativeSum)
tiiColor = tii > upperLevel ? #0ebb23 : tii < lowerLevel ? #ff0000 : #f4b77d
plot(tii, title="TII", linewidth=2, color=tiiColor, transp=0)
transparent = color.new(color.white, 100)
maxLevelPlot = hline(100, title="Max Level", linestyle=hline.style_dotted, color=transparent)
upperLevelPlot = hline(upperLevel, title="Upper Level", linestyle=hline.style_dotted)
hline(50, title="Middle Level", linestyle=hline.style_dotted)
lowerLevelPlot = hline(lowerLevel, title="Lower Level", linestyle=hline.style_dotted)
minLevelPlot = hline(0, title="Min Level", linestyle=hline.style_dotted, color=transparent)
fill(upperLevelPlot, lowerLevelPlot, color=color.new(color.purple, 95))
upperFillColor = tii > upperLevel and highlightBreakouts ? color.new(color.green, 10) : transparent
lowerFillColor = tii < lowerLevel and highlightBreakouts ? color.new(color.red, 10) : transparent
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(tii, 50)
C1_S_Trigger = ta.crossunder(tii, 50)
Daily
- 17/7/close - TP = 1xATR
- 17/7/close - TP = 2.5xATR
Forecast Oscillator
// Input parameters
src = input.source(close, title="Source")
len = input.int(defval=14, minval=1, title="Length")
// Linear regression calculations
lrc = ta.linreg(src, len, 0)
lrc1 = ta.linreg(src, len, 1)
lrs = (lrc - lrc1)
TSF = ta.linreg(src, len, 0) + lrs
// Forecast Oscillator calculation
fosc = 100 * (src - TSF[1]) / src
// Color conditions
col12 = fosc > fosc[1]
col32 = fosc < fosc[1]
color2 = col12 ? color.new(#21C400, 0) : col32 ? color.new(#960012, 0) : color.blue
// Plot the Forecast Oscillator
plot(fosc, color=color2, linewidth=2, title="TSF")
// Plot a horizontal line at 0
hline(0, linestyle=hline.style_dotted, color=color.blue)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(fosc, 0)
C1_S_Trigger = ta.crossunder(fosc, 0)
Daily
- close/15 - TP = 1xATR
- close/71- TP = 2.5xATR
PFE (Polarized Fractal Efficiency)
// Input parameters
Length = input.int(9, minval=1)
LengthEMA = input.int(5, minval=1)
TopBand = input.int(50)
LowBand = input.int(-50 )
hline(TopBand, color=color.green, title = "TopBand")
hline(LowBand, color=color.red, title = "LowBand")
PFE = math.sqrt(math.pow(close - close[Length], 2) + 100)
C2C = math.sum(math.sqrt(math.pow((close - close[1]), 2) + 1), Length)
xFracEff = close - close[Length] > 0 ? math.round((PFE / C2C) * 100) : math.round(-(PFE / C2C) * 100)
xEMA = ta.ema(xFracEff, LengthEMA)
if xEMA[1] < TopBand and xEMA > TopBand
alert("Cross TopBand", alert.freq_once_per_bar)
if xEMA[1] > LowBand and xEMA < LowBand
alert("Cross LowBand", alert.freq_once_per_bar)
plot(xEMA, color=color.blue, title="PFE")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(xEMA, 0)
C1_S_Trigger = ta.crossunder(xEMA, 0)
Daily
- 2/6- TP = 1xATR
- 11/7- TP = 1xATR
- 9/9 - TP = 1xATR
- 12/12 - TP = 1xATR
- 5/12 - TP = 1xATR
Doda Stochastic
// Input parameters
// --- Constants --------------------------- //
color grn_clr = #4caf50
color red_clr = #ff5252
color ylw_clr = #ffeb3b
color gry_clr = #787b86
// --- Inputs --------------------------- //
ma_src = input.source(defval=close, title="MA Source", tooltip="Default : Close")
ma_len = input.int(defval=8, title="MA Length", tooltip="Default : 8")
minmax_len = input.int(defval=13, title="Min Max Lookback", tooltip="Default : 13")
doda_ma_len = input.int(defval=9, title="Doda MA Length", tooltip="Default : 9")
lo_line = input.float(defval=21., title="Low-Mid-High Level", inline="lvls")
mid_line = input.float(defval=55., title="", inline="lvls")
hi_line = input.float(defval=89., title="", inline="lvls")
// --- Calculations --------------------------- //
ma = ta.ema(ma_src, ma_len)
minval = ta.lowest(ma, minmax_len)
maxval = ta.highest(ma, minmax_len)
stoch = (maxval - minval != 0) ? 100. * (ma - minval) / (maxval - minval) : 0.0
doda = ta.ema(stoch, ma_len)
doda_ma = ta.ema(doda, doda_ma_len)
// --- Charting --------------------------- //
plot(doda, title="Doda", color=grn_clr, linewidth=2, display=display.all)
plot(doda_ma, title="Doda Signal", color=red_clr, linewidth=2, display=display.all)
plot(stoch, title="Stochastic", color=ylw_clr, linewidth=1, display=display.none)
hline(price=lo_line, title="Lo-Line", color=gry_clr, linestyle=hline.style_dashed, linewidth=1, editable=true, display=display.all)
hline(price=mid_line, title="Mid-Line", color=gry_clr, linestyle=hline.style_dotted, linewidth=1, editable=true, display=display.all)
hline(price=hi_line, title="Hi-Line", color=gry_clr, linestyle=hline.style_dashed, linewidth=1, editable=true, display=display.all)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(doda, 50)
C1_S_Trigger = ta.crossunder(doda, 50)
Daily
- close/6/13/9 - TP = 1xATR
- close/8/9/9 - TP = 1xATR
- close/10/8/9 - TP = 1xATR
- hlc3/7/13/9 - TP = 1xATR
- close/8/9/9 - TP = 2.5xATR
Chartmill Value
// Input parameters
length = input.int(3, title="Length")
vc = ta.sma(hl2, length)
useModifiedFormula = input.bool(false, title="Use Modified Formula")
os1 = input.float(-0.51, title="Oversold 1")
ob1 = input.float(0.43, title="Overbought 1")
// Denominator calculation
denom = useModifiedFormula ? (ta.atr(length) * math.sqrt(length)) : ta.atr(length)
// CVI calculation
cvi = (close - vc) / denom
// Plot oversold and overbought levels
plot(os1, color=color.green, title="Oversold 1")
plot(ob1, color=color.red, title="Overbought 1")
// Uncomment to enable additional oversold/overbought levels
// os2 = input.float(-1.5, title="Oversold 2")
// ob2 = input.float(1.5, title="Overbought 2")
// plot(os2, color=color.green, style=plot.style_dashed)
// plot(ob2, color=color.red, style=plot.style_dashed)
// Plot CVI
plot(cvi, color=color.blue, linewidth=2, title="CVI")
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(cvi, 0)
C1_S_Trigger = ta.crossunder(cvi, 0)
Daily
- 40 - TP = 1xATR
Kuskus Starlight
// Input parameters
length = input.int(30, title="Length Periods")
pricesmoothing = input.float(0.3, title="Price Smoothing",step=0.1)
indexsmoothing = input.float(0.3, title="Index Smoothing",step=0.1)
var float greatestrange = na
var float extmapbuffer = na
var float extmapbuffer1 = na
// Highest high and lowest low over the length
highesthigh = ta.highest(high, length)
lowestlow = ta.lowest(low, length)
// Greatestrange calculation
greatestrange := (highesthigh - lowestlow) != 0 ? (highesthigh - lowestlow) : nz(greatestrange[1])
// Mid price
midprice = (high + low) / 2
// Pricelocation calculation
pricelocation = 2 * ((midprice - lowestlow) / greatestrange) - 1
// Smoothing of pricelocation
extmapbuffer := pricesmoothing * nz(extmapbuffer[1]) + (1 - pricesmoothing) * pricelocation
smoothedlocation = math.min(math.max(extmapbuffer, -0.99), 0.99)
// Fisher location calculation
fishindex = math.log((1 + smoothedlocation) / (1 - smoothedlocation))
// Smoothing of Fisher index
extmapbuffer1 := indexsmoothing * nz(extmapbuffer1[1]) + (1 - indexsmoothing) * fishindex
smoothedfish = extmapbuffer1
// Plot the smoothed fisher index as a histogram with conditional coloring
plot(smoothedfish, color=(smoothedfish > 0 ? color.green : color.red), linewidth=3, style=plot.style_histogram)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(smoothedfish, 0)
C1_S_Trigger = ta.crossunder(smoothedfish, 0)
Daily
- 10/0.3/0.3 - TP = 1xATR
- 10/0.6/0.3 - TP = 1xATR
Linear Regression Slope
// Input parameters
length = input.int(20, title="Slope length")
src = input(close, title="Source")
slopeAbsThreshold = input.float(0.0, title="Slope Absolute Value threshold", minval=0, step=0.1)
//alexgrover's linreg formula
x = bar_index
y = src
x_ = ta.sma(x,length)
y_ = ta.sma(y,length)
mx = ta.stdev(x,length)
my = ta.stdev(y,length)
c = ta.correlation(x,y,length)
slope = c * (my/mx)
//inter = y_ - slope*x_
//reg = x*slope + inter
trend = math.abs(slope)>slopeAbsThreshold
rising = slope>slope[1]
falling = slope<slope[1]
up = slope>0
down = slope<0
up_rising_color = color.new(color.green, 0)
up_falling_color = color.new(color.green, 50)
down_falling_color = color.new(color.red, 0)
down_rising_color = color.new(color.red, 50)
col = trend and up and rising?up_rising_color:trend and up and falling?up_falling_color:trend and down and falling?down_falling_color:trend and down and rising?down_rising_color : color.gray
plot(slope, title="Linear regression slope", style=plot.style_histogram, color = col, linewidth=3)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(slope, 0)
C1_S_Trigger = ta.crossunder(slope, 0)
Dorsey Inertia
// Input parameters
stdevLength = input.int(title="Standard Deviation Length", defval=21)
rviSmoothLength = input.int(title="RVI Smoothing Length", defval=14)
smoothLength = input.int(title="Inertia Smoothing Length", defval=14)
// Relative Volatility Index (1993)
rviOriginal(src, stdevLength, smoothLength) =>
stdev = ta.stdev(src, stdevLength)
upSum = ta.ema(ta.change(src) >= 0 ? stdev : 0, smoothLength)
downSum = ta.ema(ta.change(src) >= 0 ? 0 : stdev, smoothLength)
100 * upSum / (upSum + downSum)
// Calculate RVI
rviHigh = rviOriginal(high, stdevLength, rviSmoothLength)
rviLow = rviOriginal(low, stdevLength, rviSmoothLength)
rvi = (rviHigh + rviLow) / 2
// Inertia calculation using linear regression
inertia = ta.linreg(rvi, smoothLength, 0)
// Inertia color based on value
inertiaColor = inertia > 50 ? color.new(color.lime, 0) : color.new(color.red, 0)
// Plot inertia and middle level
plot(inertia, title="Inertia", linewidth=2, color=inertiaColor)
hline(50, title="Middle Level", linestyle=hline.style_dotted)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(inertia, 50)
C1_S_Trigger = ta.crossunder(inertia, 50)
Daily
- 20/10/11 - TP = 1xATR
- 20/13/10 - TP = 2.5xATR
Derivative Oscillator
// Input parameters
length=input.int(14, title="RSI Length")
horiz1=input.int(7, title = "Horizontal Line 1")
horiz2=input.int(-7, title = "Horizontal Line 2")
p=input.int(9,title="SMA length")
ema1=input.int(5,title="EMA1 length")
ema2=input.int(3,title="EMA2 length")
var float s1 = na
var float s2 = na
s1:=ta.ema(ta.ema(ta.rsi(close, length), ema1),ema2)
s2:=s1 - ta.sma(s1,p)
c_color=s2 < 0 ? (s2 < s2[1] ? color.red : color.lime) : (s2 >= 0 ? (s2 > s2[1] ? color.lime : color.red) : na)
plot(s2 , style=plot.style_histogram, color=c_color, linewidth = 3)
band1 = hline(horiz1, color=color.blue)
band0 = hline(horiz2, color=color.blue)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(s2, 0)
C1_S_Trigger = ta.crossunder(s2, 0)
Daily
- 14/7/-7/10/8/5 - TP = 1xATR
- 14/7/-7/10/8/5 - TP = 2.5ATR
Double Smoothed Momentum
// Input parameters
aLength = input.int(title="ALength", defval=2, minval=1)
yLength = input.int(title="YLength", defval=5, minval=1)
zLength = input.int(title="ZLength", defval=25, minval=1)
inp = input.source(title="Source", defval=close)
res = input.timeframe(title="Resolution", defval="")
rep = input.bool(title="Allow Repainting?", defval=false)
bar = input.bool(title="Allow Bar Color Change?", defval=true)
src = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
hc = ta.highest(src, aLength)
lc = ta.lowest(src, aLength)
top = ta.ema(ta.ema(src - lc, yLength), zLength)
bot = ta.ema(ta.ema(hc - lc, yLength), zLength)
mom = bot != 0 ? 100 * top / bot : 0
momEma = ta.ema(mom, zLength)
sig = mom > momEma ? 1 : mom < momEma ? -1 : 0
alertcondition(ta.crossover(sig, 0), title="Buy Signal", message="Bullish Change Detected")
alertcondition(ta.crossunder(sig, 0), title="Sell Signal", message="Bearish Change Detected")
momColor = sig > 0 ? color.green : sig < 0 ? color.red : color.black
barcolor(bar ? momColor : na)
plot(mom, color=momColor, linewidth=2)
plot(momEma, color=color.black, linewidth=1)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(mom, momEma)
C1_S_Trigger = ta.crossunder(mom, momEma)
Daily
- 2/5/26/close - TP = 1xATR
- 2/5/26/close - TP = 2.5xATR
Ehlers Smoothed Adaptive Momentum
// Input parameters
src = input(hl2, title="Source")
a = input(0.07, title="Alpha")
co = input(8.0, title="Cutoff")
var float c = na
var float q1 = na
var float ip = na
var float p = na
var float f3 = na
pi = math.pi
dtr = pi / 180.0
rtd = 1 / dtr
s = (src + 2 * src[1] + 2 * src[2] + src[3]) / 6.0
c := nz(((1 - 0.5 * a) * (1 - 0.5 * a) * (s - 2 * nz(s[1]) + nz(s[2])) + 2 * (1 - a) * nz(c[1]) - (1 - a) * (1 - a) * nz(c[2])), (src - 2 * src[1] + src[2]) / 4.0)
q1 := (0.0962 * c + 0.5769 * nz(c[2]) - 0.5769 * nz(c[4]) - 0.0962 * nz(c[6])) * (0.5 + 0.08 * nz(ip[1]))
I1 = nz(c[3])
dp_ = (q1 != 0 and q1[1] != 0) ? ((I1 / q1 - nz(I1[1]) / nz(q1[1])) / (1 + I1 * nz(I1[1]) / (q1 * nz(q1[1])))) : 0
dp = dp_ < 0.1 ? 0.1 : (dp_ > 1.1 ? 1.1 : dp_)
med(x, y, z) => (x + y + z) - math.min(x, math.min(y, z)) - math.max(x, math.max(y, z))
md = med(dp, dp[1], med(dp[2], dp[3], dp[4]))
dc = md == 0 ? 15 : 2 * pi / md + 0.5
ip := 0.33 * dc + 0.67 * nz(ip[1])
p := 0.15 * ip + 0.85 * nz(p[1])
pr = math.round(math.abs(p - 1))
vx = array.new_float(76)
for i = 1 to 75
array.set(vx, i, ta.valuewhen(pr == i, src - src[i], 0))
v1 = array.get(vx, 75)
a1 = math.exp(-pi / co)
b1 = 2.0 * a1 * math.cos((1.738 * 180 / co) * dtr)
c1 = a1 * a1
coef2 = b1 + c1
coef3 = -(c1 + b1 * c1)
coef4 = c1 * c1
coef1 = 1 - coef2 - coef3 - coef4
f3 := nz(coef1 * v1 + coef2 * nz(f3[1]) + coef3 * nz(f3[2]) + coef4 * nz(f3[3]), v1)
ml = plot(0, color=color.gray, title="ZeroLine")
pl = plot(f3 > 0 ? f3 : 0, title="DummyP", color=color.gray, linewidth=0, style=plot.style_circles)
nl = plot(f3 < 0 ? f3 : 0, title="DummyN", color=color.gray, linewidth=0, style=plot.style_circles)
plot(f3, title="Ehlers SAMI", color=color.black, linewidth=2)
fill(pl, ml, color.green, title="PositiveFill", transp=70)
fill(nl, ml, color.red, title="NegativeFill", transp=70)
ebc = input(false, title="Enable bar colors")
bc = ebc ? (f3 > 0 ? (f3 > nz(f3[1]) ? color.lime : color.green) : (f3 < f3[1] ? color.red : color.orange)) : na
barcolor(bc)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(f3, 0)
C1_S_Trigger = ta.crossunder(f3, 0)
Daily
- hl2/0.04/8 - TP = 1xATR
Glitch Index
// Input parameters
import TradingView/ta/7 as ta
f_zlsma(float src, simple int length, simple int offset = 0) =>
lsma = ta.linreg(src, length, offset)
lsma2 = ta.linreg(lsma, length, offset)
eq = lsma - lsma2
zlsma = lsma + eq
zlsma
getAverageName(float src, simple string inp, simple int length) =>
switch inp
"SMA" => ta.sma(src, length)
"EMA" => ta.ema(src, length)
"SWMA" => ta.swma(src)
"DEMA" => ta.dema(src, length)
"TEMA" => ta.tema(src, length)
"LSMA" => ta.linreg(src, length, 0)
"ZLSMA" => f_zlsma(src, length)
=> ta.sma(src, length)
priceSet(simple string inp) =>
switch inp
"Close" => close
"Open" => open
"High" => high
"Low" => low
"Median" => hl2
"Typical" => hlc3
"Weighted" => hlcc4
"Average" => ohlc4
"Avg Median Body" => (open + close) / 2
"Trend Biased Price" => close > open ? (high+close) / 2 : (low+close) / 2
"Trend Biased Extreme Price" => close > open ? high : low
=> close
// Inputs
MaPeriod = input.int(30, "Ma Period")
MaMethod = input.string("SMA", title="MA Method", options=["SMA", "EMA", "SWMA", "DEMA", "TEMA", "LSMA", "ZLSMA"])
priceType = input.string("Median", "Source", options=["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Avg Median Body", "Trend Biased Price", "Trend Biased Extreme Price"])
innerLevel = input.float(2.0, "Inner Level")
outterLevel = input.float(5.0, "Outter Level")
colorType = input.string("Gradient", title="Coloring Type", options=["Gradient", "Threshold Based"])
// Glitch Index Calculations
price = priceSet(priceType)
_ma = getAverageName(price, MaMethod, MaPeriod)
rocma = ((_ma - _ma[1]) * 0.1) + 1
maMul = _ma * rocma
diff = price - maMul
gli_ind = (diff / price) * -10
// Glitch Index Coloring
gli_col = gli_ind > outterLevel ? color.green : gli_ind < -outterLevel ? color.red : gli_ind > innerLevel ? color.rgb(106, 185, 109, 57) : gli_ind < -innerLevel ? color.rgb(233, 111, 111, 40) : color.new(color.yellow, 60)
gradcol = color.from_gradient(gli_ind, -outterLevel, outterLevel, color.red, color.green)
colorSelect = colorType == "Gradient" ? gradcol : gli_col
// Main Plot
plot(gli_ind, title="Gli Index", color= colorSelect, style=plot.style_columns)
plot(gli_ind, title="Gli Index Line", color= colorSelect, style=plot.style_line, linewidth = 2)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(gli_ind, 0)
C1_S_Trigger = ta.crossunder(gli_ind, 0)
// //REVERSE indicator conditions as Trigger
// C1_L_Trigger = ta.crossunder(gli_ind, 0)
// C1_S_Trigger = ta.crossover(gli_ind, 0)
Daily
- 30/sma/avg median body/2/5 REVERSE - TP = 1xATR
- 85/sma/avg median body/2/5 REVERSE - TP = 1xATR
- 29/ema/median/2/5 - TP = 1xATR
Price Momentum Oscillator
// Input parameters
firstLength = input.int(title="1st Smoothing Length", defval=35)
secondLength = input.int(title="2nd Smoothing Length", defval=20)
signalLength = input.int(title="Signal Length", defval=10)
src = input.source(title="Source", defval=close)
highlightCrossovers = input.bool(title="Highlight PMO/Signal Crossovers ?", defval=false)
highlightZeroCrossovers = input.bool(title="Highlight Zero Line Crossovers ?", defval=false)
applyFilling = input.bool(title="Apply Ribbon Filling ?", defval=false)
pmo = ta.ema(10 * ta.ema(nz(ta.roc(src, 1)), firstLength), secondLength)
signal = ta.ema(pmo, signalLength)
trendColor = pmo > signal ? color.new(#0ebb23, 0) : color.new(color.red, 0)
pmoColor = applyFilling ? trendColor : color.new(#0094ff, 0)
signalColor = applyFilling ? trendColor : color.new(#ff6a00, 0)
pmoPlot = plot(pmo, title="PMO", color=pmoColor)
signalPlot = plot(signal, title="Signal", color=signalColor)
hline(0, title="Zero Line", linestyle=hline.style_dotted)
transparent = color.new(color.white, 100)
fillColor = applyFilling ? trendColor : transparent
fill(pmoPlot, signalPlot, color=fillColor, transp=70)
zeroCrossBgColor = highlightZeroCrossovers ? (pmo > 0 ? color.new(color.green, 10) : color.new(color.red, 10)) : transparent
bgcolor(zeroCrossBgColor)
plotshape(ta.crossover(pmo, signal) and highlightCrossovers ? pmo : na, title="Crossover", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green)
plotshape(ta.crossunder(pmo, signal) and highlightCrossovers ? pmo : na, title="Crossunder", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red)
//Insert indicator conditions as Trigger
C1_L_Trigger = ta.crossover(pmo, signal)
C1_S_Trigger = ta.crossunder(pmo, signal)
Daily
- 35/20/9 - TP = 1xATR
- 35/20/9 - TP = 2.5xATR
- 21/20/9 - TP = 2.5xATR