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.
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");