Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

//@version=5

indicator("Combined Indicator", shorttitle="Combined Ind", overlay=true)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Indicateur 1 : Range Filter - B&S Signals
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Range Size Function


rng_size(x, qty, n) =>
wper = (n * 2) - 1
avrng = ta.ema(math.abs(x - x[1]), n)
AC = ta.ema(avrng, wper) * qty
AC

// Range Filter Function


rng_filt(x, rng_, n) =>
r = rng_
var rfilt = array.new_float(2, x)
array.set(rfilt, 1, array.get(rfilt, 0))
if x - r > array.get(rfilt, 1)
array.set(rfilt, 0, x - r)
if x + r < array.get(rfilt, 1)
array.set(rfilt, 0, x + r)
rng_filt1 = array.get(rfilt, 0)
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
[hi_band, lo_band, rng_filt]

// Inputs for Range Filter


rng_src = input.source(defval=close, title="Swing Source")
rng_per = input.int(defval=20, minval=1, title="Swing Period")
rng_qty = input.float(defval=3.5, minval=0.0000001, title="Swing Multiplier")

// Range Filter Values


[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per),
rng_per)

// Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0

// Trading Conditions
longCond = (rng_src > filt and rng_src > rng_src[1] and upward > 0) or (rng_src >
filt and rng_src < rng_src[1] and upward > 0)
shortCond = (rng_src < filt and rng_src < rng_src[1] and downward > 0) or (rng_src
< filt and rng_src > rng_src[1] and downward > 0)

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

// Plot Buy and Sell Labels


plotshape(longCondition, title="Buy Signal", text="BUY", textcolor=color.white,
style=shape.labelup, size=size.normal, location=location.belowbar,
color=color.new(color.green, 0))
plotshape(shortCondition, title="Sell Signal", text="SELL", textcolor=color.white,
style=shape.labeldown, size=size.normal, location=location.abovebar,
color=color.new(color.red, 0))

// Alerts
alertcondition(longCondition, title="Buy Alert", message="BUY")
alertcondition(shortCondition, title="Sell Alert", message="SELL")

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Indicateur 2 : Multi-Spectral RSI Deviations [AlgoAlpha]
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Inputs for Multi-Spectral RSI


upColor = input.color(#00ffbb, "Up Colour")
downColor = input.color(#ff1100, "Down Colour")
len = input.int(7, "RSI Length 1", minval=1)
len1 = input.int(14, "RSI Length 2", minval=1)
len2 = input.int(35, "RSI Length 3", minval=1)
slen = input.int(20, "Smoothing Length", minval=1)

// RSI values
v1 = ta.rsi(close, len)
v2 = ta.rsi(close, len1)
v3 = ta.rsi(close, len2)
x = v1 - v2
x1 = v2 - v3
f = ta.hma(math.avg(x, x1), slen)

// Plot Bullish and Bearish Reversal


plotchar(ta.crossover(f, f[1]) and f[1] < -10, title="MS-RSI Bullish Reversal",
char="▲", location=location.belowbar, color=upColor, size=size.tiny)
plotchar(ta.crossunder(f, f[1]) and f[1] > 10, title="MS-RSI Bearish Reversal",
char="▼", location=location.abovebar, color=downColor, size=size.tiny)

// Alerts for Bullish and Bearish Reversal


alertcondition(ta.crossover(f, f[1]) and f[1] < -10, title="MS-RSI Bullish Reversal
Alert", message="MS-RSI Bullish Reversal")
alertcondition(ta.crossunder(f, f[1]) and f[1] > 10, title="MS-RSI Bearish Reversal
Alert", message="MS-RSI Bearish Reversal")
indicateur avec siganl inversee

//@version=5
indicator("Combined Indicator", shorttitle="Combined Ind", overlay=true)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Indicateur 1 : Range Filter - B&S Signals
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Range Size Function


rng_size(x, qty, n) =>
wper = (n * 2) - 1
avrng = ta.ema(math.abs(x - x[1]), n)
AC = ta.ema(avrng, wper) * qty
AC

// Range Filter Function


rng_filt(x, rng_, n) =>
r = rng_
var rfilt = array.new_float(2, x)
array.set(rfilt, 1, array.get(rfilt, 0))
if x - r > array.get(rfilt, 1)
array.set(rfilt, 0, x - r)
if x + r < array.get(rfilt, 1)
array.set(rfilt, 0, x + r)
rng_filt1 = array.get(rfilt, 0)
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
[hi_band, lo_band, rng_filt]
// Inputs for Range Filter
rng_src = input.source(defval=close, title="Swing Source")
rng_per = input.int(defval=20, minval=1, title="Swing Period")
rng_qty = input.float(defval=3.5, minval=0.0000001, title="Swing Multiplier")

// Range Filter Values


[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per),
rng_per)

// Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0

// Trading Conditions
longCond = (rng_src > filt and rng_src > rng_src[1] and upward > 0) or (rng_src >
filt and rng_src < rng_src[1] and upward > 0)
shortCond = (rng_src < filt and rng_src < rng_src[1] and downward > 0) or (rng_src
< filt and rng_src > rng_src[1] and downward > 0)

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

// Plot Buy and Sell Labels


plotshape(longCondition, title="Buy Signal", text="BUY", textcolor=color.white,
style=shape.labelup, size=size.normal, location=location.belowbar,
color=color.new(color.green, 0))
plotshape(shortCondition, title="Sell Signal", text="SELL", textcolor=color.white,
style=shape.labeldown, size=size.normal, location=location.abovebar,
color=color.new(color.red, 0))

// Alerts
alertcondition(longCondition, title="Buy Alert", message="BUY")
alertcondition(shortCondition, title="Sell Alert", message="SELL")

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Indicateur 2 : Multi-Spectral RSI Deviations [AlgoAlpha]
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Inputs for Multi-Spectral RSI


upColor = input.color(#00ff00, "Bullish Colour") // Green for Bullish
downColor = input.color(#ff0000, "Bearish Colour") // Red for Bearish
len = input.int(7, "RSI Length 1", minval=1)
len1 = input.int(14, "RSI Length 2", minval=1)
len2 = input.int(35, "RSI Length 3", minval=1)
slen = input.int(20, "Smoothing Length", minval=1)

// RSI values
v1 = ta.rsi(close, len)
v2 = ta.rsi(close, len1)
v3 = ta.rsi(close, len2)
x = v1 - v2
x1 = v2 - v3
f = ta.hma(math.avg(x, x1), slen)

// Inverted Plot Bullish and Bearish Reversal


inverted_bullish_reversal = ta.crossunder(f, f[1]) and f[1] > 10
inverted_bearish_reversal = ta.crossover(f, f[1]) and f[1] < -10

plotshape(inverted_bullish_reversal, title="MS-RSI Inverted Bullish Reversal",


style=shape.triangleup, location=location.belowbar, color=upColor, size=size.tiny)
plotshape(inverted_bearish_reversal, title="MS-RSI Inverted Bearish Reversal",
style=shape.triangledown, location=location.abovebar, color=downColor,
size=size.tiny)

// Alerts for Inverted Bullish and Bearish Reversal


alertcondition(inverted_bullish_reversal, title="MS-RSI Inverted Bullish Reversal
Alert", message="MS-RSI Inverted Bullish Reversal")
alertcondition(inverted_bearish_reversal, title="MS-RSI Inverted Bearish Reversal
Alert", message="MS-RSI Inverted Bearish Reversal")

You might also like