HappyRe: Already Converted TradingView Indicators to MT4 Indicators

451
Hi everyone ๐Ÿ’•
Is it possible to make an MT4 version of this indicator:
https://www.tradingview.com/v/Uz2AJ0i4/

I think for reversal trading's it filters a lot of bad trades.
It is called support and resistance high volume boxes.

Pine script code:

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("Support and Resistance (High Volume Boxes) [ChartPrime]", shorttitle = "SR Breaks and Retests [ChartPrime]", overlay=true, max_boxes_count = 50)


// ---------------------------------------------------------------------------------------------------------------------}
// ๐™๐™Ž๐™€๐™ ๐™„๐™‰๐™‹๐™๐™๐™Ž
// ---------------------------------------------------------------------------------------------------------------------{
int   lookbackPeriod = input.int(20, "Lookback Period", minval=1, group = "Settings")
int   vol_len        = input.int(2, "Delta Volume Filter Length", tooltip = "Higher input, will filter low volume boxes"
                                                                                                   , group = "Settings")
float box_withd      = input.float(1, "Adjust Box Width", maxval = 1000, minval = 0, step = 0.1)


// ---------------------------------------------------------------------------------------------------------------------}
// ๐™„๐™‰๐˜ฟ๐™„๐˜พ๐˜ผ๐™๐™Š๐™ ๐˜พ๐˜ผ๐™‡๐˜พ๐™๐™‡๐˜ผ๐™๐™„๐™Š๐™‰๐™Ž
// ---------------------------------------------------------------------------------------------------------------------{
// Delta Volume Function
upAndDownVolume() =>
    posVol = 0.0
    negVol = 0.0
    
    var isBuyVolume = true    

    switch
        close > open   => isBuyVolume := true
        close < open   => isBuyVolume := false

    if isBuyVolume
        posVol += volume
    else
        negVol -= volume

    posVol + negVol


// Function to identify support and resistance boxes
calcSupportResistance(src, lookbackPeriod) =>
    // Volume
    Vol    = upAndDownVolume()
    vol_hi = ta.highest(Vol/2.5, vol_len)
    vol_lo = ta.lowest(Vol/2.5, vol_len)

    var float supportLevel      = na
    var float supportLevel_1    = na    
    var float resistanceLevel   = na
    var float resistanceLevel_1 = na    
    var box   sup               = na
    var box   res               = na
    var color res_color         = na
    var color sup_color         = na    
    var float multi             = na

    var bool  brekout_res       = na
    var bool  brekout_sup       = na
    var bool  res_holds         = na
    var bool  sup_holds         = na

    // Find pivot points
    pivotHigh = ta.pivothigh(src, lookbackPeriod, lookbackPeriod)
    pivotLow  = ta.pivotlow (src, lookbackPeriod, lookbackPeriod)
    // Box width
    atr       = ta.atr(200)
    withd     = atr * box_withd

    // Find support levels with Positive Volume
    if (not na(pivotLow)) and Vol > vol_hi 

        supportLevel   := pivotLow
        supportLevel_1 := supportLevel-withd       

        topLeft         = chart.point.from_index(bar_index-lookbackPeriod, supportLevel)
        bottomRight     = chart.point.from_index(bar_index, supportLevel_1)

        sup_color      := color.from_gradient(Vol, 0, ta.highest(Vol, 25), color(na), color.new(color.green, 30))

        sup := box.new(
                       top_left     = topLeft, 
                       bottom_right = bottomRight, 
                       border_color = color.green, 
                       border_width = 1, 
                       bgcolor      = sup_color, 
                       text         = "Vol: "+str.tostring(math.round(Vol,2)), 
                       text_color   = chart.fg_color, 
                       text_size    = size.small
                       ) 


    // Find resistance levels with Negative Volume
    if (not na(pivotHigh)) and Vol < vol_lo
   
        resistanceLevel   := pivotHigh
        resistanceLevel_1 := resistanceLevel+withd

        topLeft            = chart.point.from_index(bar_index-lookbackPeriod, resistanceLevel)
        bottomRight        = chart.point.from_index(bar_index, resistanceLevel_1)

        res_color         := color.from_gradient(Vol, ta.lowest(Vol, 25), 0, color.new(color.red, 30), color(na))

        res := box.new(
                       top_left     = topLeft, 
                       bottom_right = bottomRight, 
                       border_color = color.red, 
                       border_width = 1, 
                       bgcolor      = res_color, 
                       text         = "Vol: "+str.tostring(math.round(Vol,2)), 
                       text_color   = chart.fg_color, 
                       text_size    = size.small
                       ) 

    // Adaptive Box Len
    sup.set_right(bar_index+1)
    res.set_right(bar_index+1)

    // Break of support or resistance conditions
    brekout_res := ta.crossover(low, resistanceLevel_1)
    res_holds   := ta.crossunder(high, resistanceLevel)

    sup_holds   := ta.crossover(low, supportLevel)
    brekout_sup := ta.crossunder(high, supportLevel_1)

    // Change Color of Support to red if it was break, change color of resistance to green if it was break
    if brekout_sup
        sup.set_bgcolor(color.new(color.red, 80))
        sup.set_border_color(color.red)
        sup.set_border_style(line.style_dashed)

    if sup_holds
        sup.set_bgcolor(sup_color)
        sup.set_border_color(color.green)
        sup.set_border_style(line.style_solid)

    if brekout_res
        res.set_bgcolor(color.new(color.green, 80))
        res.set_border_color(color.new(color.green, 0))
        res.set_border_style(line.style_dashed)

    if res_holds
        res.set_bgcolor(res_color)
        res.set_border_color(color.new(color.red, 0))
        res.set_border_style(line.style_solid)

    [supportLevel, resistanceLevel, brekout_res, res_holds, sup_holds, brekout_sup]


// Calculate support and resistance levels and their breakouts
[supportLevel,
         resistanceLevel, 
             brekout_res, 
                 res_holds, 
                     sup_holds, 
                         brekout_sup] = calcSupportResistance(close, lookbackPeriod)


// Check if Resistance become Support or Support Become Resistance
var bool res_is_sup = na
var bool sup_is_res = na

switch
    brekout_res => res_is_sup := true
    res_holds   => res_is_sup := false

switch
    brekout_sup => sup_is_res := true
    sup_holds   => sup_is_res := false


// ---------------------------------------------------------------------------------------------------------------------}
// ๐™‘๐™„๐™Ž๐™๐˜ผ๐™‡๐™„๐™•๐˜ผ๐™๐™„๐™Š๐™‰
// ---------------------------------------------------------------------------------------------------------------------{
// Plot Res and Sup breakouts and holds 
plotchar(res_holds, "Resistance Holds", "โ—†", 
             color = #e92929,   size = size.tiny, location = location.abovebar, offset = -1)
plotchar(sup_holds, "Support Holds",    "โ—†", 
             color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1)

plotchar(brekout_res and res_is_sup[1], "Resistance as Support Holds", "โ—†", 
             color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1)
plotchar(brekout_sup and sup_is_res[1], "Support as Resistance Holds", "โ—†", 
             color = #e92929,   size = size.tiny, location = location.abovebar, offset = -1)

// Break Out Labels
if brekout_sup and not sup_is_res[1]
    label.new(
              bar_index[1], supportLevel[1], 
              text       = "Break Sup", 
              style      = label.style_label_down, 
              color      = #7e1e1e, 
              textcolor  = chart.fg_color, 
              size       = size.small
              )

if brekout_res and not res_is_sup[1]
    label.new(
              bar_index[1], resistanceLevel[1], 
              text       = "Break Res", 
              style      = label.style_label_up, 
              color      = #2b6d2d, 
              textcolor  = chart.fg_color, 
              size       = size.small
              )


// โ—†
// ---------------------------------------------------------------------------------------------------------------------}


CodeRe: Already Converted TradingView Indicators to MT4 Indicators

453
Hi Mrtools and Kvak

here is an idea of mine that macd of osma. can you convert it in mt4?

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/
// ยฉ Alpha24

//@version=5
indicator("MACD of OSMA Original", overlay=false)

// User-defined inputs
shortLength = input(12, title="Short Length")
longLength = input(26, title="Long Length")
signalSmoothing = input(9, title="Signal Smoothing")

// Calculate MACD
macdLine = ta.ema(close, shortLength) - ta.ema(close, longLength)
signalLine = ta.ema(macdLine, signalSmoothing)
osma = macdLine - signalLine

// Calculate MACD of OSMA
osmaEma12 = ta.ema(osma, shortLength)
osmaEma26 = ta.ema(osma, longLength)
macdOfOsma = osmaEma12 - osmaEma26
signalLineOsma = ta.ema(macdOfOsma, signalSmoothing)
osmaOfMacdOfOsma = macdOfOsma - signalLineOsma

// Plotting
plot(macdOfOsma, color=color.blue, title="MACD of OSMA Original", linewidth=2)
plot(signalLineOsma, color=color.orange, title="Signal Line of OSMA", linewidth=2)
hline(0, "Zero Line", color=color.gray)
plot(osmaOfMacdOfOsma, color=#1aaace, title="OSMA of MACD of OSMA", style=plot.style_histogram, linewidth=1)
"Key of SUCCESS is BLINDLY BELIVE your SYSTEM "

Re: Already Converted TradingView Indicators to MT4 Indicators

454
alpha24 wrote: Mon Aug 19, 2024 12:24 am Hi Mrtools and Kvak

here is an idea of mine that macd of osma. can you convert it in mt4?

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/
// ยฉ Alpha24

//@version=5
indicator("MACD of OSMA Original", overlay=false)

// User-defined inputs
shortLength = input(12, title="Short Length")
longLength = input(26, title="Long Length")
signalSmoothing = input(9, title="Signal Smoothing")

// Calculate MACD
macdLine = ta.ema(close, shortLength) - ta.ema(close, longLength)
signalLine = ta.ema(macdLine, signalSmoothing)
osma = macdLine - signalLine

// Calculate MACD of OSMA
osmaEma12 = ta.ema(osma, shortLength)
osmaEma26 = ta.ema(osma, longLength)
macdOfOsma = osmaEma12 - osmaEma26
signalLineOsma = ta.ema(macdOfOsma, signalSmoothing)
osmaOfMacdOfOsma = macdOfOsma - signalLineOsma

// Plotting
plot(macdOfOsma, color=color.blue, title="MACD of OSMA Original", linewidth=2)
plot(signalLineOsma, color=color.orange, title="Signal Line of OSMA", linewidth=2)
hline(0, "Zero Line", color=color.gray)
plot(osmaOfMacdOfOsma, color=#1aaace, title="OSMA of MACD of OSMA", style=plot.style_histogram, linewidth=1)
MACD (OsMA of OsMA)

Think this is close.

PS: Further explanation on this indicator, here.
These users thanked the author mrtools for the post (total 11):
RodrigoRT7, Cagliostro, alpha24, moey_dw, kvak, Jimmy, ssotiro, Ricstar_8, macd & rsi, global, maroka


Re: Already Converted TradingView Indicators to MT4 Indicators

456
Hi dear coders.
Please if you can make this indicator.
It is open source code from Trading View.
Hope that we can have this for MT4

https://www.tradingview.com/script/Ty6C ... TR-Levels/

Code: Select all

// Saty ATR Levels
// Copyright (C) 2022 Saty Mahajan
// Author is not responsible for your trading using this script.
// Data provided in this script is not financial advice.
//
// Features:
// - Day, Multiday, Swing, Position, Long-term, Keltner trading modes
// - Range against ATR for each period
// - Put and call trigger idea levels
// - Intermediate levels
// - Full-range levels
// - Extension levels
// - Trend label based on the 8-21-34 Pivot Ribbon
//
// Special thanks to Gabriel Viana.
// Based on my own ideas and ideas from Ripster, drippy2hard, 
// Adam Sliver, and others.

//@version=5
indicator('Saty ATR Levels', shorttitle='Saty ATR Levels', overlay=true)

// Options
day_trading = 'Day'
multiday_trading = 'Multiday'
swing_trading = 'Swing'
position_trading = 'Position'
longterm_trading = 'Long-term'
trading_type = input.string(day_trading, 'Trading Type', options=[day_trading, multiday_trading, swing_trading, position_trading, longterm_trading])
use_options_labels = input(true, 'Use Options Labels')
atr_length = input(14, 'ATR Length')
trigger_percentage = input(0.236, 'Trigger Percentage')
previous_close_level_color = input(color.white, 'Previous Close Level Color')
lower_trigger_level_color = input(color.yellow, 'Lower Trigger Level Color')
upper_trigger_level_color = input(color.aqua, 'Upper Trigger Level Color')
key_target_level_color = input(color.silver, 'Key Target Level Color')
atr_target_level_color = input(color.white, 'ATR Target Level Color')
intermediate_target_level_color = input(color.gray, 'Intermediate Target Level Color')
show_all_fibonacci_levels = input(true, 'Show All Fibonacci Levels')
show_extensions = input(false, 'Show Extensions')
level_size = input(2, 'Level Size')
show_info = input(true, 'Show Info Label')
use_current_close = input(false, 'Use Current Close')
fast_ema = input(8, 'Fast EMA')
pivot_ema = input(21, 'Pivot EMA')
slow_ema = input(34, 'Slow EMA')

// Set the appropriate timeframe based on trading mode
timeframe_func() =>
    timeframe = 'D'
    if trading_type == day_trading
        timeframe := 'D'
    else if trading_type == multiday_trading
        timeframe := 'W'
    else if trading_type == swing_trading
        timeframe := 'M'
    else if trading_type == position_trading
        timeframe := '3M'
    else if trading_type == longterm_trading
        timeframe := '12M'
    else
        timeframe := 'D'

// Trend
price = close
fast_ema_value = ta.ema(price, fast_ema)
pivot_ema_value = ta.ema(price, pivot_ema)
slow_ema_value = ta.ema(price, slow_ema)
bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and pivot_ema_value >= slow_ema_value
bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and pivot_ema_value <= slow_ema_value

// Data
period_index = use_current_close ? 0 : 1
ticker = ticker.new(syminfo.prefix, syminfo.ticker, session=session.extended)
previous_close = request.security(ticker, timeframe_func(), close[period_index], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
atr = request.security(ticker, timeframe_func(), ta.atr(atr_length)[period_index], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
period_high = request.security(ticker, timeframe_func(), high, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
period_low = request.security(ticker, timeframe_func(), low, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
range_1 = period_high - period_low
tr_percent_of_atr = range_1 / atr * 100
lower_trigger = previous_close - trigger_percentage * atr
upper_trigger = previous_close + trigger_percentage * atr
lower_0382 = previous_close - atr * 0.382
upper_0382 = previous_close + atr * 0.382
lower_0500 = previous_close - atr * 0.5
upper_0500 = previous_close + atr * 0.5
lower_0618 = previous_close - atr * 0.618
upper_0618 = previous_close + atr * 0.618
lower_0786 = previous_close - atr * 0.786
upper_0786 = previous_close + atr * 0.786
lower_1000 = previous_close - atr
upper_1000 = previous_close + atr
lower_1236 = lower_1000 - atr * 0.236
upper_1236 = upper_1000 + atr * 0.236
lower_1382 = lower_1000 - atr * 0.382
upper_1382 = upper_1000 + atr * 0.382
lower_1500 = lower_1000 - atr * 0.5
upper_1500 = upper_1000 + atr * 0.5
lower_1618 = lower_1000 - atr * 0.618
upper_1618 = upper_1000 + atr * 0.618
lower_1786 = lower_1000 - atr * 0.786
upper_1786 = upper_1000 + atr * 0.786
lower_2000 = lower_1000 - atr
upper_2000 = upper_1000 + atr
lower_2236 = lower_2000 - atr * 0.236
upper_2236 = upper_2000 + atr * 0.236
lower_2382 = lower_2000 - atr * 0.382
upper_2382 = upper_2000 + atr * 0.382
lower_2500 = lower_2000 - atr * 0.5
upper_2500 = upper_2000 + atr * 0.5
lower_2618 = lower_2000 - atr * 0.618
upper_2618 = upper_2000 + atr * 0.618
lower_2786 = lower_2000 - atr * 0.786
upper_2786 = upper_2000 + atr * 0.786
lower_3000 = lower_2000 - atr
upper_3000 = upper_2000 + atr

// Add Labels
tr_vs_atr_color = color.green
if tr_percent_of_atr <= 70
    tr_vs_atr_color := color.green
else if tr_percent_of_atr >= 90
    tr_vs_atr_color := color.red
else
    tr_vs_atr_color := color.orange

trading_mode = 'Day'
if trading_type == day_trading
    trading_mode := 'Day'
else if trading_type == multiday_trading
    trading_mode := 'Multiday'
else if trading_type == swing_trading
    trading_mode := 'Swing'
else if trading_type == position_trading
    trading_mode := 'Position'
else if trading_type == longterm_trading
    trading_mode := 'Long-term'
else
    trading_mode := ''

long_label = ''
short_label = ''
if use_options_labels
    long_label := 'Calls'
    short_label := 'Puts'
else
    long_label := 'Long'
    short_label := 'Short'

trend_color = color.orange
if bullish
    trend_color := color.green
else if bearish
    trend_color := color.red
else
    trend_color := color.orange

var tbl = table.new(position.top_right, 1, 4)
if barstate.islast and show_info
    table.cell(tbl, 0, 0, 'Saty ATR Levels', bgcolor=trend_color)
    table.cell(tbl, 0, 1, trading_mode + ' Range ($' + str.tostring(range_1, '#.##') + ') is ' + str.tostring(tr_percent_of_atr, '#.#') + '% of ATR ($' + str.tostring(atr, '#.##') + ')', bgcolor=tr_vs_atr_color)
    table.cell(tbl, 0, 2, long_label + ' > $' + str.tostring(upper_trigger, '#.##') + ' | +1 ATR $' + str.tostring(upper_1000, '#.##'), bgcolor=upper_trigger_level_color)
    table.cell(tbl, 0, 3, short_label + ' < $' + str.tostring(lower_trigger, '#.##') + ' | -1 ATR: $' + str.tostring(lower_1000, '#.##'), bgcolor=lower_trigger_level_color)

// Add levels
plot(show_extensions ? lower_3000 : na, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='-300.0%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-278.6%', style=plot.style_stepline)
plot(show_extensions ? lower_2618 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='-261.8%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-250.0%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-238.2%', style=plot.style_stepline)
plot(show_extensions ? lower_2236 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='-223.6%', style=plot.style_stepline)
plot(show_extensions ? lower_2000 : na, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='-200.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-178.6%', style=plot.style_stepline)
plot(show_extensions ? lower_1618 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='-161.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-150.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-138.2%', style=plot.style_stepline)
plot(show_extensions ? lower_1236 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='-123.6%', style=plot.style_stepline)
plot(lower_1000, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='-100%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-78.6%', style=plot.style_stepline)
plot(lower_0618, color=color.new(key_target_level_color, 40), linewidth=level_size, title='-61.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-50.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='-38.2%', style=plot.style_stepline)
plot(lower_trigger, color=color.new(lower_trigger_level_color, 40), linewidth=level_size, title='Lower Trigger', style=plot.style_stepline)
plot(previous_close, color=color.new(previous_close_level_color, 40), linewidth=level_size, title='Previous Close', style=plot.style_stepline)
plot(upper_trigger, color=color.new(upper_trigger_level_color, 40), linewidth=level_size, title='Upper Trigger', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? upper_0382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='38.2%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? upper_0500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='50.0%', style=plot.style_stepline)
plot(upper_0618, color=color.new(key_target_level_color, 40), linewidth=level_size, title='61.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? upper_0786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='78.6%', style=plot.style_stepline)
plot(upper_1000, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='100%', style=plot.style_stepline)
plot(show_extensions ? upper_1236 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='123.6%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='138.2%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='150.0%', style=plot.style_stepline)
plot(show_extensions ? upper_1618 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='161.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='178.6%', style=plot.style_stepline)
plot(show_extensions ? upper_2000 : na, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='200.0%', style=plot.style_stepline)
plot(show_extensions ? upper_2236 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='223.6%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2382 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='238.2%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2500 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='250.0%', style=plot.style_stepline)
plot(show_extensions ? upper_2618 : na, color=color.new(key_target_level_color, 40), linewidth=level_size, title='261.8%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2786 : na, color=color.new(intermediate_target_level_color, 40), linewidth=level_size, title='278.6%', style=plot.style_stepline)
plot(show_extensions ? upper_3000 : na, color=color.new(atr_target_level_color, 40), linewidth=level_size, title='300%', style=plot.style_stepline)

Re: Already Converted TradingView Indicators to MT4 Indicators

457
mrtools wrote: Mon Aug 19, 2024 6:43 am Think this is close.
MACD of OsMA
Honey guys whats difference between this MACD of OsMA and a standard MACD OsMA!? Sorry looks good just no info/comparison & scratching my head!!!
Official Forex-station GIF animator at your service ๐Ÿ‘จโ€โš–๏ธ
See a GIF with Forex-station.com on it? I probably made it
The best divergence indicator in the world.
Real news exists: Infowars.com ๐Ÿ‘ˆ

Re: Already Converted TradingView Indicators to MT4 Indicators

458
moey_dw wrote: Tue Aug 20, 2024 8:24 pm Honey guys whats difference between this MACD of OsMA and a standard MACD OsMA!? Sorry looks good just no info/comparison & scratching my head!!!
The standard osma is a macd - macd signal. With the macd of osma it uses that osma (macd-signal) in its calculation to make another macd and signal with the histogram being the actual, guess you could call it an osma of osma , and the lines being a macd and signal of osma. Comparing it with a regular built in osma looks to sometimes be a couple of bars faster and a little bit smoother. Hopefully that helps, and probably Alpha24 will explain much better.
These users thanked the author mrtools for the post (total 3):
Rajamohamed, moey_dw, alpha24

Re: Already Converted TradingView Indicators to MT4 Indicators

459
mrtools wrote: Tue Aug 20, 2024 10:30 pm The standard osma is a macd - macd signal. With the macd of osma it uses that osma (macd-signal) in its calculation to make another macd and signal with the histogram being the actual, guess you could call it an osma of osma , and the lines being a macd and signal of osma. Comparing it with a regular built in osma looks to sometimes be a couple of bars faster and a little bit smoother. Hopefully that helps, and probably Alpha24 will explain much better.
You are right Mrtoolz its why I said it looks good because I find it is faster a few bars earlier than the traditional MACD OsMA.... thanks to two gentlemen for your idea and explanation here I believe this is a better MACD ๐Ÿ‘Œโค๏ธ๐Ÿ‘
These users thanked the author moey_dw for the post (total 3):
mrtools, alpha24, global
Official Forex-station GIF animator at your service ๐Ÿ‘จโ€โš–๏ธ
See a GIF with Forex-station.com on it? I probably made it
The best divergence indicator in the world.
Real news exists: Infowars.com ๐Ÿ‘ˆ

Re: Already Converted TradingView Indicators to MT4 Indicators

460
[url]https://www.tradingview.com/script/yYyu ... ies-Range/ Can anyone compile this code for mt4 ?

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ยฉ ClassicScott

// ACBR, or, Average Candle Bodies Range is a volatility and momentum indicator designed to indicate periods of increasing volatility and/or
// momentum. The genesis of the idea formed from my pondering what a trend trader is really looking for in terms of a volatility indicator. Most
// indicators I've come across haven't, in my opinion, done a satisfactory job of highlighting this. I kept thinking about the ATR (I use it for
// stops and targets) but I realized I didn't care about highs or lows in regards to a candle's volatility or momentum, nor do I care about their
// relation to a previous close. What really matters to me is candle body expansion. That is all. So, I created this.

// ACBR is extremely simple at its heart. I made it more complicated of course, because why would I want anything for myself to be simple?
// Originally it was envisaged to be a simple volatility indicator highlighting areas of increasing and decreasing volatility. Then I decided
// some folks might want an indicator that could show this in a directional manner, i.e., an oscillator, so I spent some more hours tackling that

// To start, the original version of the indicator simply subtracts opening price from closing price if the candle closes above the open, and
// subtracts the close from the open if the candle closes below the open. This way we get a positive number that simply measures candle expansion.
// We then apply a moving average to these values in order to smooth them (if you want). To get an oscillator we always subtract the close from
// the open, thus when a candle closes below its open we get a negative number.

// I've naturally added an optional signal line as a helpful way of gauging volatility because obviously the values themselves may not tell you
// much. But I've also added something that I call a baseline. You can use this in a few ways, but first let me explain the two options for how
// the baseline can be calculated. And what do I mean by 'baseline?' I think of it as an area of the indicator where if the ACBR is below you will
// not want to enter into any trades, and if the ACBR is above then you are free to enter trades based on your system (or you might want to enter
// in areas of low volatility if your system calls for that). Waddah Attar Explosion is another indicator that implements something similar.
// The baseline is calculated in two different ways: one of which is making a Donchian Channel of the ACBR, and then using the basis as the
// baseline, while the other is applying an RMA to the cb_dif, which is the base unit that makes up the ACBR. Now, the basis of a Donchian Channel
// typically is the average of the highs and the lows. If we did that here we would have a baseline much too high (but maybe not...), however,
// I've made the divisor user adjustable. In this way you can adjust the height (or I guess you might say 'width' if it's an oscillator) however
// you like, thus making the indicator more or less sensitive. In the case of using the ACBR as the baseline we apply a multiplier to the values
// in order to adjust the height. Apologies if I'm being overly verbose. If you want to skip all of this I have tooltips in the settings for all of
// the inputs that I think need an explanation.

// When using the indicator as an oscillator there are baselines above and below the zero line. One funny thing: if using the ACBR as calculation
// type for the baselines in oscillator mode, the baselines themselves will oscillate around the zero line. There is no way to fix this due to
// the calculation. That isn't necessarily bad (based on my eyeball test), but I probably wouldn't use it in such a way. But experiment! They
// could actually be a very fine entry or confirmation indicator. And while I'm on the topic of confirmation indicators, using this indicator as
// an oscillator naturally makes it a confirmation indicator. It just happens to have a volatility measurement baked into it. It may also be used
// as an exit and continuation indicator. And speaking of these things, there are optional shapes for indicating when you might want to exit or
// take a continuation trade. I've added alerts for these things too.

// Lastly, oscillator mode is good for identifying divergences.


// ****** \\
// *** A note on colors in the style tab
// I truly do not understand why TradingView has every single color grouped together under (nearly) every single adjustable element of the indicator.
// It makes no sense to me because only certain colors apply to certain aspects of it. I'm going to help you out here by giving you a cheat sheet
// so you can make color changes more easily.
// Colors 0 and 1 apply to the ACBR plot.
// Colors 2, 3, and 4 apply to the background coloring.
// Colors 5 and 6 apply to advancing and declining volatility (bar color for crosses)
// Colors 7, 8, and 9 apply to candle colors


//@version=5
indicator("+ Average Candle Bodies Range", shorttitle='+ AVG CBR', format=format.inherit , timeframe='', timeframe_gaps=true)

////INPUTS\\\\

//ACBR INPUTS
average_type = input.string(defval='EMA', options=['EMA', 'HMA', 'RMA', 'SMA', 'VWMA', 'WMA'], title='Smoothing Type', group='Candle Bodies Inputs')
period = input.int(defval=4, title='Period', group='Candle Bodies Inputs')

//SIGNAL LINE INPUTS
signal_type = input.string(defval='HMA', options=['EMA', 'HMA', 'RMA', 'SMA', 'VWMA', 'WMA'], title='Signal Type', group='Signal Line Inputs')
signal_period = input.int(defval=14, title='Period', group='Signal Line Inputs')

//BASELINE INPUTS
bline_type = input.string(defval='Donchian', options=['Donchian', 'ACBR'], title='Baseline Calculation Type', group='Baseline Inputs', tooltip='How the baseline is calculated to determine volatility is either via a Donchian Channel, whereby the highest and lowest of the average range is calculated over a determined period, and the basis is used as the baseline (this can be adjusted with the height input), or the Average Candle Bodies Range, which is adjusted by its own height input. If you are using this as an oscillator I dont recommend using the ACBR as a baseline because of the way it calculates, however, if you do try to use it this way at least have signal line momentum turned on.')
vol_period_type = input.string(defval='RexDog Self-Adjusting', options=['RexDog Self-Adjusting', 'User Selected'], title='Baseline Period Type', group='Baseline Inputs', tooltip='RexDog Self-Adjusting is based on the RexDog Average by xkavalis. It is an average of six different averages, thus it is dynamic, or self-adjusting, and can not be changed by the user. If you want to be able to choose an averaging period yourself select User Selected.')
vol_period = input.int(defval=200, title='Period', group='Baseline Inputs', tooltip='You can ignore this if using the RexDog BPT above, otherwise, a smaller number is going to be more reactive to changes in volatility, whereas a larger number will not. There is no right or wrong answer here.')
divisor = input.float(defval=3, title='Donchian Calculated Height', minval=0.1, step=0.1, group='Baseline Inputs', tooltip='This adjusts the height of your baseline, and, if using the RexDog BPT, is the only way to adjust the sensitivity. A smaller number makes for a baseline farther away from zero. Probably want to stay above two. Three to three and a half is a good range to start.')
cb_mult = input.float(defval=1, title='ACBR Calculated Height', minval=0.1, step=0.1, group='Baseline Inputs', tooltip='Same as above but for two things. One: contrary to the Donchian height, a larger number increases the distance of the baseline from zero (I recommend no greater than 1 in non-directional mode, and even that, in my opinion, is too high). Two: if using as an oscillator, the baseline period plays heavily into how you will adjust the height. Larger numbers like 200 need a larger height, like 3. However, as stated in the above first tooltip, I dont recommend it being used this way.')

//GENERAL OPTIONS
signal_rise_fall = input.bool(defval=true, title='Require Increasing Momentum of Signal Line', group='General Options', tooltip='Require that the signal line be rising in non-directional mode, or, when in oscillator mode, rising when the ACBR is above zero and falling when it is below zero to highlight increasing volatility. Remember, a moving average (which is what a signal line is) is a measure of the momentum of the underlying source, in this case volatility. In oscillator mode a falling signal line would be defined as increasing in momentum once the ACBR crosses below zero.')
avg_range_style = input.bool(defval=false, title='ACBR is Directional', group='General Options', tooltip='If checked the ACBR oscillates around a zero line indicating bullish or bearish volatility. If unchecked it is a measure of market volatility only, and does not indicate a direction to trade in.')

//BAR COLOR AND BACKGROUND COLOR SIGNAL LINE OPTIONS
bg_signal = input.bool(defval=false, title='Color Background', group='Signal Line Options', tooltip='Colors background if the ACBR is beyond the signal line.')
barcolor_signal = input.bool(defval=false, title='Color Bars', group='Signal Line Options', tooltip='Colors bars if the ACBR is beyond the signal line.')
strong_signal = input.bool(false, 'Volatility Advancing', group='Signal Line Options', tooltip='Colors the bar when the ACBR crosses above the signal line in non-directional mode. Colors the bar when the ACBR crosses above the signal line when above zero or below the signal line when below zero in oscillator mode.')
weak_signal = input.bool(false, 'Volatility Declining', group='Signal Line Options', tooltip='Colors the bar when the ACBR crosses below the signal line when in non-directional mode. Colors the bar when the ACBR crosses below the signal line when above zero or above the signal line when below zero in oscillator mode.')

//BAR COLOR AND BACKGROUND COLOR BASELINE OPTIONS
bg_bline = input.bool(defval=false, title='Color Background', group='Baseline Options', tooltip='Colors background if the ACBR is beyond the baseline(s).')
barcolor_bline = input.bool(defval=true, title='Color Bars', group='Baseline Options', tooltip='Colors bars if the ACBR is beyond the baseline(s).')
strong_bline = input.bool(false, 'Volatility Advancing', group='Baseline Options', tooltip='Colors the bar when the ACBR crosses above the baseline in non-directional mode. Colors the bar when the ACBR crosses above the upper baseline or below the lower baseline when in oscillator mode.')
weak_bline = input.bool(false, 'Volatility Declining', group ='Baseline Options', tooltip='Colors the bar when the ACBR crosses below the baseline in non-directional mode. Colors the bar when the ACBR crosses below the upper baseline or above the lower baseline when in oscillator mode.')


/////////////////////////////////////////////////////////////////////////////////////


////CANDLE BODY CALCULATION
float cb_dif = 0.0
if not avg_range_style and close > open
cb_dif := close - open
else if not avg_range_style and close < open
cb_dif := open - close
else if avg_range_style
cb_dif := close - open


////MOVING AVERAGE TO USE TO CREATE THE AVERAGE
cb_range(type, src, period) =>
float result = 0
if type == 'EMA'
result := ta.ema(cb_dif, period)
if type == 'HMA'
result := ta.hma(cb_dif, period)
if type == 'RMA'
result := ta.rma(cb_dif, period)
if type == 'SMA'
result := ta.sma(cb_dif, period)
if type == 'VWMA'
result := ta.vwma(cb_dif, period)
if type == 'WMA'
result := ta.wma(cb_dif, period)
result

avg_range = cb_range(average_type, cb_dif, period)


////SIGNAL LINE CHOICES
signal(type, src, signal_period) =>
float result = 0
if type == 'EMA'
result := ta.ema(avg_range, signal_period)
if type == 'HMA'
result := ta.hma(avg_range, signal_period)
if type == 'RMA'
result := ta.rma(avg_range, signal_period)
if type == 'SMA'
result := ta.sma(avg_range, signal_period)
if type == 'VWMA'
result := ta.vwma(avg_range, signal_period)
if type == 'WMA'
result := ta.wma(avg_range, signal_period)
result

signal_line = signal(signal_type, avg_range, signal_period)


/////////////////////////////////////////////////////////////////////////////////////


////CALCULATIONS FOR BASELINE VOLATILITY
//DONCHIAN CHANNEL
highest_baseline = vol_period_type == 'RexDog Self-Adjusting' ? (ta.highest(avg_range, 5) + ta.highest(avg_range, 9) + ta.highest(avg_range, 24) + ta.highest(avg_range, 50) + ta.highest(avg_range, 100) + ta.highest(avg_range, 200)) / 6 : ta.highest(avg_range, vol_period)
lowest_baseline = vol_period_type == 'RexDog Self-Adjusting' ? (ta.lowest(avg_range, 5) + ta.lowest(avg_range, 9) + ta.lowest(avg_range, 24) + ta.lowest(avg_range, 50) + ta.lowest(avg_range, 100) + ta.lowest(avg_range, 200)) / 6 : ta.lowest(avg_range, vol_period)

//ACBR
acbr_baseline = vol_period_type == 'RexDog Self-Adjusting' ? (ta.rma(cb_dif, 5) + ta.rma(cb_dif, 9) + ta.rma(cb_dif, 24) + ta.rma(cb_dif, 50) + ta.rma(cb_dif, 100) + ta.rma(cb_dif, 200)) / 6 : ta.rma(cb_dif, vol_period)

//COMPLETE
high_baseline = bline_type == 'Donchian' and avg_range_style ? highest_baseline / divisor : bline_type == 'Donchian' and not avg_range_style ? (highest_baseline + lowest_baseline) / divisor : bline_type == 'ACBR' ? acbr_baseline * cb_mult : na
low_baseline = bline_type == 'Donchian' and avg_range_style ? lowest_baseline / divisor : bline_type == 'ACBR' ? acbr_baseline * cb_mult * -1 : na


/////////////////////////////////////////////////////////////////////////////////////


////ACBR COLOR
avg_range_color = if not avg_range_style and avg_range > avg_range[1]
color.new(#ff9800, 0)
else if not avg_range_style and avg_range < avg_range[1]
color.new(#2962ff, 0)
else if avg_range > 0 and avg_range > avg_range[1] and avg_range_style
color.new(#ff9800, 0)
else if avg_range > 0 and avg_range < avg_range[1] and avg_range_style
color.new(#2962ff, 0)
else if avg_range < 0 and avg_range < avg_range[1] and avg_range_style
color.new(#ff9800, 0)
else if avg_range < 0 and avg_range > avg_range[1] and avg_range_style
color.new(#2962ff, 0)


/////////////////////////////////////////////////////////////////////////////////////


////PLOTS
plot(avg_range, title='Average Candle Bodies Range', color=avg_range_color, linewidth=2, style=plot.style_histogram)
plot(signal_line, title='Signal Line', color=signal_line > 0 and signal_line > signal_line[1] or signal_line < 0 and signal_line < signal_line[1] ? color.new(#00bcd4, 0) : signal_line < 0 and signal_line > signal_line[1] or signal_line > 0 and signal_line < signal_line[1] ? color.new(#e91e63, 0) : na , linewidth=2, style=plot.style_line)
plot(high_baseline, title='High Baseline', color=color.yellow, style=plot.style_line)
plot(avg_range_style ? low_baseline : na, title='Low Baseline', color=color.yellow, style=plot.style_line)


/////////////////////////////////////////////////////////////////////////////////////


//SIGNAL LINE RISING/FALLING -- SEE signal_rise_fall UNDER GENERAL OPTIONS
signal_rising = signal_rise_fall and signal_line > signal_line[1]
signal_falling = signal_rise_fall and signal_line < signal_line[1]


/////////////////////////////////////////////////////////////////////////////////////
////BACKGROUND COLOR CONDITIONS AND COLORING


//DIRECTIONAL
dir_above_bline = bg_bline and avg_range_style and high_baseline > 0 and avg_range > high_baseline or bg_bline and low_baseline > 0 and avg_range > low_baseline
dir_below_bline = bg_bline and avg_range_style and low_baseline < 0 and avg_range < low_baseline or bg_bline and high_baseline < 0 and avg_range < high_baseline
dir_above_signal = bg_signal and avg_range_style and avg_range > 0 and avg_range > signal_line
dir_below_signal = bg_signal and avg_range_style and avg_range < 0 and avg_range < signal_line


//NON-DIRECTIONAL
above_bline = bg_bline and not avg_range_style and avg_range > high_baseline
below_bline = bg_bline and not avg_range_style and avg_range < high_baseline
above_signal = bg_signal and not avg_range_style and avg_range > signal_line
below_signal = bg_signal and not avg_range_style and avg_range < signal_line


//ABOVE BASELINE
AboveBaselineStrongSignal = if (signal_rising and above_bline)
color.new(#00bcd4, 50)
else if (signal_rising and below_bline or signal_falling and below_bline)
color.new(#e91e63, 100)
else if (signal_rising and dir_above_bline)
color.new(#00bcd4, 50)
else if (signal_falling and dir_below_bline)
color.new(#e91e63, 50)

AboveBaseline = if (not signal_rise_fall and above_bline)
color.new(#00bcd4, 50)
else if (not signal_rise_fall and below_bline)
color.new(#e91e63, 100)
else if (not signal_rise_fall and dir_above_bline)
color.new(#00bcd4, 50)
else if (not signal_rise_fall and dir_below_bline)
color.new(#e91e63, 50)

//ABOVE SIGNAL LINE
AboveSignalLineStrongSignal = if (signal_rising and above_signal)
color.new(#00bcd4, 50)
else if (signal_rising and below_signal or signal_falling and below_signal)
color.new(#e91e63, 100)
else if (signal_rising and dir_above_signal)
color.new(#00bcd4, 50)
else if (signal_falling and dir_below_signal)
color.new(#e91e63, 50)

AboveSignalLine = if (not signal_rise_fall and above_signal)
color.new(#00bcd4, 50)
else if (not signal_rise_fall and below_signal)
color.new(#e91e63, 100)
else if (not signal_rise_fall and dir_above_signal)
color.new(#00bcd4, 50)
else if (not signal_rise_fall and dir_below_signal)
color.new(#e91e63, 50)


bgcolor(AboveBaselineStrongSignal, title='Background | ACBR > Baseline & Signal Rising')
bgcolor(AboveBaseline, title='Background | ACBR > Baseline')
bgcolor(AboveSignalLineStrongSignal, title='Background | ACBR > Signal Line & Signal Rising')
bgcolor(AboveSignalLine, title='Background | ACBR > Signal Line')


/////////////////////////////////////////////////////////////////////////////////////
////BAR COLOR CONDITIONS AND COLORING (ACBR CROSSING ABOVE OR BELOW BASELINE/SIGNAL LINE)


//DIRECTIONAL
dir_barcolor_strong_bline_up = strong_bline and avg_range_style and high_baseline > 0 and ta.crossover(avg_range, high_baseline) or strong_bline and avg_range_style and low_baseline > 0 and ta.crossover(avg_range, low_baseline)
dir_barcolor_strong_bline_down = strong_bline and avg_range_style and high_baseline < 0 and ta.crossunder(avg_range, high_baseline) or strong_bline and avg_range_style and low_baseline < 0 and ta.crossunder(avg_range, low_baseline)
dir_barcolor_weak_bline_up = weak_bline and avg_range_style and high_baseline > 0 and ta.crossunder(avg_range, high_baseline) or weak_bline and avg_range_style and low_baseline > 0 and ta.crossunder(avg_range, low_baseline)
dir_barcolor_weak_bline_down = weak_bline and avg_range_style and high_baseline < 0 and ta.crossover(avg_range, high_baseline) or weak_bline and avg_range_style and low_baseline < 0 and ta.crossover(avg_range, low_baseline)
dir_barcolor_strong_signal_up = strong_signal and avg_range_style and avg_range > 0 and ta.crossover(avg_range, signal_line)
dir_barcolor_strong_signal_down = strong_signal and avg_range_style and avg_range < 0 and ta.crossunder(avg_range, signal_line)
dir_barcolor_weak_signal = weak_signal and avg_range_style and avg_range > 0 and ta.crossunder(avg_range, signal_line) or weak_signal and avg_range_style and avg_range < 0 and ta.crossover(avg_range, signal_line)


//NON-DIRECTIONAL
barcolor_strong_bline = not avg_range_style and strong_bline and ta.crossover(avg_range, high_baseline)
barcolor_weak_bline = not avg_range_style and weak_bline and ta.crossunder(avg_range, high_baseline)
barcolor_strong_signal = not avg_range_style and strong_signal and ta.crossover(avg_range, signal_line)
barcolor_weak_signal = not avg_range_style and weak_signal and ta.crossunder(avg_range, signal_line)


BarColorBaselineCrossStrongSignal = if (signal_rising and barcolor_strong_bline)
#ffeb3b
else if (barcolor_weak_bline)
#673ab7
else if (signal_rising and dir_barcolor_strong_bline_up or signal_falling and dir_barcolor_strong_bline_down)
#ffeb3b
else if (dir_barcolor_weak_bline_up or dir_barcolor_weak_bline_down)
#673ab7


BarColorBaselineCross = if (not signal_rise_fall and barcolor_strong_bline)
#ffeb3b
else if (not signal_rise_fall and barcolor_weak_bline)
#673ab7
else if (not signal_rise_fall and dir_barcolor_strong_bline_up or not signal_rise_fall and dir_barcolor_strong_bline_down)
#ffeb3b
else if (dir_barcolor_weak_bline_up or dir_barcolor_weak_bline_down)
#673ab7

BarColorSignalLineCrossStrongSignal = if (signal_rising and barcolor_strong_signal)
#ffeb3b
else if (barcolor_weak_signal)
#673ab7
else if (signal_rising and dir_barcolor_strong_signal_up)
#ffeb3b
else if (signal_falling and dir_barcolor_strong_signal_down)
#ffeb3b
else if (dir_barcolor_weak_signal)
#673ab7

BarColorSignalLineCross = if (not signal_rise_fall and barcolor_strong_signal)
#ffeb3b
else if (not signal_rise_fall and barcolor_weak_signal)
#673ab7
else if (not signal_rise_fall and dir_barcolor_strong_signal_up)
#ffeb3b
else if (not signal_rise_fall and dir_barcolor_strong_signal_down)
#ffeb3b
else if (dir_barcolor_weak_signal)
#673ab7


barcolor(BarColorBaselineCrossStrongSignal, title='Bar Color | ACBR Baseline Cross & Signal Rising')
barcolor(BarColorBaselineCross, title='Bar Color | ACBR Baseline Cross ')
barcolor(BarColorSignalLineCrossStrongSignal, title='Bar Color | ACBR Signal Line Cross & Signal Rising')
barcolor(BarColorSignalLineCross, title='Bar Color | ACBR Signal Line Cross')


/////////////////////////////////////////////////////////////////////////////////////
////BAR COLOR CONDITIONS AND COLORING (ACBR ABOVE OR BELOW BASELINE/SIGNAL LINE)


//DIRECTIONAL
dir_barcolor_above_bline = barcolor_bline and avg_range_style and high_baseline > 0 and avg_range > high_baseline or barcolor_bline and low_baseline > 0 and avg_range > low_baseline
dir_barcolor_below_bline = barcolor_bline and avg_range_style and low_baseline < 0 and avg_range < low_baseline or barcolor_bline and high_baseline < 0 and avg_range < high_baseline
dir_barcolor_neutral_bline = barcolor_bline and avg_range_style and avg_range < high_baseline and avg_range > low_baseline or barcolor_bline and avg_range_style and avg_range > high_baseline and avg_range < low_baseline or barcolor_bline and avg_range_style and signal_falling and avg_range > high_baseline or barcolor_bline and avg_range_style and signal_rising and avg_range < low_baseline
dir_barcolor_above_signal = barcolor_signal and avg_range_style and avg_range > 0 and avg_range > signal_line
dir_barcolor_below_signal = barcolor_signal and avg_range_style and avg_range < 0 and avg_range < signal_line
dir_barcolor_neutral_signal = barcolor_signal and avg_range_style and avg_range > 0 and avg_range < signal_line or barcolor_signal and avg_range_style and avg_range < 0 and avg_range > signal_line or barcolor_signal and avg_range_style and avg_range > 0 and avg_range > signal_line and signal_falling or barcolor_signal and avg_range_style and avg_range < 0 and avg_range < signal_line and signal_rising

//NON-DIRECTIONAL
barcolor_above_bline = barcolor_bline and not avg_range_style and avg_range > high_baseline
barcolor_below_bline = barcolor_bline and not avg_range_style and avg_range < high_baseline
barcolor_above_signal = barcolor_signal and not avg_range_style and avg_range > signal_line
barcolor_below_signal = barcolor_signal and not avg_range_style and avg_range < signal_line


//ABOVE BASELINE
BarColorAboveBaselineStrongSignal = if (signal_rising and barcolor_above_bline)
color.new(#00bcd4, 0)
else if (signal_rising and barcolor_below_bline or signal_falling and barcolor_above_bline or signal_falling and barcolor_below_bline)
color.new(#e91e63, 0)
else if (signal_rising and dir_barcolor_above_bline)
color.new(#00bcd4, 0)
else if (signal_falling and dir_barcolor_below_bline)
color.new(#e91e63, 0)
else if (dir_barcolor_neutral_bline)
color.new(color.gray, 0)

BarColorAboveBaseline = if (not signal_rise_fall and barcolor_above_bline)
color.new(#00bcd4, 0)
else if (not signal_rise_fall and barcolor_below_bline)
color.new(#e91e63, 0)
else if (not signal_rise_fall and dir_barcolor_above_bline)
color.new(#00bcd4, 0)
else if (not signal_rise_fall and dir_barcolor_below_bline)
color.new(#e91e63, 0)
else if (dir_barcolor_neutral_bline)
color.new(color.gray, 0)

//ABOVE SIGNAL LINE
BarColorAboveSignalLineStrongSignal = if (signal_rising and barcolor_above_signal)
color.new(#00bcd4, 0)
else if (signal_rising and barcolor_below_signal or signal_falling and barcolor_above_signal or signal_falling and barcolor_below_signal)
color.new(#e91e63, 0)
else if (signal_rising and dir_barcolor_above_signal)
color.new(#00bcd4, 0)
else if (signal_falling and dir_barcolor_below_signal)
color.new(#e91e63, 0)
else if (dir_barcolor_neutral_signal)
color.new(color.gray, 0)

BarColorAboveSignalLine = if (not signal_rise_fall and barcolor_above_signal)
color.new(#00bcd4, 0)
else if (not signal_rise_fall and barcolor_below_signal)
color.new(#e91e63, 0)
else if (not signal_rise_fall and dir_barcolor_above_signal)
color.new(#00bcd4, 0)
else if (not signal_rise_fall and dir_barcolor_below_signal)
color.new(#e91e63, 0)
else if (dir_barcolor_neutral_signal)
color.new(color.gray, 0)


barcolor(BarColorAboveBaselineStrongSignal, title='Bar Color | ACBR > Baseline & Signal Rising')
barcolor(BarColorAboveBaseline, title='Bar Color | ACBR > Baseline')
barcolor(BarColorAboveSignalLineStrongSignal, title='Bar Color | ACBR > Signal Line & Signal Rising')
barcolor(BarColorAboveSignalLine, title='Bar Color | ACBR > Signal Line')


/////////////////////////////////////////////////////////////////////////////////////


///CONTINUATION TRADE SYMBOLS
bull_cont_trade = avg_range_style and avg_range > 0 and avg_range[1] < signal_line and ta.crossover(avg_range, signal_line)
bear_cont_trade = avg_range_style and avg_range < 0 and avg_range[1] > signal_line and ta.crossunder(avg_range, signal_line)

plotshape(bull_cont_trade, title='Bullish Continuation', style=shape.arrowup, location=location.bottom, color=color.blue)
plotshape(bear_cont_trade, title='Bearish Continuation', style=shape.arrowdown, location=location.top, color=color.red)


////EXIT TRADE SYMBOLS
exit_long_quickly = signal_line > 0 and signal_line < signal_line[1] and signal_line[1] > signal_line[2]
exit_long_slowly = signal_line > 0 and ta.crossunder(avg_range, signal_line)
exit_short_quickly = signal_line < 0 and signal_line > signal_line[1] and signal_line[1] < signal_line[2]
exit_short_slowly = signal_line < 0 and ta.crossover(avg_range, signal_line)

plotshape(exit_short_quickly, title='Quick Exit Short', style=shape.xcross, location=location.bottom, color=color.blue)
plotshape(exit_short_slowly, title='Slow Exit Short', style=shape.xcross, location=location.bottom, color=color.blue)
plotshape(exit_long_quickly, title='Quick Exit Long', style=shape.xcross, location=location.top, color=color.red)
plotshape(exit_long_slowly, title='Slow Exit Long', style=shape.xcross, location=location.top, color=color.red)

hline(0, title='Zero Line', color=color.silver, linestyle=hline.style_dotted)


/////////////////////////////////////////////////////////////////////////////////////


////ALERT CONDITIONS
alertcondition(bull_cont_trade, title='Continuation Trade - Bullish', message='Bullish continuation trade by ACBR.')
alertcondition(bear_cont_trade, title='Continuation Trade - Bearish', message='Bearish continuation trade by ACBR.')
alertcondition(exit_long_quickly, title='Exit Long Quickly', message='Exit long trade, by ACBR.')
alertcondition(exit_long_slowly, title='Exit Long Slowly', message='Exit long trade, by ACBR.')
alertcondition(exit_short_quickly, title='Exit Short Quickly', message='Exit short trade, by ACBR.')
alertcondition(exit_short_slowly, title='Exit Short Slowly', message='Exit short trade, by ACBR.')
alertcondition(high_baseline > 0 and ta.crossover(avg_range, high_baseline) or low_baseline > 0 and ta.crossover(avg_range, low_baseline), title='ACBR Crossing Above Upper Baseline', message='ACBR has crossed above the upper baseline.')
alertcondition(high_baseline < 0 and ta.crossunder(avg_range, high_baseline) or low_baseline < 0 and ta.crossunder(avg_range, low_baseline), title='ACBR Crossing Below Lower Baseline', message='ACBR has crossed below the lower baseline.')
alertcondition(avg_range > 0 and ta.crossover(avg_range, signal_line), title='ACBR Crossing Above Signal Line Trade Entry', message='ACBR has crossed above the signal line. Possible trade entry.')
alertcondition(avg_range < 0 and ta.crossunder(avg_range, signal_line), title='ACBR Crossing Below Signal Line Trade Entry', message='ACBR has crossed below the signal line. Possible trade entry.')


+++ACBR, or, Average Candle Bodies Range is a volatility and momentum indicator designed to indicate periods of increasing volatility and/or momentum. The genesis of the idea formed from my pondering what a trend trader is really looking for in terms of a volatility indicator. Most indicators I've come across haven't, in my opinion, done a satisfactory job of highlighting this. I kept thinking about the ATR (I use it for stops and targets) but I realized I didn't care about highs or lows in regards to a candle's volatility or momentum, nor do I care about their relation to a previous close. What really matters to me is candle body expansion. That is all. So, I created this.

ACBR is extremely simple at its heart. I made it more complicated of course, because why would I want anything for myself to be simple? Originally it was envisaged to be a simple volatility indicator highlighting areas of increasing and decreasing volatility. Then I decided some folks might want an indicator that could show this in a directional manner, i.e., an oscillator, so I spent some more hours tackling that

To start, the original version of the indicator simply subtracts opening price from closing price if the candle closes above the open, and subtracts the close from the open if the candle closes below the open. This way we get a positive number that simply measures candle expansion. We then apply a moving average to these values in order to smooth them (if you want). To get an oscillator we always subtract the close from the open, thus when a candle closes below its open we get a negative number.

I've naturally added an optional signal line as a helpful way of gauging volatility because obviously the values themselves may not tell you much. But I've also added something that I call a baseline. You can use this in a few ways, but first let me explain the two options for how the baseline can be calculated. And what do I mean by 'baseline?' I think of it as an area of the indicator where if the ACBR is below you will not want to enter into any trades, and if the ACBR is above then you are free to enter trades based on your system (or you might want to enter in areas of low volatility if your system calls for that). Waddah Attar Explosion is another indicator that implements something similar. The baseline is calculated in two different ways: one of which is making a Donchian Channel of the ACBR, and then using the basis as the baseline, while the other is applying an RMA to the cb_dif, which is the base unit that makes up the ACBR. Now, the basis of a Donchian Channel typically is the average of the highs and the lows. If we did that here we would have a baseline much too high (but maybe not...), however, I've made the divisor user adjustable. In this way you can adjust the height (or I guess you might say 'width' if it's an oscillator) however you like, thus making the indicator more or less sensitive. In the case of using the ACBR as the baseline we apply a multiplier to the values in order to adjust the height. Apologies if I'm being overly verbose. If you want to skip all of this I have tooltips in the settings for all of the inputs that I think need an explanation.

When using the indicator as an oscillator there are baselines above and below the zero line. One funny thing: if using the ACBR as calculation type for the baselines in oscillator mode, the baselines themselves will oscillate around the zero line. There is no way to fix this due to the calculation. That isn't necessarily bad (based on my eyeball test), but I probably wouldn't use it in such a way. But experiment! They could actually be a very fine entry or confirmation indicator. And while I'm on the topic of confirmation indicators, using this indicator as an oscillator naturally makes it a confirmation indicator. It just happens to have a volatility measurement baked into it. It may also be used as an exit and continuation indicator. And speaking of these things, there are optional shapes for indicating when you might want to exit or take a continuation trade. I've added alerts for these things too.

Lastly, oscillator mode is good for identifying divergences.