############################ Signal
input VxNetagg3Length = 7;
input Volume_Bias_Based_on3 = { default "Close_Price" , "Trend" }; ## this makes a difference only in few bars.. it's not used in any calc
input VxNetSmooth_agg3 = 6;
input VolPressureCalc3 = { default "WAverage", "Sum" };
input VxNetagg3 = AggregationPeriod.FIVE_MIN;
def VxNetagg3_O = open(period = VxNetagg3);
def VxNetagg3_C = close(period = VxNetagg3);
def VxNetagg3_H = high(period = VxNetagg3);
def VxNetagg3_L = low(period = VxNetagg3);
def VxNetagg3_V = volume(period = VxNetagg3);
def VolState_agg3;
switch (Volume_Bias_Based_on3) {
case Trend:
VolState_agg3 = if VxNetagg3_C > VxNetagg3_C[1] then 1 else if VxNetagg3_C == VxNetagg3_C [1] then 0 else -1;
default :
VolState_agg3 = if VxNetagg3_C > VxNetagg3_O then 1 else if VxNetagg3_C == VxNetagg3_O then 0 else -1;
}
def Vx_agg3 = if VolPressureCalc3 == VolPressureCalc3.Sum then Sum(VxNetagg3_V, VxNetagg3Length) else WMA(VxNetagg3_V, VxNetagg3Length) ;
def Range_agg3 = VxNetagg3_H - VxNetagg3_L;
def VolUp_agg3 = if VxNetagg3_C > VxNetagg3_O and Range_agg3 <> 0 then (Range_agg3 / (2 * Range_agg3 + VxNetagg3_O - VxNetagg3_C)) * VxNetagg3_V
else if VxNetagg3_C < VxNetagg3_O and Range_agg3 <> 0 then ((Range_agg3 + VxNetagg3_C - VxNetagg3_O) / (2 * Range_agg3 + VxNetagg3_C - VxNetagg3_O)) * VxNetagg3_V
else 0.5 * VxNetagg3_V;
def VolDn_agg3 = VxNetagg3_V - VolUp_agg3;
def VxPlus_agg3 = if VolPressureCalc3 == VolPressureCalc3.Sum then Sum (VolUp_agg3, VxNetagg3Length) else WMA (VolUp_agg3, VxNetagg3Length);
def VxMinus_agg3 = if VolPressureCalc3 == VolPressureCalc3.Sum then Sum (VolDn_agg3, VxNetagg3Length) else WMA (VolDn_agg3, VxNetagg3Length);
def VxNetRaw_agg3 = VxPlus_agg3 - VxMinus_agg3 ;
## Smooth with a very short zero-lag to eliminate outliers
##### New Stuff #######
def VxRatioPlot_agg3 = 100 * VxNetRaw_agg3 / Vx_agg3;
def VxRatioPlotSmoothed_agg3 = 2 * WMA(VxRatioPlot_agg3, VxNetSmooth_agg3) - WMA(WMA(VxRatioPlot_agg3, VxNetSmooth_agg3), VxNetSmooth_agg3);
# Smart Momentum Tiers
def MomentumShiftDown = if((VxRatioPlotSmoothed_agg3 from 1 or 2 or 3 bars ago > 20) and (VxRatioPlotSmoothed_agg3 < ((VxRatioPlotSmoothed_agg3 from 1 or 2 or 3 bars ago) - 10)), 1, 0);
def MomentumShiftUp = if((VxRatioPlotSmoothed_agg3 from 1 or 2 or 3 bars ago < -20) and (VxRatioPlotSmoothed_agg3 > ((VxRatioPlotSmoothed_agg3 from 1 or 2 or 3 bars ago) + 10)), 1, 0);
#Mean Reversion
#The logic I am hoping to eventually use
def VxIncreasing = if VxRatioPlotSmoothed_agg3 > VxRatioPlotSmoothed_agg3[1] then 1 else 0;
def longentry = MomentumShiftUp and VxIncreasing is true;
def BarsFromLongEntry = if longentry[1] == 1 then 1 else BarsFromLongEntry[1] + 1;
def hold_has_been_true_for_n_bars_long = if (VxIncreasing + BarsFromLongEntry) == BarsFromLongEntry then 1 else 0;
def holdlong = if hold_has_been_true_for_n_bars_long == 1 then 1 else 0;
plot holdlongplot = if holdlong is true then low else Double.NaN;
#The signals that are avalible
def longexit = if VxIncreasing[1] == 1 and VxIncreasing == 0 then 1 else 0;
plot entry_signal = if longentry then high else double.nan;
plot exit_signal = if longexit == 1 then high else double.nan;