
Creator Message: https://www.tradingview.com/v/I5qJDPxT/
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RedKTrader - March 2023
#// https://www.tradingview.com/v/I5qJDPxT/
#// inspecting the effort vs result concept by plotting volume vs. price change
#// this is like looking at distance versus fuel consumption - but comparing a normalized average of each
#// to help reveal areas of volume & price action anomalies, contraction & expansion
#indicator('RedK Effort Versus Results Explorer', 'RedK EVEREX v1.0', precision = 0,
# Converted and mod by [email protected] - 03/2023
declare lower;
input UseChartTimeframe = yes;
input CustomAggregation = AggregationPeriod.FIFTEEN_MIN;
input DisplayType = {Default EVEREX, Bias, Both};
input ColorBars = yes;
input BiasLabel = yes;
input Signal_Line = yes;
input rofLine = yes;
input bandScale = {default "100", "200", "400"}; # "Band Scale"
input LookbackCalcType = {default "Simple", "Same as RRoF"}; # 'Lookback Averaging Type'
input lookback = 20; # 'lookback'
input RofType = {default WMA, EMA, SMA, HMA, RMA, SMMA, MAV}; # 'MA type'
input RofLength = 10; # 'ROF Length'
input RofSmooth = 3; # 'Smooth'
input SignalType = {default WMA, EMA, SMA, HMA, RMA, SMMA, MAV}; # 'Signal Ma Type'
input signalLength = 5; # 'Signal Length'
input BiasType = {default WMA, EMA, SMA, HMA, RMA, SMMA, MAV}; # 'Bias MA type',
input BiasLength = 30; # 'Bias Length'
def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def last = isNaN(close);
def scale = if bandscale == bandscale."100" then 100 else
if bandscale == bandscale."200" then 200 else
if bandscale == bandscale."400" then 400 else scale[1];
def ikbk = LookbackCalcType == LookbackCalcType."Simple";
def DispBias = DisplayType==DisplayType.Bias or DisplayType==DisplayType.Both;
def DispEVEREX = DisplayType==DisplayType.EVEREX or DisplayType==DisplayType.Both;
def chartTf = GetAggregationPeriod();
def tf = if UseChartTimeframe then chartTf else CustomAggregation;
def close = close(Period=tf);
def high = high(Period=tf);
def low = low(Period=tf);
def open = open(Period=tf);
def volume = volume(Period=tf);
#---- Color
DefineGlobalColor("c_vol_grn" , CreateColor(15, 65, 61));
DefineGlobalColor("b_vol_grn" , CreateColor(33,145,135));
DefineGlobalColor("c_vol_red" , CreateColor(84, 9, 8));
DefineGlobalColor("b_vol_red" , CreateColor(235,37,33));
DefineGlobalColor("c_pri_grn" , CreateColor(13,62,13));
DefineGlobalColor("b_pri_grn" , CreateColor(43,208,43));
DefineGlobalColor("c_pri_red" , CreateColor(83,42,0));
DefineGlobalColor("b_pri_red" , CreateColor(240,122,0));
DefineGlobalColor("c_up" , CreateColor(41,98,255));
DefineGlobalColor("c_dn" , CreateColor(255,152,0));
DefineGlobalColor("green" , CreateColor(0,177,0));
DefineGlobalColor("red" , CreateColor(177,0,0));
DefineGlobalColor("dgreen" , CreateColor(0,39,0));
DefineGlobalColor("dred" , CreateColor(59,0,0));
#// --- Functions
#GetAverage(_data, _len, MAOption) =>
script GetAverage {
input _data = close;
input _len = 10;
input MAOption = "SMA";
def w = wma(_data, _len);
def mav = ((Average(_data, _len)[1]*(_len-1)) + _data) / _len;
def GetAverage = if MAOption == "SMA" then Average(_data, _len) else
if MAOption == "SMMA" then if isNaN(w[1]) then average(_data, _len) else
CompoundValue(1, (w[1] * (_len - 1) + _data) / _len, average(_data, _len)) else
if MAOption == "EMA" then ExpAverage(_data, _len) else
if MAOption == "MAV" then mav else
if MAOption == "HMA" then HullMovingAvg(_data, _len) else
if MAOption == "RMA" then WildersAverage(_data, _len) else
if MAOption == "WMA" then WMA(_data, _len) else Average(_data, _len);
plot out = GetAverage;
}
#Normalize(_Value, _Avg) =>
script Normalize {
input _Value = close;
input _Avg = 10;
def _X = _Value / _Avg;
def _Nor =
if _X > 1.50 then 1.00 else
if _X > 1.20 then 0.90 else
if _X > 1.00 then 0.80 else
if _X > 0.80 then 0.70 else
if _X > 0.60 then 0.60 else
if _X > 0.40 then 0.50 else
if _X > 0.20 then 0.25 else 0.1;
plot norm = _Nor;
}
#// Calculations
def v = if IsNaN(volume) then 1 else volume;
def NoVol_Flag = if IsNaN(volume) then yes else no;# // this is a flag to use later
def Vola = if ikbk then Average(v,lookback) else GetAverage(v, lookback, RofType);
def Vola_n_pre = Normalize(v, Vola) * 100;
#//Now trap the case of no volume data - ensure final calculation not impacted
def Vola_n = if NoVol_Flag then 100 else Vola_n_pre;
def BarSpread = close - open;
def BarRange = high - low;
def R2 = Highest(high, 2) - Lowest(low, 2);
def SrcShift = close - close[1];
#//TR = ta.tr(true)
def sign_shift = Sign(SrcShift);
def sign_spread = Sign(BarSpread);
#// in-bar assessments
def barclosing = 2 * (close - low) / BarRange * 100 - 100;
def s2r = BarSpread / BarRange * 100;
def BarSpread_abs = AbsValue(BarSpread);
def BarSpread_avg = if ikbk then Average(BarSpread_abs,lookback) else GetAverage(BarSpread_abs, lookback, RofType);
def BarSpread_ratio_n = Normalize(BarSpread_abs, BarSpread_avg) * 100 * sign_spread ;
#// 2-bar assessments
def barclosing_2 = 2 * (close - Lowest(low, 2)) / R2 * 100 - 100;
def Shift2Bar_toR2 = SrcShift / R2 * 100;
def SrcShift_abs = AbsValue(SrcShift);
def srcshift_avg = if ikbk then Average(SrcShift_abs,lookback) else GetAverage(SrcShift_abs, lookback, RofType);
def srcshift_ratio_n = Normalize(SrcShift_abs, srcshift_avg) * 100 * sign_shift;
#/ Relative Price Strength combining all strength elements
def Pricea_n = (barclosing + s2r + BarSpread_ratio_n + barclosing_2 + Shift2Bar_toR2 + srcshift_ratio_n) / 6;# "Price Normalized"
#//Let's take Bar Flow as the combined price strength * the volume:avg ratio
def bar_flow = Pricea_n * Vola_n / 100;
#/ Relative Price Strength combining all strength elements
def bulls = Max(bar_flow, 0);
def bears = -1 * Min(bar_flow, 0);
def bulls_avg = GetAverage(bulls, RofLength, RofType);
def bears_avg = GetAverage(bears, RofLength, RofType);
def dx = bulls_avg / bears_avg;
def RROF = 2 * (100 - 100 / (1 + dx)) - 100;
def RROF_s = WMA(RROF, RofSmooth);
def Signal = GetAverage(RROF_s, signalLength, SignalType);
#// Calculate Bias / sentiment on longer length
def dx_b = GetAverage(bulls, BiasLength, BiasType) / GetAverage(bears, BiasLength, BiasType);
def RROF_b = 2 * (100 - 100 / (1 + dx_b)) - 100;
def RROF_bs = WMA(RROF_b, RofSmooth);
#// Colors & plots
def up = RROF_s >= 0;
def s_up = RROF_bs >= 0;
plot level1 = if last then na else 0.25 * scale; # '1/4 Level'
plot level2 = if last then na else 0.50 * scale; # '2/4 Level'
plot level3 = if last then na else 0.75 * scale; # '3/4 Level'
plot level4 = if last then na else scale; # '4/4 Level'
level1.SetDefaultColor(Color.GRAY);
level2.SetDefaultColor(Color.GRAY);
level3.SetDefaultColor(Color.GRAY);
level4.SetDefaultColor(Color.GRAY);
level1.SetStyle(Curve.SHORT_DASH);
level2.SetStyle(Curve.SHORT_DASH);
level3.SetStyle(Curve.SHORT_DASH);
level4.SetStyle(Curve.SHORT_DASH);
#// Plot main plot, smoothed plot and signal line
plot RROF_Smooth = if rofLine then RROF_s else na;#, 'RROF Smooth'
#RROF_Smooth.SetLineWeight(2);
RROF_Smooth.SetDefaultColor(Color.WHITE);
plot SignalLine = if Signal_Line then Signal else na;#, "Signal Line"
SignalLine.SetLineWeight(3);
SignalLine.AssignValueColor( if up then GlobalColor("c_up") else GlobalColor("c_dn"));
#// Plot Bias / Sentiment
plot BiasSentiment = if DispBias then RROF_bs else na;#, "Bias / Sentiment"
BiasSentiment.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
BiasSentiment.AssignValueColor(if s_up then GlobalColor("green") else GlobalColor("red"));
AddLabel(BiasLabel, if RROF_bs>0 then "Bias: UP" else "Bias: DN", if RROF_bs>0 then Color.GREEN else Color.RED);
plot ZeroLine = if last then na else 0; # 'Zero Line'
ZeroLine.AssignValueColor(if s_up then GlobalColor("green") else GlobalColor("red"));
#// =============================================================================
#// Plot Price Strength & Relative Volume as stacked "equalizer bands"
def nPrice = Max(Min(Pricea_n, 100), -100);
def nVol = Max(Min(Vola_n, 100), -100);
def bar = bar_flow;
def c_vol = bar > 0;
def cb_vol = if bar > 0 then 1 else -1;
def vc_lo = if DispEVEREX then 0 else na;
def vc_hi = nVol * scale / 100 / 2;
def pc_lo = if DispEVEREX then vc_hi else na; def pc_hi = vc_hi + AbsValue(nPrice) * scale / 100 / 2;
AddChart(high = if c_vol then pc_hi else na , low = pc_lo , open = pc_hi, close = pc_lo,
type = ChartType.CANDLE, growcolor = GlobalColor("c_pri_grn"));
AddChart(high = if c_vol then pc_hi else na , low = pc_lo , open = pc_lo, close = pc_hi,
type = ChartType.CANDLE, growcolor = GlobalColor("b_pri_grn"));
AddChart(high = if !c_vol then pc_hi else na , low = pc_lo , open = pc_hi, close = pc_lo,
type = ChartType.CANDLE, growcolor = GlobalColor("c_pri_red"));
AddChart(high = if !c_vol then pc_hi else na , low = pc_lo , open = pc_lo, close = pc_hi,
type = ChartType.CANDLE, growcolor = GlobalColor("b_pri_red"));
AddChart(high = if c_vol then vc_hi else na , low = vc_lo , open = vc_hi, close = vc_lo,
type = ChartType.CANDLE, growcolor = GlobalColor("c_vol_grn"));
AddChart(high = if c_vol then vc_hi else na , low = vc_lo , open = vc_lo, close = vc_hi,
type = ChartType.CANDLE, growcolor = GlobalColor("b_vol_grn"));
AddChart(high = if !c_vol then vc_hi else na , low = vc_lo , open = vc_hi, close = vc_lo,
type = ChartType.CANDLE, growcolor = GlobalColor("c_vol_red"));
AddChart(high = if !c_vol then vc_hi else na , low = vc_lo , open = vc_lo, close = vc_hi,
type = ChartType.CANDLE, growcolor = GlobalColor("b_vol_red"));
#-- Background
AddCloud(if up then pos else neg, if up then neg else pos, GlobalColor("dgreen"), GlobalColor("dred"));
#-- Bar Color
def ExtUp = s_up and c_vol;
def ExtDn = !s_up and !c_vol;
AssignPriceColor( if !ColorBars then Color.CURRENT else
if ExtUp then Color.GREEN else
if s_up then Color.DARK_GREEN else
if ExtDn then Color.RED else
if !s_up then Color.DARK_RED else Color.GRAY);
#--- END CODE
Last edited by a moderator: