How to center a histogram on the zero-line of an oscillator?

ben

New member
If you combine two studies in the lower section, they never mend well.
I am trying to combine the two studies below so that the centerline of the Stochastic Full Diff histogram is the same as the centerline of the Spearman oscillator.
I included my default settings that I use for NQ 2-min chart.
I will include the Spearman back-tester for your viewing pleasure if you so desire to test it. I never back tested the StochFullDiff though.

Code:
#Another Ben
#Stochastic Full Differential Histogram with Custom painted bars.

declare lower;

input priceH = high;
input priceL = low;
input priceC = close;
input kPeriod = 10;
input kSlowingPeriod = 3;
input dPeriod = 10;
input averageType = AverageType.SIMPLE;
input paintBars = yes;

plot StochasticHistogram = reference StochasticFull(0, 0, kPeriod, dPeriod, priceH, priceL, priceC, kSlowingPeriod, averageType).FullK - reference StochasticFull(0, 0, kPeriod, dPeriod, priceH, priceL, priceC, kSlowingPeriod, averageType).FullD;
plot ZeroLine = 0;

StochasticHistogram.SetDefaultColor(GetColor(5));
StochasticHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochasticHistogram.SetLineWeight(3);
StochasticHistogram.DefineColor("Up", Color.UPTICK);
StochasticHistogram.DefineColor("Down", Color.DOWNTICK);
StochasticHistogram.AssignValueColor(if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.color("Up") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.color("Down") else GetColor(1));
ZeroLine.SetDefaultColor(GetColor(8));

StochasticHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochasticHistogram.SetLineWeight(3);
StochasticHistogram.DefineColor("Positive and Up", Color.GREEN);
StochasticHistogram.DefineColor("Positive and Down", GetColor(4));
StochasticHistogram.DefineColor("Negative and Down", Color.RED);
StochasticHistogram.DefineColor("Negative and Up", GetColor(4));
StochasticHistogram.AssignValueColor(if StochasticHistogram >= 0 then if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.Color("Positive and Up") else StochasticHistogram.Color("Positive and Down") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.Color("Negative and Down") else StochasticHistogram.Color("Negative and Up"));

DefineGlobalColor("Positive and UP“, Color.GREEN);
DefineGlobalColor("Positive and Down", GetColor(4));
DefineGlobalColor("Negative and Down", Color.RED);
DefineGlobalColor("Negative and Up", GetColor(4));
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if StochasticHistogram >= 0 then if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.Color("Positive and Up") else StochasticHistogram.Color("Positive and Down") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.Color("Negative and Down") else StochasticHistogram.Color("Negative and Up"));

Code:
#Another Ben
#StochFullDiff with cloud default backtested for 2min NQ
declare lower;

input price = close;
input length = 13;
input averageLength = 4;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = Average(Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

AddCloud(Spearman, SpearmanAverage, Color.GREEN, Color.RED);

Spearman.SetDefaultColor(GetColor(1));
SpearmanAverage.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(8));
OverSold.SetDefaultColor(GetColor(6));

Code:
#Another Ben
#Spearman Backtester default settings for 2min NQ
input price = close;
input length = 13;
input averageLength = 4;
input AverageType = AverageType.EXPONENTIAL;
input over_bought = 80;
input over_sold = -80;

Assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = Average(Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

AddCloud(Spearman, SpearmanAverage, Color.GREEN, Color.RED);

Spearman.SetDefaultColor(GetColor(1));
SpearmanAverage.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(8));
OverSold.SetDefaultColor(GetColor(6));

AddOrder(OrderType.BUY_AUTO, Spearman crosses above SpearmanAverage, close, 1, Color.YELLOW, Color.YELLOW, "BUY");

AddOrder(OrderType.SELL_AUTO, Spearman crosses below SpearmanAverage, close, 1, Color.RED, Color.RED, "SELL");
 

ben

New member
I previously tried to combine indicators in order to correct this issue without luck; however, I combined these two and it seems to work. Here is the code for the combo and if desired, back-tester for Spearman is in post above:
Code:
#Another Ben
#Spearman w/ Cloud and StochFullDiff painted bars combo.
#Spearman (Close, 13,4, EXPONENTIAL) backtested for NQ 2min (5-23-22 thru 6-17-22)

declare lower;

#Spearman with cloud
input price = close;
input length = 13;
input averageLength = 4;
input averageType = AverageType.EXPONENTIAL;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = MovingAverage(AverageType, Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

AddCloud(Spearman, SpearmanAverage, Color.GREEN, Color.RED);

Spearman.SetDefaultColor(GetColor(1));
SpearmanAverage.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(8));
OverSold.SetDefaultColor(GetColor(6));

#Stochastic Full Differential Histogram with Custom painted bars.

input priceH = high;
input priceL = low;
input priceC = close;
input kPeriod = 10;
input kSlowingPeriod = 3;
input dPeriod = 10;
input averageType2 = AverageType.SIMPLE;
input paintBars = yes;

plot StochasticHistogram = reference StochasticFull(0, 0, kPeriod, dPeriod, priceH, priceL, priceC, kSlowingPeriod, averageType2).FullK - reference StochasticFull(0, 0, kPeriod, dPeriod, priceH, priceL, priceC, kSlowingPeriod, averageType2).FullD;


StochasticHistogram.SetDefaultColor(GetColor(5));
StochasticHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochasticHistogram.SetLineWeight(3);
StochasticHistogram.DefineColor("Up", Color.UPTICK);
StochasticHistogram.DefineColor("Down", Color.DOWNTICK);
StochasticHistogram.AssignValueColor(if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.color("Up") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.color("Down") else GetColor(1));
ZeroLine.SetDefaultColor(GetColor(8));

StochasticHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochasticHistogram.SetLineWeight(3);
StochasticHistogram.DefineColor("Positive and Up", Color.GREEN);
StochasticHistogram.DefineColor("Positive and Down", GetColor(4));
StochasticHistogram.DefineColor("Negative and Down", Color.RED);
StochasticHistogram.DefineColor("Negative and Up", GetColor(4));
StochasticHistogram.AssignValueColor(if StochasticHistogram >= 0 then if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.Color("Positive and Up") else StochasticHistogram.Color("Positive and Down") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.Color("Negative and Down") else StochasticHistogram.Color("Negative and Up"));

DefineGlobalColor("Positive and UP“, Color.GREEN);
DefineGlobalColor("Positive and Down", GetColor(4));
DefineGlobalColor("Negative and Down", Color.RED);
DefineGlobalColor("Negative and Up", GetColor(4));
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if StochasticHistogram >= 0 then if StochasticHistogram > StochasticHistogram[1] then StochasticHistogram.Color("Positive and Up") else StochasticHistogram.Color("Positive and Down") else if StochasticHistogram < StochasticHistogram[1] then StochasticHistogram.Color("Negative and Down") else StochasticHistogram.Color("Negative and Up"));
#END
 

ben

New member
Found the one I was struggling with, combing the RMI and the Awesome Oscillator. Seems to be an issue that would have to be resolved by equalizing the formulas to be centered on zero. Not sure how to do that one.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
  • 100 %
Reactions: ben
Solution

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top