# CumulativeVolumeDeltaPlusDeltaSignals
#Pseudo Delta Signals based on Trade-Devils Footprint Indicator
#
https://tradedevils-indicators.com/products/footprint-orderflow-indicator-ninjatrader
# The length of the accumulation is user controlled. The cumulative bar
# is the sum of the deltas for the past 10 bars. Change that length to
# 252 (a year in days) then plot something like AAPL. Very interesting.
#Comment out ring if audio alerts not wanted
# LongShort
# 5.7.2019
declare lower;
input length = 10;
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def Delt = buying - selling;
plot Delta = Delt;
Delta.AssignValueColor(if Delta > 0 then Color.GREEN else Color.RED);
Delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Delta.hide();
Plot DeltaFadingBearish = rsi(5)>50 and Delta[2] > 0 and Delta[2] < Delta[3] and Delta[1]> 0 and Delta[1] < Delta[2] and Delta > 0 and Delta <Delta[1];
Plot DeltaFadingBullish = rsi(5)< 50 and Delta[2] < 0 and Delta[2] > Delta[3] and Delta[1]< 0 and Delta[1] > Delta[2] and Delta < 0 and Delta > Delta[1];
Plot DeltaRise = Delta > Delta[1] and Delta[1] > Delta[2] and Delta[2] > Delta[3] and Delta[3] > Delta[4];
Plot DeltaFall = Delta < Delta[1] and Delta[1] < Delta[2] and Delta[2] < Delta[3] and Delta[3] < Delta[4];
Plot DeltaDvgPos = Lowest(low,10) and close > close[1] and delta > 0 ;
Plot DeltaDvgNeg = Highest(high,10) and close < close[1] and delta < 0 ;
Plot DeltaTrapBullish = simpleMovingAvg(close,10)> simpleMovingAvg(close,20) and low[2] == Lowest(low,3) and close[2]< close[3] and delta[2]<0 and close[1]> close[2] and delta[1]>0 and close > close[1] and delta>delta[1] and close > high[2];
Plot DeltaTrapBearish = simpleMovingAvg(close,10) < simpleMovingAvg(close,20) and high[2] == highest(high,3) and close[2]> close[3] and delta[2]>0 and close[1]< close[2] and delta[1]<0 and close < close[1] and delta<delta[1] and close <low[2];
Plot DeltaSlingshotBull = rsi(5)[2]<45 and delta[2]<0 and close[2]< close[3] and delta[1]>0 and close[1] > close[2] and delta> delta[1] and close>close[1] and close> high[2];
Plot DeltaSlingshotBear = rsi(5)[2]>65 and delta[2]>0 and close[2]> close[3] and delta[1]<0 and close[1] <close[2] and delta<delta[1] and close<close[1] and close< low[2];
Plot DeltaSweepBull = rsi(5)[1]<45 and delta[1]<0 and close[1]< close[2] and delta >0 and close > close[1] and volume >volume[1]*2;
Plot DeltaSweepBear = rsi(5)[1]>65 and delta[1]>0 and close[1]>close[2] and delta <0 and close < close[1] and volume >volume[1]*2;
Plot DeltaFadingBearishIntraday = close is greater than vwap and rsi(5)>50 and Delta[2] > 0 and Delta[2] < Delta[3] and Delta[1]> 0 and Delta[1] < Delta[2] and Delta > 0 and Delta <Delta[1];
Plot DeltaFadingBullishIntraday = close is less than vwap and rsi(5)< 50 and Delta[2] < 0 and Delta[2] > Delta[3] and Delta[1]< 0 and Delta[1] > Delta[2] and Delta < 0 and Delta > Delta[1];
Plot DeltaRiseIntraday = close is greater than vwap and Delta > Delta[1] and Delta[1] > Delta[2] and Delta[2] > Delta[3] and Delta[3] > Delta[4];
Plot DeltaFallIntraday = close is less than vwap and Delta < Delta[1] and Delta[1] < Delta[2] and Delta[2] < Delta[3] and Delta[3] < Delta[4];
Plot DeltaDvgPosIntraday = close is less than vwap and Lowest(low,10) and close > close[1] and delta > 0 ;
Plot DeltaDvgNegIntraday = close is greater than vwap and Highest(high,10) and close < close[1] and delta < 0 ;
Plot DeltaTrapBullishIntraday = close is greater than vwap and simpleMovingAvg(close,10)> simpleMovingAvg(close,20) and low[2] == Lowest(low,3) and close[2]< close[3] and delta[2]<0 and close[1]> close[2] and delta[1]>0 and close > close[1] and delta>delta[1] and close > high[2];
Plot DeltaTrapBearishIntraday = close is less than vwap and simpleMovingAvg(close,10) < simpleMovingAvg(close,20) and high[2] == highest(high,3) and close[2]> close[3] and delta[2]>0 and close[1]< close[2] and delta[1]<0 and close < close[1] and delta<delta[1] and close <low[2];
Plot DeltaSlingshotBullIntraday = close is less than vwap and rsi(5)[2]<45 and delta[2]<0 and close[2]< close[3] and delta[1]>0 and close[1] > close[2] and delta> delta[1] and close>close[1] and close> high[2];
Plot DeltaSlingshotBearIntraday = close is less than vwap and rsi(5)[2]>65 and delta[2]>0 and close[2]> close[3] and delta[1]<0 and close[1] <close[2] and delta<delta[1] and close<close[1] and close< low[2];
Plot DeltaSweepBullIntraday = close is greater than vwap and rsi(5)[1]<45 and delta[1]<0 and close[1]< close[2] and delta >0 and close > close[1] and volume >volume[1]*2;
Plot DeltaSweepBearIntraday = close is less than vwap and rsi(5)[1]>65 and delta[1]>0 and close[1]>close[2] and delta <0 and close < close[1] and volume >volume[1]*2;
#Alerts
def DeltaFadingBearishAlert = DeltaFadingBearish;
Alert(DeltaFadingBearishAlert,"DeltaFadingBearish", Alert.Bar, Sound.Ring);
def DeltaFadingBullishAlert = DeltaFadingBullish;
Alert(DeltaFadingBullishAlert,"DeltaFadingBullish", Alert.Bar, Sound.Ring);
def DeltaRiseAlert = DeltaRise;
Alert(DeltaRiseAlert,"DeltaRise", Alert.Bar, Sound.Ring);
def DeltaFallAlert = DeltaFall;
Alert(DeltaFallAlert," DeltaFall", Alert.Bar, Sound.Ring);
def DeltaDvgPosAlert = DeltaDvgPos;
Alert(DeltaDvgPosAlert,"DeltaDvgPos", Alert.Bar, Sound.Ring);
def DeltaDvgNegAlert = DeltaDvgNeg;
Alert(DeltaDvgNegAlert,"DeltaDvgNeg", Alert.Bar, Sound.Ring);
def DeltaTrapBullishAlert = DeltaTrapBullish;
Alert(DeltaTrapBullishAlert,"DeltaTrapBullish", Alert.Bar, Sound.Ring);
def DeltaTrapBearishAlert = DeltaTrapBearish;
Alert(DeltaTrapBearishAlert,"DeltaTrapBearish", Alert.Bar, Sound.Ring);
def DeltaSlingshotBullAlert = DeltaSlingshotBull;
Alert(DeltaSlingshotBullAlert," DeltaSlingshotBull", Alert.Bar, Sound.Ring);
def DeltaSlingshotBearAlert = DeltaSlingshotBear;
Alert(DeltaSlingshotBearAlert,"DeltaSlingshotBear", Alert.Bar, Sound.Ring);
def DeltaSweepBullAlert = DeltaSweepBull;
Alert(DeltaSweepBullAlert,"DeltaSweepBull", Alert.Bar, Sound.Ring);
def DeltaSweepBearAlert = DeltaSweepBear;
Alert(DeltaSweepBearAlert,"DeltaSweepBear", Alert.Bar, Sound.Ring);
plot zero = 0;
zero.setDefaultColor(Color.BLUE);
plot CumulativeVolumeDelta = sum(Delta,length);
CumulativeVolumeDelta.AssignValueColor(if CumulativeVolumeDelta > 0 then Color.GREEN else Color.RED);
CumulativeVolumeDelta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Plot CumulativeDeltaTrendBuyIntraday = close is greater than vwap and rsi(5)<50 and CumulativeVolumeDelta >0;
Plot CumulativeDeltaTrendSellIntraday = close is less than vwap and rsi(5)>50 and CumulativeVolumeDelta < 0;
def CumulativeDeltaTrendBuyIntradayAlert = CumulativeDeltaTrendBuyIntraday;
Alert(CumulativeDeltaTrendBuyIntradayAlert,"CumulativeDeltaTrendBuyIntraday", Alert.Bar, Sound.Ring);
def CumulativeDeltaTrendSellIntradayAlert = CumulativeDeltaTrendSellIntraday;
Alert(CumulativeDeltaTrendSellIntradayAlert,"CumulativeDeltaTrendSellIntraday", Alert.Bar, Sound.Ring);