0% found this document useful (0 votes)
52 views7 pages

Macd Rsi

This document contains a TradingView script that implements a technical analysis indicator combining MACD, RSI, and Stochastic Oscillator with divergence detection. It allows users to customize various parameters, such as the lengths for moving averages and the display options for signals and lines. The script is designed to visualize market trends and potential reversal points based on the selected indicators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views7 pages

Macd Rsi

This document contains a TradingView script that implements a technical analysis indicator combining MACD, RSI, and Stochastic Oscillator with divergence detection. It allows users to customize various parameters, such as the lengths for moving averages and the display options for signals and lines. The script is designed to visualize market trends and potential reversal points based on the selected indicators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © fikira
//@version=5
indicator('MACD, RSI & Stoch + Divergences ', shorttitle='MRS + DIV',
max_lines_count=500, max_labels_count=500, max_bars_back=5000, overlay=false)

//study("MACD DEMA", shorttitle='MACD DEMA')


// by ToFFF
sma = input(12, title='DEMA Courte')
lma = input(26, title='DEMA Longue')
tsp = input(9, title='Signal')
dolignes = input(true, title="Lignes")

MMEslowa = ta.ema(close, lma)


MMEslowb = ta.ema(MMEslowa, lma)
DEMAslow = ((2 * MMEslowa) - MMEslowb)

MMEfasta = ta.ema(close, sma)


MMEfastb = ta.ema(MMEfasta, sma)
DEMAfast = ((2 * MMEfasta) - MMEfastb)

LigneMACDZeroLag = (DEMAfast - DEMAslow)

MMEsignala = ta.ema(LigneMACDZeroLag, tsp)


MMEsignalb = ta.ema(MMEsignala, tsp)
Lignesignal = ((2 * MMEsignala) - MMEsignalb)

MACDZeroLag = (LigneMACDZeroLag - Lignesignal)

swap1 = MACDZeroLag > 0 ? color.green : color.red

plot(MACDZeroLag, color=swap1, style=plot.style_columns, title='Histo')


p1 = plot(dolignes ? LigneMACDZeroLag : na, color=color.blue, title='LigneMACD')
p2 = plot(dolignes ? Lignesignal : na, color=color.red, title='Signal')
fill(p1, p2, color=#2195f32c)
hline(50)

i_hi = input.string('high', title='', group='source [high - low]' ,


inline='hl' , options=['high', 'close', 'max open/close'] )
i_lo = input.string('low' , title='', group='source [high - low]' ,
inline='hl' , options=['low' , 'close', 'min open/close'] )
left = input.int ( 10 , 'left ' ,
inline='l' )
iBl_Reg = input.bool(true , 'Bullish Regular DIV ' ,
inline='a' ), iColBl_Reg = input.color(color.lime, '', inline='a')
iBl_Hid = input.bool(false, 'Bullish Hidden DIV ' ,
inline='b' ), iColBl_Hid = input.color(color.gray, '', inline='b')
iBr_Reg = input.bool(true , 'Bearish Regular DIV' ,
inline='c' ), iColBr_Reg = input.color(color.red , '', inline='c')
iBr_Hid = input.bool(false, 'Bearish Hidden DIV ' ,
inline='d' ), iColBr_Hid = input.color(color.gray, '', inline='d')
show = input.string('rsi', 'show ', options
= ['rsi', 'stoch', 'macd', 'hist', 'none'] , group='settings',
inline='s' )
src = input(close, title='Source', group='settings')
lenrsi = input.int ( 14, title='rsi ', group='settings',
inline='rsi' )
lenK = input.int ( 14, title='stoch ' , group='settings',
inline='stoch')
smoothK = input.int ( 3, title='' , group='settings',
inline='stoch')
smoothD = input.int ( 3, title='' , group='settings',
inline='stoch')
fastLen = input.int ( 12, title='macd ' , group='settings',
inline='macd' )
slowLen = input.int ( 26, title='' , group='settings',
inline='macd' )
signLen = input.int ( 9, title='' , group='settings',
inline='macd' )

maxBack = input.int (1000, 'Lookback', minval=500, maxval=2000, tooltip='lines can


be max x bars long')
bars = math.max (maxBack + 1, input.int (1000 , 'only last ',
inline='bars', minval=500, maxval=5000))
last_b = input.bool(true, 'bars (=faster)', inline='bars')
frstPiv = input.bool(true, 'left osc point must be a Pivot Point')

lines = input.bool(true , title="Show Lines")


arrows = input.bool(false, title="Show Arrows")
symbl = input.string(title="Style", defval="Label", group='Labels', options
= ["Label", "Arrow", "Triangle", "Circle", "Square", "Xcross", "Cross",
"Flag", "Diamond"])
size = input.string(title="Label Size", defval="Auto", group='Labels', options
= ["Tiny", "Small", "Normal", "Auto"])

hi = i_hi == 'high' ? high : i_hi == 'close' ? close : math.max(open, close)


lo = i_lo == 'low' ? low : i_hi == 'close' ? close : math.min(open, close)

rsi = ta.rsi(src, lenrsi)


k = ta.sma(ta.stoch(rsi, rsi, rsi, lenK), smoothK)
d = ta.sma(k, smoothD)
islast_b = last_b ? last_bar_index - bar_index < bars : true

[macd, sign, hist] = ta.macd(close, fastLen, slowLen, signLen)

sBull = label.style_label_up
sBear = label.style_label_down
_size = size.auto

switch symbl
"Label" => sBull := label.style_label_up , sBear := label.style_label_down
"Arrow" => sBull := label.style_arrowup , sBear := label.style_arrowdown
"Triangle" => sBull := label.style_triangleup, sBear :=
label.style_triangledown
"Circle" => sBull := label.style_circle , sBear := label.style_circle
"Square" => sBull := label.style_square , sBear := label.style_square
"Xcross" => sBull := label.style_xcross , sBear := label.style_xcross
"Cross" => sBull := label.style_cross , sBear := label.style_cross
"Flag" => sBull := label.style_flag , sBear := label.style_flag
"Diamond" => sBull := label.style_diamond , sBear := label.style_diamond

switch size
"Tiny" => _size := size.tiny
"Small" => _size := size.small
"Normal" => _size := size.normal
"Auto" => _size := size.auto

osc =
switch show
'rsi' => rsi
'stoch' => k
'macd' => macd
'hist' => hist
=> na

ph = ta.pivothigh(hi, left, 1)
pl = ta.pivotlow (lo, left, 1)

//
drawWhenPh(osc) =>
if ph and islast_b
for i = 2 to maxBack
if nz(hi[i], hi) > nz(hi[i +1], hi) and nz(hi[i], hi) > nz(hi[i -1],
hi)
broken = false
testline = line.new(bar_index - i, nz(hi[i], hi), bar_index -1, ph)
for j = 1 to i
if hi[j] > line.get_price(testline, bar_index - j)
broken := true
break
if broken == false
maxOSCp1 = math.max(osc[i], osc[i+1], osc[i+2])
idx1 = maxOSCp1 == osc[i] ? i : maxOSCp1 == osc[i+1] ?
i+1 : i+2
maxOSCp2 = 0. //math.max(osc , osc[ 1], osc[ 2])
idx2 = 0 //maxOSCp2 == osc ? 0 : maxOSCp2 == osc[ 1] ?
1 : 2
//
isHgst1 = osc[1] > osc and osc[1] > osc[2]
isHgst2 = osc[2] > osc[1] and osc[2] > osc[3]
maxOSCp2 := isHgst1 ? osc[1] : isHgst2 ? osc[2] : na
idx2 := isHgst1 ? 1 : isHgst2 ? 2 : na
//
x1 = bar_index - idx1
y1 = maxOSCp1
x2 = bar_index - idx2
y2 = maxOSCp2
if isHgst1 or isHgst2
testln2_OSC = frstPiv ? line.new(x1 - left, y1 - ((y2 - y1)
/ (x2 - x1) * left), x2, y2) : line.new(x1, y1, x2, y2)
for l = 1 to frstPiv ? i + left : i
if osc[l] > line.get_price(testln2_OSC, bar_index - l)
broken := true
break
if broken == false
if iBr_Hid and maxOSCp2 > maxOSCp1 and ph < nz(hi[i],
hi)
if arrows
label.new(bar_index - idx2, maxOSCp2,
style=sBear, color=iColBr_Hid, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, maxOSCp1, bar_index
- idx2, maxOSCp2, color=color.gray)
if iBr_Reg and maxOSCp2 < maxOSCp1 and ph > nz(hi[i],
hi)
if arrows
label.new(bar_index - idx2, maxOSCp2,
style=sBear, color=iColBr_Reg, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, maxOSCp1, bar_index
- idx2, maxOSCp2, color=color.red )
line.delete(testln2_OSC)
line.delete(testline)
//
if ph[1] and islast_b
for i = 3 to maxBack
if nz(hi[i], hi) > nz(hi[i +1], hi) and nz(hi[i], hi) > nz(hi[i -1],
hi)
broken = false
testline = line.new(bar_index - i, nz(hi[i], hi), bar_index -2,
ph[1])
for j = 2 to i
if hi[j] > line.get_price(testline, bar_index - j)
broken := true
break
if broken == false
maxOSCp1 = math.max(osc[i], osc[i+1], osc[i+2])
idx1 = maxOSCp1 == osc[i] ? i : maxOSCp1 == osc[i+1] ?
i+1 : i+2
maxOSCp2 = 0.
idx2 = 0
isHgst1 = osc[1] > osc and osc[1] > osc[2]
maxOSCp2 := isHgst1 ? osc[1] : na
idx2 := isHgst1 ? 1 : na
x1 = bar_index - idx1
y1 = maxOSCp1
x2 = bar_index - idx2
y2 = maxOSCp2
if isHgst1
testln2_OSC = frstPiv ? line.new(x1 - left, y1 - ((y2 - y1)
/ (x2 - x1) * left), x2, y2) : line.new(x1, y1, x2, y2)
for l = 2 to frstPiv ? i + left : i
if osc[l] > line.get_price(testln2_OSC, bar_index - l)
broken := true
break
if broken == false
if iBr_Hid and maxOSCp2 > maxOSCp1 and ph[1] < nz(hi
[i], hi )
if arrows
label.new(bar_index - idx2, maxOSCp2,
style=sBear, color=iColBr_Hid, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, maxOSCp1, bar_index
- idx2, maxOSCp2, color=color.gray)
if iBr_Reg and maxOSCp2 < maxOSCp1 and ph[1] > nz(hi
[i], hi )
if arrows
label.new(bar_index - idx2, maxOSCp2,
style=sBear, color=iColBr_Reg, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, maxOSCp1, bar_index
- idx2, maxOSCp2, color=color.red )
line.delete(testln2_OSC)
line.delete(testline)

//
drawWhenPl(osc) =>
if pl and islast_b
for i = 1 to maxBack
if nz(lo [i], lo ) < nz(lo [i +1], lo ) and nz(lo [i], lo ) < nz(lo [i
-1], lo )
broken = false
testline = line.new(bar_index - i, nz(lo [i], lo ), bar_index -1,
pl)
for j = 1 to i
if lo [j] < line.get_price(testline, bar_index - j)
broken := true
break
if broken == false
minOSCp1 = math.min(osc[i], osc[i+1], osc[i+2])
idx1 = minOSCp1 == osc[i] ? i : minOSCp1 == osc[i+1] ?
i+1 : i+2
minOSCp2 = 0.
idx2 = 0
isLwst1 = osc[1] < osc and osc[1] < osc[2]
isLwst2 = osc[2] < osc[1] and osc[2] < osc[3]
minOSCp2 := isLwst1 ? osc[1] : isLwst2 ? osc[2] : na
idx2 := isLwst1 ? 1 : isLwst2 ? 2 : na
x1 = bar_index - idx1
y1 = minOSCp1
x2 = bar_index - idx2
y2 = minOSCp2
if isLwst1 or isLwst2
testln2_OSC = frstPiv ? line.new(x1 - left, y1 - ((y2 - y1)
/ (x2 - x1) * left), x2, y2) : line.new(x1, y1, x2, y2)
for l = 1 to frstPiv ? i + left : i
if osc[l] < line.get_price(testln2_OSC, bar_index - l)
broken := true
break
if broken == false
if iBl_Hid and minOSCp2 < minOSCp1 and pl > nz(lo [i],
lo )
if arrows
label.new(bar_index - idx2, minOSCp2,
style=sBull, color=iColBl_Hid, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, minOSCp1, bar_index
- idx2, minOSCp2, color=color.gray)
if iBl_Reg and minOSCp2 > minOSCp1 and pl < nz(lo [i],
lo )
if arrows
label.new(bar_index - idx2, minOSCp2,
style=sBull, color=iColBl_Reg, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, minOSCp1, bar_index
- idx2, minOSCp2, color=color.lime)
line.delete(testln2_OSC)
line.delete(testline)
//
if pl[1] and islast_b
for i = 3 to maxBack
if nz(lo [i], lo ) < nz(lo [i +1], lo ) and nz(lo [i], lo ) < nz(lo [i
-1], lo )
broken = false
testline = line.new(bar_index - i, nz(lo [i], lo ), bar_index -2,
pl[1])
for j = 2 to i
if lo [j] < line.get_price(testline, bar_index - j)
broken := true
break
if broken == false
minOSCp1 = math.min(osc[i], osc[i+1], osc[i+2])
idx1 = minOSCp1 == osc[i] ? i : minOSCp1 == osc[i+1] ?
i+1 : i+2
minOSCp2 = 0.
idx2 = 0
isLwst1 = osc[1] < osc and osc[1] < osc[2]
minOSCp2 := isLwst1 ? osc[1] : na
idx2 := isLwst1 ? 1 : na
x1 = bar_index - idx1
y1 = minOSCp1
x2 = bar_index - idx2
y2 = minOSCp2
if isLwst1
testln2_OSC = frstPiv ? line.new(x1 - left, y1 - ((y2 - y1)
/ (x2 - x1) * left), x2, y2) : line.new(x1, y1, x2, y2)
for l = 2 to frstPiv ? i + left : i
if osc[l] < line.get_price(testln2_OSC, bar_index - l)
broken := true
break
if broken == false
if iBl_Hid and minOSCp2 < minOSCp1 and pl[1] > nz(lo
[i], lo )
if arrows
label.new(bar_index - idx2, minOSCp2,
style=sBull, color=iColBl_Hid, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, minOSCp1, bar_index
- idx2, minOSCp2, color=color.gray)
if iBl_Reg and minOSCp2 > minOSCp1 and pl[1] < nz(lo
[i], lo )
if arrows
label.new(bar_index - idx2, minOSCp2,
style=sBull, color=iColBl_Reg, yloc=yloc.price, size=_size)
if lines
line.new(bar_index - idx1, minOSCp1, bar_index
- idx2, minOSCp2, color=color.lime)
line.delete(testln2_OSC)
line.delete(testline)

drawWhenPh(osc)
drawWhenPl(osc)

pk = plot(show == 'stoch' ? k : na, linewidth=2, color=color.new(color.aqua, 50),


title='Stoch \'k\'')
pd = plot(show == 'stoch' ? d : na, linewidth=2, color=color.new(color.red, 50),
title='Stoch \'d\'')
fill(pk, pd, color.new(k > d ? color.green : color.red, 75), title='BG
Over/Undersold RSI')

plot(show == 'rsi' ? rsi : na, linewidth=3, color=color.yellow, title='RSI')


col_black = color.new(color.black, 100)
colT = input.color(color.new(color.red , 80), '', inline='lT',
group='Hlines')
colM = input.color(color.new(color.yellow, 20), '', inline='lM',
group='Hlines')
colB = input.color(color.new(color.lime , 80), '', inline='lB',
group='Hlines')

h2 = hline(show == 'rsi' or show == 'stoch' ? input.int(20, '', inline='lB',


group='Hlines') : na, color=show == 'rsi' or show == 'stoch' ? col_black :
color(na), linestyle=hline.style_dotted, title="Extreme Oversold Stoch Rsi")
h3 = hline(show == 'rsi' or show == 'stoch' ? input.int(30, '', inline='lB',
group='Hlines') : na, color=show == 'rsi' or show == 'stoch' ? col_black :
color(na), linestyle=hline.style_dotted, title="Oversold Stoch Rsi")
h5 = hline(show == 'rsi' or show == 'stoch' ? input.int(50, '', inline='lM',
group='Hlines') : na, color=show == 'rsi' or show == 'stoch' ? colM :
color(na), linestyle=hline.style_dotted, title="Middle line")
h7 = hline(show == 'rsi' or show == 'stoch' ? input.int(70, '', inline='lT',
group='Hlines') : na, color=show == 'rsi' or show == 'stoch' ? col_black :
color(na), linestyle=hline.style_dotted, title="Overbought Stoch Rsi")
h8 = hline(show == 'rsi' or show == 'stoch' ? input.int(80, '', inline='lT',
group='Hlines') : na, color=show == 'rsi' or show == 'stoch' ? col_black :
color(na), linestyle=hline.style_dotted, title="Extreme Overbought Stoch Rsi")

fill(h3, h2, color=colB, title="BG Color overbought to extreme overbought zone")


fill(h8, h7, color=colT, title="BG Color oversold to extreme oversold zone" )

col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

plot(show == 'macd' or show == 'hist' ? hist : na, title="Histogram",


style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above :
col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ))
plot(show == 'macd' or show == 'hist' ? macd : na, title="MACD", color=col_macd,
linewidth=2)
plot(show == 'macd' or show == 'hist' ? sign : na, title="Signal",
color=col_signal, linewidth=2)

You might also like