// Description :
// Mean Reversion Channel objective, based on Mean Reversion theory (everything has a tendency to revert back to its mean), is to help visualizing:
// Inner Channel -> Dynamic Support and Resistance
// Outer Channel -> Overbought/Oversold Zone which may signal consolidation phase or potential reversal due to unsustainable move
// The concept of this indicator oriiginally derived from Keltner Channel (The Keltner Channel was first introduced by Chester Keltner in the 1960s. The original formula used simple moving averages (SMA) and the high-low price range to calculate the bands. In the 1980s, a new formula was introduced that used ATR.)
// Instead if using SMA/EMA, this indicator used SuperSmoother MA as it's mean with longer lookback period (default to 200) to get more stable channel line. i also added second level so the indicator will have inner and outer channel
// Details of each filtering type used for mean calculation can be read in Ehlers Technical Papers: "Swiss Army Knife Indicator" and/or his book "Cybernetics Analysis for Stock and Futures"
// Disclaimer:
// Past performance is not an indicator of future results.
// My opinions are my own and do not constitute financial advice in any way whatsoever.
// Nothing published by me constitutes an investment/trading recommendation, nor should any data or Content published by me be relied upon for any investment/trading activities.
// I strongly recommends that you perform your own independent research and/or speak with a qualified investment professional before making any financial decisions.
// Any ideas to further improve this indicator are welcome :)
Thank you for sharing your Mean Reversion Channel (MRC) indicator code. How can I assist you with it? Are you looking for suggestions to improve the indicator, help with updating it, or do you have specific questions about its functionality?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
//************************************************************************************************************
// Functions Start {
//************************************************************************************************************
var pi = 2 * asin(1)
var mult = pi * innermult
var mult2 = pi * outermult
var gradsize = 0.5
var gradtransp = zonetransp
get_tf(_lvl)=>
y = f_resInMinutes()
z = timeframe.period
if(mtf_typ=="Auto")
if y < 1
z := _lvl == 1 ? "1" : _lvl == 2 ? "5" : z
else if y <= 3
z := _lvl == 1 ? "5" : _lvl == 2 ? "15" : z
else if y <= 10
z := _lvl == 1 ? "15" : _lvl == 2 ? "60" : z
else if y <= 30
z := _lvl == 1 ? "60" : _lvl == 2 ? "240" : z
else if y <= 120
z := _lvl == 1 ? "240" : _lvl == 2 ? "D" : z
else if y <= 240
z := _lvl == 1 ? "D" : _lvl == 2 ? "W" : z
else if y <= 1440
z := _lvl == 1 ? "W" : _lvl == 2 ? "M" : z
else if y <= 10080
z := _lvl == 1 ? "M" : z
else
z := z
else
z := _lvl == 1 ? mtf_lvl1 : _lvl == 2 ? mtf_lvl2 : z
z
//-----------------------
// Mean Reversion Channel Function
//-----------------------
get_mrc()=>
v_condition = 0
v_meanline = source
v_meanrange = supersmoother(tr, length)
get_stat(_cond) =>
ret = "Price at Mean Line\n"
if (_cond == 1)
ret := "Overbought (Weak)\n"
else if (_cond == 2)
ret := "Overbought\n"
else if (_cond == 3)
ret := "Overbought (Strong)\n"
else if (_cond == 4)
ret := "Price Near Mean\n"
else if (_cond == 5)
ret := "Price Above Mean\n"
else if (_cond == -1)
ret := "Oversold (Weak)\n"
else if (_cond == -2)
ret := "Oversold\n"
else if (_cond == -3)
ret := "Oversold (Strong)\n"
else if (_cond == -4)
ret := "Price Near Mean\n"
else if (_cond == -5)
ret := "Price Below Mean\n"
ret
//-----------------------
// Chart Drawing Function
//-----------------------
format_price(x) =>
y = tostring(x, "0.00000")
if(x>10)
y := tostring(x, "0.000")
if(x>1000)
y := tostring(x, "0.00")
y
//-----------------------
// Plot Extension
//-----------------------
if(displayline and enable_mtf and mtf_disp_typ == "Always Display")
displayline := false
var line mean = na, line.delete(mean), mean := displayline ? f_PriceLine(meanline, #FFCD00) : na
var line res1 = na, line.delete(res1), res1 := displayline ? f_PriceLine(upband1, color.green) : na
var line sup1 = na, line.delete(sup1), sup1 := displayline ? f_PriceLine(loband1, color.green) : na
var line res2 = na, line.delete(res2), res2 := displayline ? f_PriceLine(upband2, color.red) : na
var line sup2 = na, line.delete(sup2), sup2 := displayline ? f_PriceLine(loband2, color.red) : na