Author instructions:
The KDJ oscillator display consists of 3 lines (K, D and J - hence the name of the display) and 2 levels. K and D are the same lines you see when using the stochastic oscillator. The J line in turn represents the deviation of the D value from the K value. The convergence of these lines indicates new trading opportunities. Just like the Stochastic Oscillator, oversold and overbought levels correspond to the times when the trend is likely to reverse.
Function
L2 KDJ with Whale Pump and Oust is a composite indicator that combines both KDJ and Whale Pump and Oust detector. By virtue of this, fake signal of KDJ can be filtered out to some degree.
Key Signal
whalepump --> whale buy behavior will be detected and displayed in green histograms
oust --> after whale buy behavior, there usually a oust action from whale to drive out profitable orders to reduce the selling pressure of subsequent pull ups. This oust will be detected and displayed in red histograms
k --> k value of a stochastic oscillator
d --> d value of a stochastic oscillator
j --> the deviation of the d value from the d value of a stochastic oscillator
Pros and Cons
Pros:
1. filter out KDJ fake signal by introducing whale pump/oust detector
2. J value can be used to detect overbought and oversold regions
Cons:
1. It works better in small time frame and sideways. Extreme long or short conditions may cause KDJ staturate.
2. It can only indicate in current time frame, larger time frame trend info is missing.
Remarks
An improved version of L2 KDJ with Whale Pump Detector by adding oust function. Works fine in 15mins time frame.
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at #https://mozilla.org/MPL/2.0/
#// © blackcat1402
#https://www.tradingview.com/script/bhdaBHlg-blackcat-L2-KDJ-with-Whale-Pump-and-Oust/
#study("[blackcat] L2 KDJ with Whale Pump and Oust"
# Converted by Sam4Cok@Samer800 - 08/2022
#//inputs
input ShowBubble = yes;
input ShowHistogram = yes;
input BuyAlertLimit = 0; # "BuyAlertLimit"
input SellAlertLimit = 100; # "SellAlertLimit"
input Period = 18;
input SignalK = 4;
input SignalD = 4;
#//functions
declare lower;
def na = Double.NaN;
script nz {
input data = 1;
input repl = 0;
def ret_val = if IsNaN(data) then repl else data;
plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
input values = close;
input length = 0;
def r_val;
r_val = if length >= 1 then
fold i = 0 to length
with p do
if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
plot return = r_val;
}
#xsa(src,len,wei) =>
script xsa {
input src = close;
input len = 0;
input wei = 0;
def sumf;
def ma;
def out;
sumf = nz(sumf[1]) - nz(src[len]) + src;
ma = if IsNaN(src[len]) then Double.NaN else sumf / len;
out = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
plot return = out;
}
#alma(series, length, offset, sigma, floor)
script ALMA {
input series = close;
input windowsize = 9;
input Offset = 0.85;
input Sigma = 6;
def m = Offset * (windowsize - 1);
def s = windowsize/Sigma;
def Sum = fold i = 0 to windowsize with WS do
WS + Exp(-1 * (sqr(i-m))/(2*sqr(s))) * getValue(series, windowsize - i - 1);
def norm = fold j = 0 to windowsize with CW do
CW + Exp(-1 * (sqr(j-m))/(2*sqr(s)));
plot ALMA = sum / norm;
}
#//algorithm for whale pump an oust-----
def var1 = xrf(ohlc4,1)[1];
def var2 = xsa(AbsValue(low - var1), 13, 1) / xsa(Max(low - var1, 0), 10, 1);
def var3 = ExpAverage(var2, 10);
def var4 = Lowest(low, 33);
def var5 = ExpAverage(If(low <= var4, var3, 0), 3);
#//define KDJ
def rsv = (close-lowest(low,Period))/(highest(high,Period)-lowest(low,Period))*100;
def k = alma(xsa(rsv,SignalK,1),3,0.85,6);
def d = alma(xsa(k,SignalD,1),3,0.85,6);
def j = alma(3*k-2*d,3, 0.85,6);
########
#// plot signal
plot kLine = k;
kLine.SetDefaultColor(Color.WHITE);
plot dLine = d;
dLine.SetDefaultColor(Color.ORANGE);
plot jLine = j;
jLine.AssignValueColor( CreateColor(17, 118, 242));
jLine.SetLineWeight(2);
#//plot whale buy histograms
def bgcolor = if j crosses above BuyAlertLimit then 1 else
if j crosses below SellAlertLimit then -1 else 0;
AddChart(high = if bgcolor > 0 then Double.NEGATIVE_INFINITY else na,
low = if bgcolor > 0 then Double.POSITIVE_INFINITY else na,
open = if bgcolor > 0 then Double.POSITIVE_INFINITY else na,
close = if bgcolor > 0 then Double.NEGATIVE_INFINITY else 0,
type = ChartType.CANDLE, growcolor = Color.DARK_GREEN);
AddChart(high = if bgcolor < 0 then Double.NEGATIVE_INFINITY else na,
low = if bgcolor < 0 then Double.POSITIVE_INFINITY else na,
open = if bgcolor < 0 then Double.POSITIVE_INFINITY else na,
close = if bgcolor < 0 then Double.NEGATIVE_INFINITY else na,
type = ChartType.CANDLE, growcolor = Color.DARK_RED);
#//whale pump candles
plot OustHist = var5;
OustHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
OustHist.SetHiding(!ShowHistogram);
OustHist.AssignValueColor(if var5 > var5[1] then CreateColor(38,166,154) else
if var5 < var5[1] then Color.PINK else Color.GRAY);
#//Add Bubble
AddChartBubble(ShowBubble and j crosses above BuyAlertLimit, j, "B", Color.GREEN, no);
AddChartBubble(ShowBubble and j crosses below SellAlertLimit, j, "S", Color.RED, yes);
#//define bottom zone threshold values
def h1 = 90;
def h2 = 10;
def h3 = 0;
def h4 = 100;
AddCloud(h2, h3, Color.DARK_GREEN, Color.DARK_GREEN, yes);
AddCloud(h1, h4, CreateColor(255, 102, 255), CreateColor(255, 102, 255), yes);
### END
Last edited by a moderator: