Modified morning and evening stars
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeswithashish

//@version=5
indicator(title="Modified morning and evening stars", shorttitle="Trend reversal patterns ", overlay=true)
volMA=ta.sma(volume, 20)
avgbarsize=ta.sma(math.abs(open-close), 20)
//BULL PERCENTAGE 

bullper=(close-low)*100/(high-low)

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                      MORNING STAR (BULLISH PATTERN) 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

br3=bullper[2]<40 and math.abs(open[2]-close[2])/(high[2]-low[2])>0.5 //healthy bearish candle
dj2= low[1]<low[2] and math.abs(open[1]-close[1])/(high[1]-low[1])<0.3 and high[1]<high[2] // rejection and doji situation 
bl1=bullper>60 and volume>volMA and close>math.avg(low[2], high[2]) and volume>volume[1] and volume>volume[2] // Healthy bullish closing above past two bars
mrgstar=br3 and dj2 and bl1

plotshape (mrgstar, title="True Morning Star", style=shape.labelup, location=location.belowbar, color=color.green,  text="MgStar", textcolor=color.white, size=size.small)

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                   EVENING STAR (BEARISH PATTERN)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bl3=bullper[2]>60 and math.abs(open[2]-close[2])/(high[2]-low[2])>0.5 //healthy bullish
djb=low[1]>low[2] and math.abs(open[1]-close[1])/(high[1]-low[1])<0.3 and high[1]>high[2] //doji and rejection
br1=bullper<40 and volume>volMA and close<math.avg(low[2], high[2]) and volume>volume[1] and volume>volume[2] // Healthy bearish closing above past two bars

evgstar=bl3 and djb and br1

plotshape (evgstar, title="True Evening Star", style=shape.labeldown, location=location.abovebar, color=color.red,  text="EvStar", textcolor=color.white, size=size.small)

