Half Trend With SSL Hybrid
Half Trend With SSL Hybrid
Half Trend With SSL Hybrid
//By Mihkel00
// This script is designed for the NNFX Method, so it is recommended for Daily
charts only.
// Tried to implement a few VP NNFX Rules
// This script has a SSL / Baseline (you can choose between the SSL or MA), a
secondary SSL for continiuation trades and a third SSL for exit trades.
// Alerts added for Baseline entries, SSL2 continuations, Exits.
// Baseline has a Keltner Channel setting for "in zone" Gray Candles
// Added "Candle Size > 1 ATR" Diamonds from my old script with the criteria of
being within Baseline ATR range.
// Credits
// Strategy causecelebre https://www.tradingview.com/u/causecelebre/
// SSL Channel ErwinBeckers https://www.tradingview.com/u/ErwinBeckers/
// Moving Averages jiehonglim https://www.tradingview.com/u/jiehonglim/
// Moving Averages everget https://www.tradingview.com/u/everget/
// "Many Moving Averages" script Fractured
https://www.tradingview.com/u/Fractured/
///////////////////////////////////////////////////////////////////////////////////
/////////////////////
////ma
srcma1 = input(close, title="SourceMA" ,group="Simple Movinge Average")
lenma1 = input(9, minval=1, title="LengthSMA1" ,group="Simple Movinge Average")
//offsetma1 = input(title="Offset1", defval=0, minval=-500,
maxval=500 ,group="Simple Movinge Average")
outma1 = sma(srcma1, lenma1)
plot(outma1, color=color.yellow, title="SMA1", offset=0)
// ma2
lenma2 = input(55, minval=1, title="LengthSMA2" ,group="Simple Movinge Average")
outma2 = sma(srcma1, lenma2)
plot(outma2, color=color.red, title="SMA2", offset=0, display=display.none)
// ma3
lenma3 = input(200, minval=1, title="LengthSMA3" ,group="Simple Movinge Average")
outma3 = sma(srcma1, lenma3)
plot(outma3, color=color.white, title="SMA3", offset=0, display=display.none)
smoothingLine1(srcma11,smoothingLength1) =>
if typeMA == "EMA"
ema(srcma11,smoothingLength1)
else
if typeMA == "SMMA (RMA)"
rma(srcma11,smoothingLength1)
else
if typeMA == "WMA"
wma(srcma11,smoothingLength1)
else
if typeMA == "VWMA"
vwma(srcma11,smoothingLength1)
else
if typeMA == "SMA"
sma(srcma11,smoothingLength1)
smoothingLine = smoothingLine1(srcma1,smoothingLength)
plot(smoothingLine, title="Smoothing Line", color=#f37f20, offset=0)
mylongSma = crossover(smoothingLine,outma1 )
myshortSma = crossunder(smoothingLine,outma1 )
alertcondition(mylongSma,"Long / Buy")
alertcondition(myshortSma,"Short / Sell")
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
// HalfTrend1
channelDeviation1 = input(title="HalfTrend Channel Deviation", defval=2 ,group="3
HalfTrend Signal")
amplitude1 = input(title="HalfTrend1 Amplitude", defval=1 ,group="3 HalfTrend
Signal")
atr2 = atr(100) / 2
dev1 = channelDeviation1 * atr2
highPrice1 = high[abs(highestbars(amplitude1))]
lowPrice1 = low[abs(lowestbars(amplitude1))]
highma1 = sma(high, amplitude1)
lowma1 = sma(low, amplitude1)
if nextTrend1 == 1
maxLowPrice1 := max(lowPrice1, maxLowPrice1)
if trend1 == 0
if not na(trend1[1]) and trend1[1] != 0
up1 := na(down1[1]) ? down1 : down1[1]
arrowUp1 := up1 - atr2
else
up1 := na(up1[1]) ? maxLowPrice1 : max(maxLowPrice1, up1[1])
atrHigh1 := up1 + dev1
atrLow1 := up1 - dev1
else
if not na(trend1[1]) and trend1[1] != 1
down1 := na(up1[1]) ? up1 : up1[1]
arrowDown1 := down1 + atr2
else
down1 := na(down1[1]) ? minHighPrice1 : min(minHighPrice1, down1[1])
atrHigh1 := down1 + dev1
atrLow1 := down1 - dev1
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
// HalfTrend2
//study("HalfTrend", overlay=true)
atr22 = atr(100) / 2
dev2 = channelDeviation1 * atr22
highPrice2 = high[abs(highestbars(amplitude2))]
lowPrice2 = low[abs(lowestbars(amplitude2))]
highma2 = sma(high, amplitude2)
lowma2 = sma(low, amplitude2)
if nextTrend2 == 1
maxLowPrice2 := max(lowPrice2, maxLowPrice2)
if trend2 == 0
if not na(trend2[1]) and trend2[1] != 0
up2 := na(down2[1]) ? down2 : down2[1]
arrowUp2 := up2 - atr22
else
up2 := na(up2[1]) ? maxLowPrice2 : max(maxLowPrice2, up2[1])
atrHigh2 := up2 + dev2
atrLow2 := up2 - dev2
else
if not na(trend2[1]) and trend2[1] != 1
down2 := na(up2[1]) ? up2 : up2[1]
arrowDown2 := down2 + atr22
else
down2 := na(down2[1]) ? minHighPrice2 : min(minHighPrice2, down2[1])
atrHigh2 := down2 + dev2
atrLow2 := down2 - dev2
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
// HalfTrend3
//study("HalfTrend", overlay=true)
atr23 = atr(100) / 2
dev3 = channelDeviation1 * atr23
highPrice3 = high[abs(highestbars(amplitude3))]
lowPrice3 = low[abs(lowestbars(amplitude3))]
highma3 = sma(high, amplitude3)
lowma3 = sma(low, amplitude3)
if nextTrend3 == 1
maxLowPrice3 := max(lowPrice3, maxLowPrice3)
if trend3 == 0
if not na(trend3[1]) and trend3[1] != 0
up3 := na(down3[1]) ? down3 : down3[1]
arrowUp3 := up3 - atr23
else
up3 := na(up3[1]) ? maxLowPrice3 : max(maxLowPrice3, up3[1])
atrHigh3 := up3 + dev3
atrLow3 := up3 - dev3
else
if not na(trend3[1]) and trend3[1] != 1
down3 := na(up3[1]) ? up3 : up3[1]
arrowDown3 := down3 + atr23
else
down3 := na(down3[1]) ? minHighPrice3 : min(minHighPrice3, down3[1])
atrHigh3 := down3 + dev3
atrLow3 := down3 - dev3
///////////////////////////////////////////////////////////////////////////////////
///
//indicator(title="Ichimoku Cloud", shorttitle="Ichimoku", overlay=true)
conversionPeriods = input(9, minval=1, title="Conversion Line Length",
group="ichimoku and SSL Hybrid Signal")
basePeriods = input(26, minval=1, title="Base Line Length", group="ichimoku and SSL
Hybrid Signal")
ShowCrossIchi = input(title = "Show Cross ichimocu" ,defval=false, group="ichimoku
and SSL Hybrid Signal")
LongCrossIchi = crossover(conversionLine,baseLine )
ShortCrossIchi = crossunder(conversionLine,baseLine )
CrossLabelichiLow = low - (atr(30) * 0.8)
CrossLabelichiHigh = high + (atr(30) * 0.8)
alertcondition(LongCrossIchi,"Long / Buy")
alertcondition(ShortCrossIchi,"Short / Sell")
///////////////////////////////////////////////////////////////////////////////////
///
//
tema(src, len) =>
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
(3 * ema1) - (3 * ema2) + ema3
kidiv = int(1)
jurik_phase = int(3)
jurik_power = int(1)
volatility_lookback = int(10)
//MF
beta = int(0.8)
feedback = bool(false)
z = int(0.5)
//EDSMA
ssfLength = int(20)
ssfPoles = int(2)
//----
//EDSMA
get2PoleSSF(src, length) =>
PI = 2 * asin(1)
arg = sqrt(2) * PI / length
a1 = exp(-arg)
b1 = 2 * a1 * cos(arg)
c2 = b1
c3 = -pow(a1, 2)
c1 = 1 - c2 - c3
ssf = 0.0
ssf := c1 * src + c2 * nz(ssf[1]) + c3 * nz(ssf[2])
arg = PI / length
a1 = exp(-arg)
b1 = 2 * a1 * cos(1.738 * arg)
c1 = pow(a1, 2)
coef2 = b1 + c1
coef3 = -(c1 + b1 * c1)
coef4 = pow(c1, 2)
coef1 = 1 - coef2 - coef3 - coef4
ssf = 0.0
ssf := coef1 * src + coef2 * nz(ssf[1]) + coef3 * nz(ssf[2]) + coef4 *
nz(ssf[3])
edsma = 0.0
edsma := alpha * src + (1 - alpha) * nz(edsma[1])
result := edsma
result
///EXIT
ExitHigh = ma(SSL3Type, high, len3)
ExitLow = ma(SSL3Type, low, len3)
///////////////////////////////////////////////////////////////////////////////////
/////////////////////
//SSL1 VALUES
Hlv = int(na)
Hlv := close > emaHigh ? 1 : close < emaLow ? -1 : Hlv[1]
sslDown = Hlv < 0 ? emaHigh : emaLow
//SSL2 VALUES
Hlv2 = int(na)
Hlv2 := close > maHigh ? 1 : close < maLow ? -1 : Hlv2[1]
sslDown2 = Hlv2 < 0 ? maHigh : maLow
//EXIT VALUES
Hlv3 = int(na)
Hlv3 := close > ExitHigh ? 1 : close < ExitLow ? -1 : Hlv3[1]
sslExit = Hlv3 < 0 ? ExitHigh : ExitLow
base_cross_Long = crossover(close, sslExit)
base_cross_Short = crossover(sslExit, close)
codiff = base_cross_Long ? 1 : base_cross_Short ? -1 : na
//COLORS
show_color_bar = input(title="Color Bars", type=input.bool, defval=true,
group="ichimoku and SSL Hybrid Signal")
color_bar = close > upperk ? #00c3ff : close < lowerk ? #ff0062 : color.gray
color_ssl1 = close > sslDown ? #00c3ff : close < sslDown ? #ff0062 : na
//PLOTS
plotarrow(codiff, colorup=#00c3ff, colordown=#ff0062,title="Exit Arrows",
transp=20, maxheight=20)
//p1 = plot(show_Baseline ? BBMC : na, color=color_bar, linewidth=4,transp=0,
title='MA Baseline')
//DownPlot = plot( show_SSL1 ? sslDown : na, title="SSL1", linewidth=3,
color=color_ssl1, transp=10)
barcolor(show_color_bar ? color_bar : na)
//up_channel = plot(show_Baseline ? upperk : na, color=color_bar, title="Baseline
Upper Channel")
//low_channel = plot(show_Baseline ? lowerk : na, color=color_bar, title="Basiline
Lower Channel")
//fill(up_channel, low_channel, color=color_bar, transp=90)
//ALERTS
//alertcondition(crossover(close, sslDown), title='SSL Cross Alert', message='SSL1
has crossed.')
//alertcondition(crossover(close, sslDown2), title='SSL2 Cross Alert',
message='SSL2 has crossed.')
//alertcondition(sell_atr, title='Sell Continuation', message='Sell Continuation.')
//alertcondition(buy_atr, title='Buy Continuation', message='Buy Continuation.')
//alertcondition(crossover(close, sslExit), title='Exit Sell', message='Exit Sell
Alert.')
//alertcondition(crossover(sslExit, close), title='Exit Buy', message='Exit Buy
Alert.')
//alertcondition(crossover(close, upperk ), title='Baseline Buy Entry',
message='Base Buy Alert.')
//alertcondition(crossover(lowerk, close ), title='Baseline Sell Entry',
message='Base Sell Alert.')
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
// candleasic
C_DownTrend = true
C_UpTrend = true
if trendRule == trendRule1
priceAvg = sma(close, 55)
C_DownTrend := close < priceAvg
C_UpTrend := close > priceAvg
if trendRule == trendRule2
sma200 = sma(close, 200)
sma50 = sma(close, 55)
C_DownTrend := close < sma50 and sma50 < sma200
C_UpTrend := close > sma50 and sma50 > sma200
C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick
body
C_OnNeckBearishNumberOfCandles = 2
C_OnNeckBearish = false
if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open <
close[1] and C_SmallBody and C_Range!=0 and abs(close-low[1])<=C_BodyAvg*0.05
C_OnNeckBearish := true
alertcondition(C_OnNeckBearish, title = "On Neck – Bearish", message = "New On Neck
– Bearish pattern detected")
if C_OnNeckBearish and OnNeckInput and (("Bearish" == CandleType) or CandleType
== "Both")
C_TweezerBottomBullishNumberOfCandles = 2
C_TweezerBottomBullish = false
if C_DownTrend[1] and not C_IsDojiBody and (C_Body * 0.2 > C_DnShadow) and
(C_Body[1] * 0.2 > C_DnShadow[1]) and (((C_Body <= C_Body[1] * 1.1) and (C_Body >
C_Body[1] * 0.9)) or ((C_Body[1] <= C_Body * 1.1) and (C_Body[1] > C_Body * 0.9)))
and (close[1] < close) and open[1] > open // and (close[1]>= open*0.95) and
(close[1]<open*1.05) // or ( (close[1]<close) and (close[1]<=open*1.05) and
(close[1]>open*0.95) ))
C_TweezerBottomBullish := true
alertcondition(C_TweezerBottomBullish, title = "Tweezer Bottom – Bullish", message
= "New Tweezer Bottom – Bullish pattern detected")
if C_TweezerBottomBullish and TweezerBottomInput and (("Bullish" == CandleType)
or CandleType == "Both")
//C_ThreeWhiteSoldiersBullishNumberOfCandles = 3
//C_3WSld_ShadowPercent = 0.6
//C_3WSld_HaveNotUpShadow = C_Body * C_3WSld_ShadowPercent > C_UpShadow
//C_3WSld_HaveNotUpShadow = C_Range / 3 > C_UpShadow
//C_ThreeWhiteSoldiersBullish = true
//if C_Body and C_Body[1] and C_Body[2]
// if C_WhiteBody and C_WhiteBody[1] and C_WhiteBody[2]
// C_ThreeWhiteSoldiersBullish := C_3WSld_HaveNotUpShadow and
C_3WSld_HaveNotUpShadow[1] and C_3WSld_HaveNotUpShadow[2]
C_NoshadowUp = (C_Body * 0.9) > C_UpShadow
C_NoshadowDn = (C_Body * 0.9) > C_DnShadow
tws = (not C_WhiteBody[3] and C_WhiteBody[2] and C_WhiteBody[1] and C_WhiteBody)
and (C_Body[1]>C_Body[2])
and (C_Body[2] <= C_Body[1]*0.9) and (C_Body[2] >= C_Body[1]*0.65)
and C_NoshadowUp and C_NoshadowDn and C_NoshadowUp[1] and C_NoshadowDn[1]
and C_NoshadowUp[2] and C_NoshadowDn[2]
C_ThreeBlackCrowsBearishNumberOfCandles = 3
C_3BCrw_ShadowPercent = 5.0
C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow
C_ThreeBlackCrowsBearish = false
if C_LongBody and C_LongBody[1] and C_LongBody[2]
if C_BlackBody and C_BlackBody[1] and C_BlackBody[2]
C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and
open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and
C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and
C_3BCrw_HaveNotDnShadow[2]
alertcondition(C_ThreeBlackCrowsBearish, title = "Three Black Crows – Bearish",
message = "New Three Black Crows – Bearish pattern detected")
if C_ThreeBlackCrowsBearish and ThreeBlackCrowsInput and (("Bearish" ==
CandleType) or CandleType == "Both")
//////////////////////////////////////////////////////////////////////