#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © Vanitati
#indicator('God Candles', overlay=true)
# converted by Sam4Cok@Samer800 - 09/2023
input lookbackPeriod = 30;#, title="Dilution"
input lineLength = 6;#, "Line Length",
input showDiamonds = yes; # "Show Diamonds",
input useSessionFilter = no; # "Use Session Time Filter"
input sessionStartTime = 1000;
input sessionEndTime = 1500;
def na = Double.NaN;
def secondsPassed = SecondsFromTime(sessionStartTime) >= 0;
def secondsRemained = SecondsTillTime(sessionEndTime) >= 0;
def rth = secondsPassed and secondsRemained;
#// ----------- God Candle Conditions ------------
def bodyBarPrevious = AbsValue(close[1] - open[1]);
def bodyBarCurrent = AbsValue(close - open);
def bullishEngulfing = (low <= low[1]) and (close >= high[1]);
def bearishEngulfing = (high >= high[1]) and (close <= low[1]);
#//god candle volume calculations
def sumVolume = Sum(volume, 10);
def av = sumVolume / 10;
def valueVolume = volume * (high - low);
def hivalueVolume = Highest(valueVolume, 10);
def va = if volume >= av * 2 or valueVolume >= hivalueVolume then 1 else
(if volume >= av * 1.5 then 2 else 0);
def isBull = close > open;
#//engulfing calculations
def lowestLow = Lowest(low[1], lookbackPeriod);
def highestHigh = Highest(high[1], lookbackPeriod);
def bullishEngulfingClimax = bullishEngulfing and
(va == 1) and isBull and (low < lowestLow);
def bearishEngulfingClimax = bearishEngulfing and
(va == 1) and !isBull and (high > highestHigh);
def bullishEngulfingDiamond = bullishEngulfing and bodyBarCurrent >= bodyBarPrevious * 2 and low[1] < open and low < open and low[1] < close and low < close;
def bearishEngulfingDiamond = bearishEngulfing and bodyBarCurrent >= bodyBarPrevious * 2 and high[1] > open and high > open and high[1] > close and high > close;
def isInSession = if useSessionFilter then RTH else yes;
def y1 = low + (open - low) / 2;
def y2 = high - (high - open) / 2;
def BullLine = if isInSession and bullishEngulfingClimax then y1 else BullLine[1];
def bearLine = if isInSession and bearishEngulfingClimax then y2 else bearLine[1];
def bullCnt = if BullLine - BullLine[1] then 0 else bullCnt[1] + 1;
def bearCnt = if bearLine - bearLine[1] then 0 else bearCnt[1] + 1;
plot GCup = if BullLine and bullCnt <= lineLength then BullLine else na;
plot GCdn = if bearLine and bearCnt <= lineLength then bearLine else na;
GCup.SetDefaultColor(Color.CYAN);
GCdn.SetDefaultColor(Color.MAGENTA);
#//Dots plotting
def bull = isInSession and bullishEngulfing and showDiamonds and
bullishEngulfingDiamond and !bullishEngulfingClimax;
def bear = isInSession and bearishEngulfing and showDiamonds and
bearishEngulfingDiamond and !bearishEngulfingClimax;
plot PressureUp = if bull then low else na;# title='Pressure up'
plot PressureDn = if bear then high else na;#='Pressure down'
PressureUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
PressureDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
PressureUp.SetDefaultColor(Color.CYAN);
PressureDn.SetDefaultColor(Color.MAGENTA);
#-- END of CODE