438 views
26

//@version=1
study("2",shorttitle="2", overlay=true)


// Getting inputs Fast MACD
fastlength = 3 // input(title="(Fast) Fast Length", type=integer, defval=5)
slowlength = 10 // input(title="(Fast) Slow Length", type=integer, defval=15)

// Getting inputs Slow MACD
fastlength2 = 8 // input(title="(Slow) Fast Length ", type=integer, defval=12)
slowlength2 = 18 // input(title="(Slow) Slow Length", type=integer, defval=26)


src = input(title="Close", defval=close)

//Checkbox simple MA vs EMA
sma_source = false //input(title="CHECK", type=bool, defval=false)

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

// Calculating Fast MACD
fast_ma = sma_source ? sma ( src , fastlength) : ema ( src , fastlength)
slow_ma = sma_source ? sma ( src , slowlength) : ema ( src , slowlength)
macdfast = fast_ma - slow_ma

// Calculating Slow MACD
fast_ma2 = sma_source ? sma ( src , fastlength2) : ema ( src , fastlength2)
slow_ma2 = sma_source ? sma ( src , slowlength2) : ema ( src , slowlength2)
macdslow = fast_ma2 - slow_ma2



// macd divergence
bulldiv1 = (macdfast>macdfast and macdslow<macdslow)
beardiv1 = (macdfast<macdfast and macdslow>macdslow)

macdstyle = 1//input(.1, title="Trend Deviation %")
thick = 2// input(2, title="TrendThickness (1 for line)")

colmacd = macdfast>macdslow ? col_grow_above : col_fall_below




plotshape(crossover(macdslow, macdfast), title="TriangleSHORT2", style=shape.triangledown, location=location.abovebar, color=red, size=size.small)
plotshape(crossover(macdfast, macdslow), title="TriangleLONG2", style=shape.triangleup, location=location.belowbar, color=green, size=size.small)


ema55= ema (close, 55)

//inputs
len1 = 5 //input(7,title="RSI Length")
len2 = 6 //input(9,title="EMA Length")
ema = ema (close,len1)
rsi = rsi ( ema ,len1)
rsiema = ema ( rsi ,len2)

offsetema = offset( ema (close,5),2)
check1 = high>high
check = low<low

//ENTRies
long = crossover( rsi ,rsiema) and check1
short = crossunder( rsi ,rsiema) and check



//plot trend change
plotshape(crossunder( rsi ,rsiema), title="Dot Short", style=shape.circle, location=location.abovebar, color=red, textcolor=red, size=size.tiny)
plotshape(crossover( rsi ,rsiema), title="Dot Long", style=shape.circle, location=location.belowbar, color=green, textcolor=green, size=size.tiny)

alertcondition(long, title="Dot Long", message="DotLong")
alertcondition(short, title="Dot Short", message="DotShort")




// div start

source = close
fast_length = 5 // input(title="(Fast) Fast Length", type=integer, defval=5)
long_term_div = true //input(true, title="Use long term Divergences?")
div_lookback_period = 55 // input(55, minval=1, title="Lookback Period")
fastLength = 9 // input(9, minval=1)
slowLength= 21 // input(21,minval=1)
signalLength= 1 //input(1,minval=1)
smoother = 1 // input(1,minval=1)
fastMA = ema (source, fastLength)
slowMA = ema (source, slowLength)
macd = fastMA - slowMA
macd2=( macd /slowMA)*100
d = sma (macd2, smoother) // smoothing PPO

bullishPrice = low

priceMins = bullishPrice > bullishPrice and bullishPrice < bullishPrice or low == low and low < low and low < low or low == low and low == low and low < low and low < low or low == low and low == low and low and low == low and low < low and low < low // this line identifies bottoms and plateaus in the price
oscMins= d > d and d < d // this line identifies bottoms in the PPO


BottomPointsInPPO = oscMins

bearishPrice = high
priceMax = bearishPrice < bearishPrice and bearishPrice > bearishPrice or high == high and high > high and high > high or high == high and high == high and high > high and high > high or high == high and high == high and high and high == high and high > high and high > high // this line identifies tops in the price
oscMax = d < d and d > d // this line identifies tops in the PPO

TopPointsInPPO = oscMax



currenttrough4=valuewhen (oscMins, d, 0) // identifies the value of PPO at the most recent BOTTOM in the PPO
lasttrough4=valuewhen (oscMins, d, 1) // NOT USED identifies the value of PPO at the second most recent BOTTOM in the PPO
currenttrough5=valuewhen (oscMax, d, 0) // identifies the value of PPO at the most recent TOP in the PPO
lasttrough5=valuewhen (oscMax, d, 1) // NOT USED identifies the value of PPO at the second most recent TOP in the PPO

currenttrough6=valuewhen (priceMins, low, 0) // this line identifies the low (price) at the most recent bottom in the Price
lasttrough6=valuewhen (priceMins, low, 1) // NOT USED this line identifies the low (price) at the second most recent bottom in the Price
currenttrough7=valuewhen (priceMax, high, 0) // this line identifies the high (price) at the most recent top in the Price
lasttrough7=valuewhen (priceMax, high, 1) // NOT USED this line identifies the high (price) at the second most recent top in the Price


delayedlow = priceMins and barssince(oscMins) < 3 ? low : na
delayedhigh = priceMax and barssince(oscMax) < 3 ? high : na

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away
filter = barssince(priceMins) < 5 ? lowest(currenttrough6, 4) : na
filter2 = barssince(priceMax) < 5 ? highest(currenttrough7, 4) : na

//delayedbottom/top when oscillator bottom/top is earlier than price bottom/top
y11 = valuewhen(oscMins, delayedlow, 0)
y12 = valuewhen(oscMax, delayedhigh, 0)

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away, since 2nd most recent top/bottom in osc
y2=valuewhen(oscMax, filter2, 1) // identifies the highest high in the tops of price with 5 bar lookback period SINCE the SECOND most recent top in PPO
y6=valuewhen(oscMins, filter, 1) // identifies the lowest low in the bottoms of price with 5 bar lookback period SINCE the SECOND most recent bottom in PPO

long_term_bull_filt = valuewhen(priceMins, lowest(div_lookback_period), 1)
long_term_bear_filt = valuewhen(priceMax, highest(div_lookback_period), 1)

y3=valuewhen(oscMax, currenttrough5, 0) // identifies the value of PPO in the most recent top of PPO
y4=valuewhen(oscMax, currenttrough5, 1) // identifies the value of PPO in the second most recent top of PPO




y7=valuewhen(oscMins, currenttrough4, 0) // identifies the value of PPO in the most recent bottom of PPO
y8=valuewhen(oscMins, currenttrough4, 1) // identifies the value of PPO in the SECOND most recent bottom of PPO

y9=valuewhen(oscMins, currenttrough6, 0)
y10=valuewhen(oscMax, currenttrough7, 0)

bulldiv= BottomPointsInPPO ? d : na // plots dots at bottoms in the PPO
beardiv= TopPointsInPPO ? d: na // plots dots at tops in the PPO


i = currenttrough5 < highest(d, div_lookback_period) // long term bearish oscilator divergence
i2 = y10 > long_term_bear_filt // long term bearish top divergence
i3 = delayedhigh > long_term_bear_filt // long term bearish delayedhigh divergence

i4 = currenttrough4 > lowest(d, div_lookback_period) // long term bullish osc divergence
i5 = y9 < long_term_bull_filt // long term bullish bottom div
i6 = delayedlow < long_term_bull_filt // long term bullish delayedbottom div




dev= 14 //input(14, title="SET")

shortCond = oscMax and (((d / valuewhen(oscMax, d, 1)) > 1-(dev/100)) and ((d / valuewhen(oscMax, d, 1)) < 1+(dev/100)))
longCond = oscMins and (((d / valuewhen(oscMins, d, 1)) > 1-(dev/100)) and ((d / valuewhen(oscMins, d, 1)) < 1+(dev/100)))



plotshape(shortCond, title="Triangle Long", style=shape.triangledown, location=location.abovebar, color=red, size=size.small)
plotshape(longCond, title="Triangle Short", style=shape.triangleup, location=location.belowbar, color=green, size=size.small)
Remove from Favorite Scripts Add to Favorite Scripts

Comments

Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out