input src = hl2;
input length = 24;
input showcross = yes;
input gain = 10000;
input k = yes;
script hma {
input _src = 0;
input _length = 0;
def avgType = AverageType.WEIGHTED;
plot return = MovingAverage(avgType, (2 * MovingAverage(avgType, _src, _length /
2)) - MovingAverage(avgType, _src, _length), Round(Sqrt(_length)));
}
script hma3 {
input _length = 0;
def p = _length / 2;
def avgType = AverageType.WEIGHTED;
plot return = MovingAverage(avgType, 3 * MovingAverage(avgType, close, p / 3) -
MovingAverage(avgType, close, p / 2) - MovingAverage(avgType,
close, p), p);
}
script kahlman {
input x = 0;
input g = 0;
def...
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
# ########################################################
# Kalman SMA200 cross
# by @tradebook 7/2021
input n = 21;
input showLabel = yes ;
DefineGlobalColor("LitePink", CreateColor (225, 220, 180)) ;
plot Kalman = WMA(((WMA(close, 3) * 3) + (WMA(close[1], 2) * 2) + close[2] + Average(close, n)) / 7, n);
plot avg200 = MovingAverage(AverageType.SIMPLE, close, 200);
AddCloud(Kalman, avg200, Color.green, GlobalColor("LitePink"));
plot UpArrow = if Kalman crosses above avg200 then low else double.NaN ;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_up);
UpArrow.SetDefaultColor(color.blue) ;
plot DownArrow = if Kalman crosses below avg200 then high else double.NaN ;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_down);
DownArrow.SetDefaultColor(color.magenta) ;
AddLabel(showLabel,
if Kalman crosses above avg200 then "Buy" else
if Kalman crosses below avg200 then "Sell" else "Kalman: " +round(Kalman,1),
if Kalman crosses above avg200 then color.green else
if Kalman crosses below avg200 then color.red else color.gray);
Alert(Kalman crosses above avg200, "Buy" , Alert.Bar, Sound.Bell);
Alert(Kalman crosses below avg200, "Sell" , Alert.Bar, Sound.Bell);
//@version=4
study("Hull Trend with Kahlman", shorttitle="HMA-Kahlman Trend", overlay=true)
src = input(hl2, "Price Data")
length = input(24, "Lookback")
showcross = input(true, "Show cross over/under")
gain = input(10000, "Gain")
k = input(true, "Use Kahlman")
hma(_src, _length) =>
wma((2 * wma(_src, _length / 2)) - wma(_src, _length), round(sqrt(_length)))
hma3(_src, _length) =>
p = length/2
wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)
kahlman(x, g) =>
kf = 0.0
dk = x - nz(kf[1], x)
smooth = nz(kf[1],x)+dk*sqrt((g/10000)*2)
velo = 0.0
velo := nz(velo[1],0) + ((g/10000)*dk)
kf := smooth+velo
a = k ? kahlman(hma(src, length), gain) : hma(src, length)
b = k ? kahlman(hma3(src, length), gain) : hma3(src, length)
c = b > a ? color.lime : color.red
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]
p1 = plot(a,color=c,linewidth=1,transp=75)
p2 = plot(b,color=c,linewidth=1,transp=75)
fill(p1,p2,color=c,transp=55)
plotshape(showcross and crossdn ? a : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="S", textcolor=color.white, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.absolute, style=shape.labelup, color=color.green, size=size.tiny, text="B", textcolor=color.white, transp=0, offset=-1)
input src = hl2;
input length = 24;
input showcross = yes;
input gain = 10000;
input k = yes;
script hma {
input _src = 0;
input _length = 0;
def avgType = AverageType.WEIGHTED;
plot return = MovingAverage(avgType, (2 * MovingAverage(avgType, _src, _length /
2)) - MovingAverage(avgType, _src, _length), Round(Sqrt(_length)));
}
script hma3 {
input _length = 0;
def p = _length / 2;
def avgType = AverageType.WEIGHTED;
plot return = MovingAverage(avgType, 3 * MovingAverage(avgType, close, p / 3) -
MovingAverage(avgType, close, p / 2) - MovingAverage(avgType,
close, p), p);
}
script kahlman {
input x = 0;
input g = 0;
def kf;
def dk = x - if IsNaN(kf[1]) then x else kf[1];
def smooth = if IsNan(kf[1]) then x else kf[1] + dk * Sqrt((g / 10000) * 2);
def velo = if IsNaN(velo[1]) then 0 else velo[1] + ((g / 10000) * dk);
kf = smooth + velo;
plot return = kf;
}
plot a = if k then kahlman(hma(src, length), gain) else hma(src, length);
plot b = if k then kahlman(hma3(length), gain) else hma3(length);
AddCloud(b, a, color.GREEN, color.RED);
AddChartBubble(b crosses above a, low, "B", color.GREEN, No);
AddChartBubble(b crosses below a, high, "S", color.RED);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | Currenttime / Now in a scan filter. | Questions | 1 | |
Divergence Filter for Moving Average Crossing | Questions | 3 | ||
S | Filter Out Low Volume Option Stocks | Questions | 1 | |
T | Scanning For Filter Between 30 and 300 bars ago | Questions | 1 | |
Question regarding Bandpass Filter Harmonic | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.