Moving Average Algo
Moving Average Algo
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd,
signal_length)
hist = macd - signal
// Get pivots.
[plFound, phFound, plFoundPot, phFoundPot] = fontilab.getOscPivots(osc, lbL, lbR)
//------
// Regular Bullish
plot(
false and showDiv and plotBullPot and plFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(bullDiv ? bullColor : noneColor)
)
plotshape(
false and showDiv and plotBullPot and bullDivPot ? osc[1] : na,
offset= -1,
title="Regular Bullish Pot Label",
text="B",
style=shape.labelup,
location=location.absolute,
color=bullPotColor,
textcolor=textColorDivPot
)
plotshape(
showDiv and plotBullPot and bullDiv ? osc[lbR] : na,
offset=-lbR,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.belowbar,
color=bullColor,
textcolor=textColor
)
//------
// Hidden Bullish
plot(
false and showDiv and plotHiddenBull and plFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullDiv ? hiddenBullColor : noneColor)
)
plotshape(
false and showDiv and plotHiddenBullPot and hiddenBullDivPot ? osc[1] : na,
offset=-1,
title="Hidden Bullish Pot Label",
text="H",
style=shape.labelup,
location=location.absolute,
color=bullPotColor,
textcolor=textColorDivPot
)
plotshape(
false and showDiv and plotHiddenBull and hiddenBullDiv ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text=" H Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------
// Regular Bearish
plot(
false and showDiv and plotBearPot and phFound ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(bearDiv ? bearColor : noneColor)
)
plotshape(
false and showDiv and plotBearPot and bearDivPot ? osc[1] : na,
offset=-1,
title="Regular Bearish Pot Label",
text="B",
style=shape.labeldown,
location=location.absolute,
color=bearPotColor,
textcolor=textColorDivPot
)
plotshape(
showDiv and plotBearPot and bearDiv ? osc[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.abovebar,
color=bearColor,
textcolor=textColor
)
//-----
// Hidden Bearish
plot(
false and showDiv and plotHiddenBear and phFound ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearDiv ? hiddenBearColor : noneColor)
)
plotshape(
false and showDiv and plotHiddenBearPot and hiddenBearDivPot ? osc[1] : na,
offset=-1,
title="Hidden Bearish Pot Label",
text="H",
style=shape.labeldown,
location=location.absolute,
color=bearPotColor,
textcolor=textColorDivPot
)
plotshape(
false and showDiv and plotHiddenBear and hiddenBearDiv ? osc[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label",
text=" H Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//-----------------------------------------------------
// Calculate BB
source = close
basis = ta.sma(source, length)
dev = multKC * ta.stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = ta.sma(source, lengthKC)
range_1 = useTrueRange ? ta.tr : high - low
rangema = ta.sma(range_1, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
period=input(20,"CCI period")
coeff=input(1,"ATR Multiplier")
AP=input(5,"ATR Period")
ATR=ta.sma(ta.tr,AP)
src1=input(close)
upT=low-ATR*coeff
downT=high+ATR*coeff
MagicTrend=0.0
MagicTrend := ta.cci(src1,period)>=0 ? (upT<nz(MagicTrend[1]) ? nz(MagicTrend[1]) :
upT) : (downT>nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT)
color1= ta.cci(src1,period)>=0 ? #0022FC : #FC0400
isBuy = val > nz(val[1]) and val>0 and nz(val[1]) < 0 and close > open and
isFilterBuy
isSell = val < nz(val[1]) and val<0 and nz(val[1]) > 0 and close < open and
isFilterSell