Hi all... I've made a number of adjustments to the latest version posted here. Specifically:
- Make the histogram easier to visualise the positive and negative market strength
- Plotting the net difference between Bulls and Bears to and incorporated a relative strenght to indicate if the market strength is sizeable or trading sideways.
- Added in coloring based on the increases or decreases in strength
- Added in an ADX option in addition to the RSI and Stoch.
- Added Sensitivity adjustment feature.
The image below includes both this new version, and the previous one for reference. Please let me know what you think.
Code below:
#TITLE
#Absolute Strength Histogram for TOS
#PRC_Absolute Strength | indicator
#DESCRIPTION
#The Absolute Strength indicator indicates the current market “strength”
#in two different ways possible RSI Method and Stochastic Method
#and by separating the bulls and bears into 2 curves.
#
#The results are then averaged with the same “length” as the one used for
#these 2 above methods and smoothed a second time using the “Smooth” variable.
#The moving average mode used is by default the Weighted one.
#CREDITS
#
https://www.prorealcode.com/prorealtime-indicators/absolute-strength/
#
https://www.prorealcode.com/user/nicolas/
#CHANGELOG
#2019.11.01
@diazlaz Initial Port
#2023.1031
@jonesjb adjusted the port to:
#1. Make the histogram easier to visualise the positive and
#negative market strengths
#2. Plotting the net difference between Bulls and Bears to
#and incorporated a relative strenght to indicate if the
#market strength is sizeable or trading sideways.
#3. Added in coloring based on the increases or decreases
#in strength
#4. Added in an ADX option in addition to the RSI and Stoch.
#5. Added Sensitivity adjustment feature.
declare lower;
DefineGlobalColor("PUp", CreateColor(143, 239, 191));
DefineGlobalColor("PDown", CreateColor(26, 158, 94));
DefineGlobalColor("PNeutral", CreateColor(54, 69, 63));
DefineGlobalColor("NUp", CreateColor(163, 24, 24));
DefineGlobalColor("NDown", CreateColor(255, 92, 92));
DefineGlobalColor("NNeutral", CreateColor(69, 58, 68));
#INPUT INDICATOR
input mode = {default RSI, Stoch, ADX}; #0-RSI method 1-Stoch method
input length = 9; #length
input smooth = 3; #period of smoothing factor
input modema = {default wma, exp, sma};
input price = close; # price data
input Sensitivity = {"low", default "medium", "high", "Let's Get Nuts"}; #medium is the standard
def Sen;
switch (Sensitivity) {
case "low":
Sen = 1.5;
case "medium":
Sen = 1;
case "high":
Sen = .5;
case "Let's Get Nuts":
Sen = 0;
}
#LOGIC
def price1 = price;
def price2 = price[1];
def Bulls;
def Bears;
switch (mode) {
case RSI:
Bulls = 0.5 * (AbsValue(price1 - price2) + (price1 - price2));
Bears = 0.5 * (AbsValue(price1 - price2) - (price1 - price2));
case Stoch:
Bulls = price1 - Lowest(low, length);
Bears = Highest(high, length) - price1;
case ADX:
Bulls = 0.5 * (AbsValue(high - high[1]) + (high - high[1]));
Bears = 0.5 * (AbsValue(low[1] - low) + (low[1] - low));
}
def AvgBulls;
def AvgBears;
def SmthBulls;
def SmthBears;
switch (modema) {
case wma:
AvgBulls = WMA(Bulls, length);
AvgBears = WMA(Bears, length);
SmthBulls = WMA(AvgBulls, smooth);
SmthBears = WMA(AvgBears, smooth);
case exp:
AvgBulls = ExpAverage(Bulls, length);
AvgBears = ExpAverage(Bears, length);
;
SmthBulls = ExpAverage(AvgBulls, smooth);
SmthBears = ExpAverage(AvgBears, smooth);
case sma:
AvgBulls = Average(Bulls, length);
AvgBears = Average(Bears, length);
;
SmthBulls = Average(AvgBulls, smooth);
SmthBears = Average(AvgBears, smooth);
}
#PLOTS
plot pSmthBulls = if SmthBulls >= SmthBears then SmthBulls - SmthBears else Double.NaN;
pSmthBulls.AssignValueColor (if
(SmthBulls - SmthBears) >= (SmthBears * Sen) and (SmthBulls - SmthBears) > (SmthBulls[1] - SmthBears[1]) then (GlobalColor("Pup")) else if
(SmthBulls - SmthBears) >= (SmthBears * Sen) and (SmthBulls - SmthBears) <= (SmthBulls[1] - SmthBears[1]) then (GlobalColor("Pdown"))
else (GlobalColor("PNeutral")));
pSmthBulls.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pSmthBulls.HideBubble();
pSmthBulls.HideTitle();
plot pSmthBears = if SmthBears > SmthBulls then SmthBulls - SmthBears else Double.NaN;
pSmthBears.AssignValueColor (if
(SmthBears - SmthBulls) > (SmthBulls * Sen) and (SmthBears - SmthBulls) > (SmthBears[1] - SmthBulls[1]) then (GlobalColor("NDown")) else if
(SmthBears - SmthBulls) > (SmthBulls * Sen) and (SmthBears - SmthBulls) <= (SmthBears[1] - SmthBulls[1]) then (GlobalColor("NUp"))
else (GlobalColor("NNeutral")));
pSmthBears.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pSmthBears.HideBubble();
pSmthBears.HideTitle();
def pSmthBullsL = SmthBulls;
#pSmthBullsL.AssignValueColor(Color.GREEN);
#pSmthBullsL.SetLineWeight(2);
def pSmthBearsL = SmthBears;
#pSmthBearsL.AssignValueColor(Color.RED);
#pSmthBearsL.SetLineWeight(2);
#COLORCANDLES
input showColorBars = no;
AssignPriceColor(
if !showColorBars then
Color.CURRENT
else if
SmthBulls > SmthBears and ((SmthBulls - SmthBears) > (SmthBears * Sen)) and (SmthBulls - SmthBears) > (SmthBulls[1] - SmthBears[1]) then (GlobalColor("Pup"))
else if
SmthBulls > SmthBears and ((SmthBulls - SmthBears) > (SmthBears * Sen)) and (SmthBulls - SmthBears) <= (SmthBulls[1] - SmthBears[1]) then (GlobalColor("Pdown"))
else if
SmthBulls > SmthBears then (GlobalColor("PNeutral")) else if
SmthBears > SmthBulls and ((SmthBears - SmthBulls) > (SmthBulls * Sen)) and (SmthBears - SmthBulls) > (SmthBears[1] - SmthBulls[1]) then (GlobalColor("NDown"))
else if
SmthBears > SmthBulls and ((SmthBears - SmthBulls) > (SmthBulls * Sen)) and (SmthBears - SmthBulls) <= (SmthBears[1] - SmthBulls[1]) then (GlobalColor("NUp"))
else if
SmthBears > SmthBulls then (GlobalColor("NNeutral"))
else
Color.YELLOW
);