// This source code is subject to the terms of the Mozilla Public License 2.
0 at
[Link]
// © RedKTrader
//@version=5
indicator('RedK Magic Ribbon', shorttitle='MagicRibbon v4.0', overlay=true,
timeframe='', timeframe_gaps=false)
//====================================================================
f_LazyLine(_data, _length) =>
w1 = 0, w2 = 0, w3 = 0
L1 = 0.0, L2 = 0.0, L3 = 0.0
w = _length / 3
if _length > 2
w2 := [Link](w)
w1 := [Link]((_length - w2) / 2)
w3 := int((_length - w2) / 2)
L1 := [Link](_data, w1)
L2 := [Link](L1, w2)
L3 := [Link](L2, w3)
L3
else
L3 := _data
L3
L3
//=====================================================================
f_CoraWave(source, length, s) =>
numerator = 0.0, denom = 0.0
c_weight = 0.0, r_multi = 2.0
Start_Wt = 0.01 // Start Weight & r_multi are set to basic values here.
End_Wt = length // use length as initial End Weight to calculate base "r"
r = [Link](End_Wt / Start_Wt, 1 / (length - 1)) - 1
base = 1 + r * r_multi
for i = 0 to length - 1 by 1
c_weight := Start_Wt * [Link](base, length - i)
numerator += source[i] * c_weight
denom += c_weight
denom
cora_raw = numerator / denom
cora_wave = [Link](cora_raw, s)
cora_wave
// ======================================================================
Source_1 = [Link](close, 'Source', inline='CRMA1', group='CoRa
Wave (Fast MA)')
Length_1 = [Link](10, 'Length', minval=1, inline='CRMA1', group='CoRa
Wave (Fast MA)')
smooth = [Link](3, 'Smooth', minval=1, inline='CRMA2', group='CoRa
Wave (Fast MA)')
Source_2 = [Link](close, 'Source', inline='RSSMA',
group='RSS_WMA (Slow MA)')
Length_2 = [Link](15, 'Smoothness', minval=1, inline='RSSMA',
group='RSS_WMA (Slow MA)')
ShowFill = [Link](true, 'Ribbon Fill?', group='RSS_WMA (Slow MA)')
FastLine = f_CoraWave(Source_1, Length_1, smooth)
SlowLine = f_LazyLine(Source_2, Length_2)
c_fup = [Link]([Link], 30)
c_fdn = [Link]([Link], 30)
Fast_up = FastLine > FastLine[1]
Fast_dn = FastLine < FastLine[1]
c_sup = [Link](#33ff00, 0)
c_sdn = [Link](#ff1111, 0)
Slow_up = SlowLine > SlowLine[1]
Slow_dn = SlowLine < SlowLine[1]
FastPlot = plot(FastLine, title='Fast Line', color=Fast_up ? c_fup : c_fdn,
linewidth=2)
SlowPlot = plot(SlowLine, title='Slow Line', color=Slow_up ? c_sup : c_sdn,
linewidth=3)
c_rup = [Link](#33ff00, 70)
c_rdn = [Link](#ff1111, 70)
c_rsw = [Link]([Link], 70)
Ribbon_up = Fast_up and Slow_up
Ribbon_dn = not Fast_up and not Slow_up
fill(FastPlot, SlowPlot, title='Ribbon Fill', color=ShowFill ? Ribbon_up ? c_rup :
Ribbon_dn ? c_rdn : c_rsw : na)
//
===================================================================================
===================
// v3.0 adds 2 optional MA's - to enable us to track what many other traders are
working with
// the below code is based on the built-in MA Ribbon in the TV library - with some
modifications
// ======================================================================
f_ma(source, length, type) =>
type == 'SMA' ? [Link](source, length) : type == 'EMA' ? [Link](source, length)
: [Link](source, length)
// ======================================================================
gr_ma = 'Optional Moving Averages'
t_ma1 = 'MA #1'
t_ma2 = 'MA #2'
show_ma1 = [Link](false, t_ma1,
inline=t_ma1, group=gr_ma)
ma1_type = [Link]('SMA', '', options=['SMA', 'EMA', 'WMA'],
inline=t_ma1, group=gr_ma)
ma1_source = [Link](close, '',
inline=t_ma1, group=gr_ma)
ma1_length = [Link](50, '', minval=1,
inline=t_ma1, group=gr_ma)
ma1_color = [Link](#9c27b0,0)
ma1 = f_ma(ma1_source, ma1_length, ma1_type)
plot(show_ma1 ? ma1 : na, color=ma1_color, title=t_ma1, linewidth=1)
show_ma2 = [Link](false, t_ma2,
inline=t_ma2, group=gr_ma)
ma2_type = [Link]('SMA', '', options=['SMA', 'EMA', 'WMA'],
inline=t_ma2, group=gr_ma)
ma2_source = [Link](close, '',
inline=t_ma2, group=gr_ma)
ma2_length = [Link](100, '', minval=1,
inline=t_ma2, group=gr_ma)
ma2_color = [Link](#1163f6,0)
ma2 = f_ma(ma2_source, ma2_length, ma2_type)
plot(show_ma2 ? ma2 : na, color=ma2_color, title=t_ma2, linewidth=1)
//
===================================================================================
===================
// v4.0 adds alerts for Fast and Slow swinging to a new move up or new move down
// This is easier than looking for the visual signal / color change .. as requested
// The main signal is really when the ribbon "agrees" on a spcific color
//
===================================================================================
===================
Alert_Fastup = Fast_up and not Fast_up[1]
Alert_Fastdn = Fast_dn and not Fast_dn[1]
Alert_Slowup = Slow_up and not Slow_up[1]
Alert_Slowdn = Slow_dn and not Slow_dn[1]
alertcondition(Alert_Fastup, 'Fast Line Swings Up', 'MagicRibbon - Fast Line
Swing Up Detected!')
alertcondition(Alert_Fastdn, 'Fast Line Swings Down', 'MagicRibbon - Fast Line
Swing Down Detected!')
alertcondition(Alert_Slowup, 'Slow Line Swings Up', 'MagicRibbon - Slow Line
Swing Up Detected!')
alertcondition(Alert_Slowdn, 'Slow Line Swings Down', 'MagicRibbon - Slow Line
Swing Down Detected!')