Page 41 of 58

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Mon Mar 25, 2024 12:03 am
by Harakty
Hello guys - does anything like this already exist for MT4? I use RSI extensions as main SL/TP levels in my daily strategy, it'd be great to have this indi on MT4 to automate the process.

Name: Trending RSI
Link: https://www.tradingview.com/script/qe0D ... artPrime/
Utility: Trending RSI takes a new approach to RSI intended to provide all of the missing information that traditional RSI lacks. Questions such as "why does the price continue to decline even during an oversold period?" can be aided using the Trending RSI.
Image

Code: Select all

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime

//@version=5
indicator("Trending RSI [ChartPrime]", max_bars_back = 5000, timeframe = "", timeframe_gaps = true)

// Declarations {

type divergence_data
    bool pivot_found = false
    bool divergence_found = false
    bool polarity = na
    float level = na
    color colour = #00000000

method pivot_found(divergence_data self, bool direction, bool enable)=>
    bool flag = false

    if enable
        if direction
            flag := self.pivot_found and self.polarity
        else
            flag := self.pivot_found and not self.polarity
    else
        flag

method divergence_found(divergence_data self, bool direction, bool enable = true)=>
    bool flag = false

    if enable
        if direction
            flag := self.divergence_found and self.polarity
        else
            flag := self.divergence_found and not self.polarity
    else
        flag

in_range(bool condition, int lower_range, int upper_range) =>
    int bars = ta.barssince(condition)
    lower_range <= bars and bars <= upper_range

find_divergence(float source, int left, int right, int lower_range, int upper_range, color bullish_color, color bearish_color)=>
    float source_offset = source[right]
    int offset = -right

    bool pl = not na(ta.pivotlow(source, left, right))
    bool ph = not na(ta.pivothigh(source, left, right))

    bool source_hl = source_offset > ta.valuewhen(pl, source_offset, 1) and in_range(pl[1], lower_range, upper_range)
    bool price_ll = low[right] < ta.valuewhen(pl, low[right], 1)
    bool bullish_condition = price_ll and source_hl and pl
    
    bool source_lh = source_offset < ta.valuewhen(ph, source_offset, 1) and in_range(ph[1], lower_range, upper_range)
    bool price_hh = high[right] > ta.valuewhen(ph, high[right], 1)
    bool bearish_condition = price_hh and source_lh and ph
    
    divergence_data ret = divergence_data.new()

    if bullish_condition
        ret := divergence_data.new(true, true, true, source_offset, bullish_color)
    else if pl
        ret := divergence_data.new(true, false, true, source_offset, bullish_color)

    if bearish_condition
        ret := divergence_data.new(true, true, false, source_offset, bearish_color)
    else if ph
        ret := divergence_data.new(true, false, false, source_offset, bearish_color)

    ret

convolve(float[] weights, float[] kernel, int iterations)=>
    var float[] convolution = weights.copy()

    if iterations > 0
        if barstate.isfirst
            for iteration = 0 to iterations - 1
                float[] temp = array.new<float>()

                for i = 0 to convolution.size() + kernel.size() - 2
                    float sum = 0.0

                    for j = 0 to kernel.size() - 1
                        int index = i - j

                        if index >= 0 and index < convolution.size()
                            sum += convolution.get(index) * kernel.get(j)
                        else
                            continue

                    temp.push(sum)

                convolution := temp.copy()

    convolution

method truncate_weights(float[] weights, bool enable = true)=>
    if enable
        int max_idx = weights.indexof(weights.max())

        if max_idx > 0
            for i = 0 to weights.indexof(weights.max()) - 1
                weights.shift()
        else
            weights

    weights

binomia_ma(float source, int length, bool enable)=>
    float pre_filter = ta.sma(source, 2)
    float[] h = array.from(0.5, 0.5)
    float[] weights = convolve(h, h, length * 10 - 1).truncate_weights()

    if enable and not na(source)
        float sum = 0
        float weight = 0

        for i = 0 to math.min(weights.size() - 1, bar_index)
            float w = weights.get(i)
            weight += w
            sum += nz(pre_filter[i], nz(source[i])) * w

        sum/weight

    else
        float(na)

precalculate_phi_coefficients(simple int length, simple float phase)=>
    var float[] coefficients = array.new<float>(length)
    var float E = 0.0

    const float SQRT_PIx2  = math.sqrt(2.0 * math.pi)
    const float MULTIPLIER = -0.5 / 0.93
    var int   length_1 = length - 1
    var float length_2 = length * 0.52353
    if barstate.isfirst
        for int i=0 to length_1
            float alpha = (i + phase - length_2) * MULTIPLIER
            float  beta = 1.0 / (0.2316419 * math.abs(alpha) + 1.0)
            float   phi = (math.exp(math.pow(alpha, 2) * -0.5)
                          *-0.398942280) * beta *
                          ( 0.319381530  + beta *
                          (-0.356563782  + beta *
                          ( 1.781477937  + beta *
                          (-1.821255978  + beta 
                          * 1.330274429)))) + 1.011
            if alpha < 0.0
                phi := 1.0 - phi
            float weight = phi / SQRT_PIx2
            E += weight
            coefficients.set(i, weight)
    [coefficients, E]

phi_smoother(series float source, series float[] coefficients, series float E, simple float hf_ratio = 0.5)=>
    float sma2 = source * math.min(math.max(0.5, hf_ratio), 1) + nz(source[1], source) * math.max(math.min(0.5, 1 - hf_ratio), 0)
    int length = coefficients.size()
    if length > 1
        float W = 0.0
        for int i=0 to length - 1
            float weight = coefficients.get(i)
            W  += weight * sma2[i]
        W / E
    else 
        source

rma(float source = close, float length = 9)=>
    float alpha = 1 / length
    var float smoothed = na
    smoothed := alpha * source + (1 - alpha) * nz(smoothed[1])

rsi(float source, int length)=> 
    float up = math.max(source - source[1], 0)
    float down = math.max(source[1] - source, 0)
    float rs = rma(up, length) / rma(down, length)
    float rsi = 100 - 100 / (1 + rs)
    rsi

reverse_rsi(series float source, simple int length, float value)=>
    float src = (source - ta.rma(source, length)) / (length / 2)
    float alpha = 1 / length
    float average_up_count = 0.0
    float average_down_count = 0.0

    average_up_count := src > src[1] 
                                     ? alpha * (src - src[1]) + (1 - alpha) * nz(average_up_count[1], 1) 
                                     : (1 - alpha) * nz(average_up_count[1], 1)

    average_down_count := src > src[1] 
                                     ? (1 - alpha) * nz(average_down_count[1], 1)
                                     : alpha * (src[1] - src) + (1 - alpha) * nz(average_down_count[1], 1)

    float reversed_value = (length - 1) * (average_down_count * value / (100 - value) - average_up_count)
    float reverse_rsi = reversed_value >= 0 ? src + reversed_value : src + reversed_value * (100 - value) / value

// }

// Inputs {

const string group_1 = "Settings"
const string top_value_tip = "Pick what RSI value you want the top range to represent."
const string bottom_value_tip = "Pick what RSI value you want the bottom range to represent"

float source = input.source(close, "Source", group = group_1)
int length = input.int(14, "Length", minval = 1, group = group_1)
float top_value = input.float(70, "Top Range", minval = 50, maxval = 99, tooltip = top_value_tip, group = group_1)
float bottom_value = input.float(30, "Bottom Range", minval = 1, maxval = 50, tooltip = bottom_value_tip, group = group_1) 
bool ma_enable = input.bool(false, "MA Length        ", inline = "MA", group = group_1)
int ma_length = input.int(30, "", minval = 0, maxval = 100, inline = "MA", group = group_1)

const string group_2 = "Smoothing"
const string smoothing_tip = "Adjusts the period of the filter."
const string speed_tip = "Adjusts the responsiveness of the filter."
const string hf_tip = "Adjusts the pre smoothing of the filter." + "\n" + "1 is no pre smoothing while 0.5 is maximum pre smoothing."

int smoothing = input.int(1, "Signal Smoothing", minval = 1, tooltip = smoothing_tip, group = group_2)
float smoothing_phase = input.float(3.7, "Signal Smoothing Speed", tooltip = speed_tip, group = group_2)
float smoothing_hf = input.float(0.7, "Signal Smoothing Pre Filter", 0.5, 1, step = 0.1, tooltip = hf_tip, group = group_2)
int boundary_smoothing = input.int(40, "Boundary Smoothing", minval = 1, tooltip = smoothing_tip, group = group_2)
float boundary_smoothing_phase = input.float(3.7, "Boundry Smoothing Speed", tooltip = speed_tip, group = group_2)
float boundary_hf = input.float(0.5, "Boundary Smoothing Pre Filter", 0.5, 1, step = 0.1, tooltip = hf_tip, group = group_2)

const string group_3 = "Divergence"
const string left_tip = "Pick the lookback for the divergence."
const string right_tip = "Pick the lookforward for the divergence. This impacts the lag of the divergence. It acts as a confirmation period."
const string lower_range_tip = "Minimum number of candles for a divergence."
const string upper_range_tip = "Maximum number of candles for a divergence."

int left = input.int(15, "Look Left", minval = 1, tooltip = left_tip, group = group_3)
int right = input.int(15, "Look Right", minval = 1, tooltip = right_tip, group = group_3)
int lower_range = input.int(5, "Lower Range", minval = 1, tooltip = lower_range_tip, group = group_3)
int upper_range = input.int(60, "Upper Range", minval = 1, tooltip = upper_range_tip, group = group_3)
string divergence_label = input.string("Line", "Divergence Drawings", ["Line", "Label", "Line and Label"], group = group_3)
bool bullish_divergence = input.bool(false, "Enable Bullish Divergence", group = group_3)
bool bearish_divergence = input.bool(false, "Enable Bearish Divergence", group = group_3)

const string group_4 = "Color"
bool glow = input.bool(true, "Glow", group = group_4)
color rsi_color = input.color(#ffffff, "RSI", group = group_4)
color ma_color = input.color(#FFEE54, "MA Color", group = group_4)
color bg_color = input.color(#7E57C21A, "BG", group = group_4)
color top_color = input.color(#a222e283, "Upper Range", group = group_4)
color bottom_color = input.color(#e5b60c83, "Lower Range", group = group_4)
color center_bullish_up_color = input.color(#21a110, "Center", inline = "Center", group = group_4)
color center_bullish_down_color = input.color(#005e05, "", inline = "Center", group = group_4)
color center_bearish_up_color = input.color(#FCA0A9, "", inline = "Center", group = group_4)
color center_bearish_down_color = input.color(#FB3E38, "", inline = "Center", group = group_4)
color bullish_divergence_color = input.color(#00B374, "Bullish Divergence", group = group_4)
color bearish_divergence_color = input.color(#F03042, "Bearish Divergence", group = group_4)
color divergence_text_color = input.color(#FEFEFE, "Divergence Text", group = group_4)
color zero_line_color = input.color(#9E9E9E, "0 Line Color", group = group_4)

// }

// Calculations {

[smoothing_coefficients, smoothing_E] = precalculate_phi_coefficients(smoothing, smoothing_phase)
[boundary_coefficients, boundary_E] = precalculate_phi_coefficients(boundary_smoothing, boundary_smoothing_phase)

float top = phi_smoother(reverse_rsi(source, length, top_value), boundary_coefficients, boundary_E, boundary_hf)
float bottom = phi_smoother(reverse_rsi(source, length, bottom_value), boundary_coefficients, boundary_E, boundary_hf)
float center = phi_smoother(reverse_rsi(source, length, 50), smoothing_coefficients, smoothing_E, smoothing_hf)

float top_glow = phi_smoother(reverse_rsi(source, length, math.min(top_value + 4, 99)), boundary_coefficients, boundary_E, boundary_hf)
float bottom_glow = phi_smoother(reverse_rsi(source, length, math.max(bottom_value - 4, 1)), boundary_coefficients, boundary_E, boundary_hf)

float rsi = phi_smoother(reverse_rsi(source, length, rsi(source, length)), smoothing_coefficients, smoothing_E, smoothing_hf)
float ma = binomia_ma(rsi, ma_length, ma_enable)

divergence_data divs = find_divergence(rsi, left, right, lower_range, upper_range, bullish_divergence_color, bearish_divergence_color)

bool bullish_pivot_found = divs.pivot_found(true, bullish_divergence)
bool bullish_divergence_found = divs.divergence_found(true, bullish_divergence)
bool bullish_divergence_alert = divs.divergence_found(true)

bool bearish_pivot_found = divs.pivot_found(false, bearish_divergence)
bool bearish_divergence_found = divs.divergence_found(false, bearish_divergence)
bool bearish_divergence_alert = divs.divergence_found(false)

bool draw_line = str.contains(divergence_label, "Line")
bool draw_label = str.contains(divergence_label, "Label")

float center_delta = center - center[1]

// }

// Color Calculations {

color center_color = center >= 0 
                                 ? (center_delta > 0 ? center_bullish_up_color : center_bullish_down_color) 
                                 : (center_delta > 0 ? center_bearish_up_color : center_bearish_down_color)

color top_glow_color_max = color.new(top_color, 80)
color bottom_glow_color_max = color.new(bottom_color, 80)
color top_glow_color_min = color.new(top_color, 100)
color bottom_glow_color_min = color.new(bottom_color, 100)

color zero_line_solid = color.new(zero_line_color, 80)
color zero_line_dashed = color.new(zero_line_color, 50)

// }

// Plotting {

plot(0, "0 Line", zero_line_solid, display = display.pane)
plot(0, "0 Line", zero_line_dashed, 4, plot.style_histogram, display = display.pane)

top_band = plot(top, "Upper Range", top_color)
bottom_band = plot(bottom, "Lower Range", bottom_color)

top_band_glow = plot(glow ? top_glow : na, "Upper Range Glow", top_glow_color_min, editable = false, display = display.none)
bottom_band_glow = plot(glow ? bottom_glow : na, "Lower Range Glow", bottom_glow_color_min, editable = false, display = display.none)

fill(top_band_glow, top_band, top_glow, 0, top_glow_color_min, top_glow_color_max, "Upper Range Glow Fill")
fill(bottom_band, bottom_band_glow, 0, bottom_glow, bottom_glow_color_max, bottom_glow_color_min, "Lower Range Glow Fill")
fill(top_band, bottom_band, bg_color, "RSI Background Fill")

plot(glow ? center : na, "Center", color.new(center_color, 95), 3, editable = false, display = display.pane)
plot(glow ? center : na, "Center", color.new(center_color, 95), 2, editable = false, display = display.pane)
plot(center, "Center", center_color,2)

plot(glow ? ma : na, "MA Glow", color.new(ma_color, 95), 3, editable = false, display = display.pane)
plot(ma, "MA", ma_color, display = ma_enable ? display.all : display.pane)

plot(glow ? rsi : na, "RSI Glow", color.new(rsi_color, 95), 4, editable = false, display = display.pane)
plot(glow ? rsi : na, "RSI Glow", color.new(rsi_color, 95), 3, editable = false, display = display.pane)
plot(glow ? rsi : na, "RSI Glow", color.new(rsi_color, 95), 2, editable = false, display = display.pane)
plot(rsi, "RSI", rsi_color)

plot(bullish_pivot_found and draw_line ? divs.level : na, "Bullish Divergence", bullish_divergence_found ? divs.colour : #00000000, 2, offset = -right, display = bullish_divergence ? display.all : display.pane)
plotshape(bullish_divergence_found and draw_label ? divs.level : na, "Bullish Divergence Label", shape.labelup, location.absolute, bullish_divergence_found ? divs.colour : na, -right, "Bullish", divergence_text_color, display = bullish_divergence ? display.all : display.pane)

plot(bearish_pivot_found and draw_line ? divs.level : na, "Bearish Divergence", bearish_divergence_found ? divs.colour : #00000000, 2, offset = -right, display = bearish_divergence ? display.all : display.pane)
plotshape(bearish_divergence_found and draw_label ? divs.level : na, "Bearish Divergence Label", shape.labeldown, location.absolute, bearish_divergence_found ? divs.colour : na, -right, "Bearish", divergence_text_color, display = bearish_divergence ? display.all : display.pane)

// }

// Alerts {

alertcondition(ta.crossover(rsi, center), "RSI Cross Over Center")
alertcondition(ta.crossunder(rsi, center), "RSI Cross Under Center")
alertcondition(ta.crossunder(rsi, top), "RSI Cross Under Upper Range")
alertcondition(ta.crossover(rsi, top), "RSI Cross Over Upper Range")
alertcondition(ta.crossover(rsi, bottom), "RSI Cross Over Lower Range")
alertcondition(ta.crossunder(rsi, bottom), "RSI Cross Under Lower Range")
alertcondition(ta.crossover(rsi, ma), "RSI Cross Over MA")
alertcondition(ta.crossunder(rsi, ma), "RSI Cross Under MA")

alertcondition(ta.crossover(rsi, 0), "RSI Cross Over 0")
alertcondition(ta.crossunder(rsi, 0), "RSI Cross Under 0")
alertcondition(ta.crossover(center, 0), "Center Cross Over 0")
alertcondition(ta.crossunder(center, 0), "Center Cross Under 0")

alertcondition(ta.crossover(center_delta, 0), "Center Bullish")
alertcondition(ta.crossunder(center_delta, 0), "Center Bearish")

alertcondition(bullish_divergence_alert, "Bullish Divergence")
alertcondition(bearish_divergence_alert, "Bearish Divergence")

// } 

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Thu Mar 28, 2024 7:50 pm
by friend4you
opita wrote: Thu Jul 21, 2022 2:27 pm Does anyone know of an indicator similar to this?

2022-07-20_21-25-59.png

Code: Select all

//@version=4
study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
length = input(title="Length", defval=14, minval=1)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
m = input(1.5, "Multiplier")
src1 = input(high)
src2 = input(low)
pline = input(true, "Show Price Lines")
col1 = input(color.blue, "ATR Text Color")
col2 = input(color.teal, "Low Text Color",inline ="1")
col3 = input(color.red, "High Text Color",inline ="2")

collong = input(color.teal, "Low Line Color",inline ="1")
colshort = input(color.red, "High Line Color",inline ="2")

ma_function(source, length) =>
	if smoothing == "RMA"
		rma(source, length)
	else
		if smoothing == "SMA"
			sma(source, length)
		else
			if smoothing == "EMA"
				ema(source, length)
			else
				wma(source, length)
				
a = ma_function(tr(true), length) * m
x = ma_function(tr(true), length) * m + src1
x2 = src2 - ma_function(tr(true), length) * m

p1 = plot(x, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
p2 = plot(x2, title = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)

var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)    

f_fillCell(_table, _column, _row, _value, _timeframe) =>

	_cellText = _timeframe+ tostring(_value, "#.#")
    table.cell(_table, _column, _row, _cellText, text_color = col1)
    table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
Atr bands as I posted in 2018 here is similar.

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Thu Mar 28, 2024 9:32 pm
by moey_dw
friend4you wrote: Thu Mar 28, 2024 7:50 pm Atr bands as I posted in 2018 here is similar.
Thanks friendly bro......

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Thu Mar 28, 2024 11:51 pm
by friend4you
moey_dw wrote: Thu Mar 28, 2024 9:32 pm Thanks friendly bro......
-u-no-post-link.gif
Don't you like reading more of my words?
I prefer these non repainting indicators:
For bands, look
post1295365861.html#p1295365861

As free system, I like
mt4-trading-systems-gifts-for-the-new-y ... 1295469953
As indicators
post1295469951.html#p1295469951

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Sun Mar 31, 2024 1:38 am
by jeffx33
Hello dear coders, I hope everyone is having a good week end.
Could anyone please convert this awesome indicator from TV to mt4 that displays other time frame candle on the same chart?
Many thanks

https://www.tradingview.com/script/ZEzP ... e-Display/

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Mon Apr 01, 2024 12:50 am
by Antonov
RodrigoRT7 wrote: Mon Mar 13, 2023 2:18 pm hello friend Wael007, how are you? always put an image so that our programmer friends know what it is about, because sometimes we have some related indicator :D
Please post the names of the indicators on screen. Pleeeaassseee

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Mon Apr 01, 2024 1:46 pm
by RodrigoRT7
Antonov wrote: Mon Apr 01, 2024 12:50 am Please post the names of the indicators on screen. Pleeeaassseee
Hello Antonov, how are you? the indicator in the photo is the TMA same as it is in the code + Market Profile + Pivot Point

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Thu Apr 11, 2024 11:44 am
by nhatduyatv
Hello,
I known a Trading View indicator, Can anyone help me converter to MT4? Thank you

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Thu Apr 11, 2024 3:58 pm
by Jimmy
nhatduyatv wrote: Thu Apr 11, 2024 11:44 am Hello
Please follow the guidelines in Post #1. You may edit your last post to add the additional information if you'd still like us to take a look for you 👍

Re: Already Converted TradingView Indicators to MT4 Indicators

Posted: Fri Apr 12, 2024 1:02 am
by GaeBolg
Hi. Can anyone convert sentiment range ma indicator to mt4 please?
Its a good signal indicator that allows us to see range market for filtering.

https://www.tradingview.com/script/LVsN ... hartPrime/

Code: Select all

//@version=5
indicator("Sentiment Range MA [ChartPrime]", overlay = true, timeframe = "", timeframe_gaps = false)

simple_filter(float source, int length, bool duel_filter)=>
    switch duel_filter
        false => ta.wma(source, length)
        true => ta.wma(ta.sma(source, length), length)

sr_ma(float source = close, int output_smoothing = 3, int trigger_smoothing = 1, int atr_length = 50, float multiplier = 1, string range_switch = "Body", bool duel_filter = false)=>
    candle_top = range_switch != "Body" ? high : math.max(open, close)
    candle_bottom = range_switch != "Body" ? low : math.min(open, close)

    smooth_top = ta.sma(candle_top, trigger_smoothing)
    smooth_bottom = ta.sma(candle_bottom, trigger_smoothing)

    tr = candle_top - candle_bottom
    atr = ta.sma(tr, atr_length)

    var float sr_ma = na
    var float current_range = na
    var float top_range = na
    var float bottom_range = na

    flag = smooth_top > top_range or smooth_bottom < bottom_range or na(current_range)

    if flag
        sr_ma := source
        current_range := atr * multiplier
        top_range := sr_ma + current_range
        bottom_range := sr_ma - current_range
        
    out = simple_filter(sr_ma, output_smoothing, duel_filter)
    smooth_top_range = simple_filter(top_range, output_smoothing, duel_filter)
    smooth_bottom_range = simple_filter(bottom_range, output_smoothing, duel_filter)

    [out, smooth_top_range, smooth_bottom_range]

source = input.source(close, "Source", group = "Settings")
output_smoothing = input.int(20, "Length", minval = 0, group = "Settings") + 1
use_double = input.bool(true, "Double Filter", group = "Settings")
smoothing = input.int(4, "Trigger Smoothing", minval = 0, group = "Settings") + 1
atr_length = input.int(200, "ATR Length", minval = 1, group = "Settings")
multiplier = input.float(6, "Range Multiplier", minval = 0, step = 0.125, group = "Settings")
range_switch = input.string("Body", "Range Style", ["Body", "Wick"], group = "Settings")

style = input.string("MA Direction", "Color Style", ["MA Direction", "MA Cross", "Solid"], group = "Color")
bullish_color = input.color(color.rgb(33, 255, 120), "Bullish Color", group = "Color")
bearish_color = input.color(color.rgb(255, 33, 33), "Bearish Color", group = "Color")

neutral_color = input.color(color.rgb(137, 137, 137), "Neutral Color", "This doubles as the solid color.", group = "Color")

[sr_ma, top_range, bottom_range] = sr_ma(source, output_smoothing, smoothing, atr_length, multiplier, range_switch, use_double)

var color ma_delta = na
var color ma_cross = na

plot_neutral = high > sr_ma and low < sr_ma
plot_bullish = low > sr_ma
plot_bearish = high < sr_ma

if plot_bullish 
    ma_cross := bullish_color

if plot_bearish
    ma_cross := bearish_color

if plot_neutral 
    ma_cross := neutral_color

ma_delta_neutral = sr_ma - nz(sr_ma[1]) == 0
ma_delta_bullish = sr_ma - nz(sr_ma[1]) > 0
ma_delta_bearish = sr_ma - nz(sr_ma[1]) < 0

if ma_delta_bullish
    ma_delta := bullish_color

if ma_delta_bearish
    ma_delta := bearish_color

if ma_delta_neutral 
    ma_delta := neutral_color

ma_color = style == "MA Cross"? ma_cross : style == "MA Direction" ? ma_delta : neutral_color

alpha = color.new(color.red, 100)

ma = plot(sr_ma, "SR MA", ma_color, 3)
top = plot(top_range, "Top Range", alpha)
bottom = plot(bottom_range, "Bottom Range", alpha)

fill(ma, top, top_value = top_range, bottom_value = sr_ma, bottom_color = color.new(ma_color, 82), top_color = alpha)
fill(ma, bottom, top_value = sr_ma, bottom_value = bottom_range, top_color = color.new(ma_color, 82), bottom_color = alpha)