#[email protected]
#Attempt at Volume Projection on low TICK charts
#Thanks to YungTraderFromMontana and evanevans for the ideas
#v8.30.2020
declare lower;
def NA = Double.NaN;
input Sentiment = {ContinuousCloseAboveBelowRatio, Inertia, SummativeStrength, HeikenAshiTrend, default AboveBelowMovAvg, AboveBelowHighVolTriggeredVWAP};
input aggregationInSeconds = 60;
input elapsedPercentSmoothValue = 5;
input elapsedProjectionDivisor = 2;
input showVerticalExceedPrevCvol = yes;
input showVerticalCycleEndCvol = yes;
def start = 0000;
def end = 1600;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def bull = c > c[1];
def bear = c < c[1];
def neutral = c == o;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(end) / aggregationInSeconds;
def test = min != min[1];
def vc = if test and !test[1] then v else if !test then vc[1] + v else vc[1];
def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multipliertest = aggregationInSeconds / secondselapsed;
def multiplier = if IsInfinite(multipliertest) then NA else multipliertest;
def percntelapsed = Round(((secondselapsed / aggregationInSeconds) * 100), 0);
def cl = if test then 1 else cl[1] + 1;
def ch = if test then cl[1] else ch[1];
def prevcumulativehigh = if test and !test[1] then vc[1] else prevcumulativehigh[1];
def cvolpassprev = vc >= prevcumulativehigh and vc[1] < prevcumulativehigh;
def highestprevchigh = HighestAll(prevcumulativehigh);
def projectioncalc = vc * multiplier;
######################
#Continuous Close Above/Below Previous Ratio
def upval = if test and !test[1] and bull then 1 else if !test and bull then upval[1] + 1 else if test and bear then 0 else upval[1];
def downval = if test and !test[1] and bear then 1 else if !test and bear then downval[1] + 1 else if test and bull then 0 else downval[1];
def ContinuousCloseRatio = upval / downval;
######################
#Inertia
input inertiaLength = 20;
input inertiaPrice = close;
def inertia = inertia(inertiaPrice,inertiaLength);
######################
#Summative Volume Strength based on close position
input summativeLength = 5;
def bvolsum = Sum(((c - l) / (h - l)) * v, summativeLength);
def svolsum = Sum(((h - c) / (h - l)) * v, summativeLength);
######################
#Heiken Ashi
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
HAhigh = Max(Max(h, HAopen), HAclose[1]);
HAlow = Min(Min(l, HAopen), HAclose[1]);
HAclose = ohlc4;
######################
#Above Below Moving Average
input movAvgPrice = close;
input movAvgType = AverageType.SIMPLE;
input movAvgLength = 50;
def MA = MovingAverage(movAvgType, movAvgPrice, movAvgLength);
######################
#Sigma Vol Filters
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
input Sigma2 = 2.0;
input Sigma3 = 3.0;
def VolAvg = MovingAverage(volAverageType, v, avgVolLength);
def sDev = StDev(data = v, length = avgVolLength);
def VolSigma2 = VolAvg + Sigma2 * sDev;
def VolSigma3 = VolAvg + Sigma3 * sDev;
######################
#VWAP
def vconf =if v > volsigma3 then 1 else if v > volsigma2 then 1 else 0;
def VolumeSum = if vconf then v else CompoundValue(1, VolumeSum[1] + v, v);
def VolumeVwapSum = if vconf then v * vwap else CompoundValue(1, VolumeVwapSum[1] + v * vwap, v * vwap);
def volumeVwap2Sum = if vconf then v * Sqr(vwap) else CompoundValue(1, volumeVwap2Sum[1] + v * Sqr(vwap), v * Sqr(vwap));
def VW = if !IsNaN(c) then VolumeVwapSum / VolumeSum else VW[1];
plot cvolpassprevsig = if cvolpassprev then vc else NA;
plot CVol = vc;
plot prevchigh = prevcumulativehigh;
plot cycleavg = Round(TotalSum(if test then ch[1] else 0) / min, 1);
plot cyclehigh = ch;
plot cyclelength = cl;
plot projection = if (projectioncalc >= highestprevchigh) and (percntelapsed < elapsedPercentSmoothValue) then projectioncalc / elapsedProjectionDivisor else projectioncalc;
cycleavg.Hide();
cyclehigh.Hide();
cyclelength.Hide();
AddVerticalLine(showVerticalExceedPrevCvol and !IsNaN(cvolpassprevsig), " " + secondselapsed + "s / " + aggregationInSeconds + " | " + percntelapsed + "%", Color.CYAN);
AddVerticalLine(showVerticalCycleEndCvol and test, " Length " + cyclelength[1] + " CVol " + prevcumulativehigh, Color.GRAY, Curve.FIRM);
def Pos;
def Neg;
switch (Sentiment){
case ContinuousCloseAboveBelowRatio:
Pos = !IsInfinite(ContinuousCloseRatio) and ContinuousCloseRatio > 1;
Neg = !IsInfinite(ContinuousCloseRatio) and ContinuousCloseRatio < 1;
case Inertia:
Pos = inertia > inertia[1];
Neg = !Pos;
case SummativeStrength:
Pos = bvolsum > svolsum;
Neg = svolsum > bvolsum;
case HeikenAshiTrend:
Pos = HAclose > HAopen;
Neg = !Pos;
case AboveBelowMovAvg:
Pos = close > MA;
Neg = !Pos;
case AboveBelowHighVolTriggeredVWAP:
Pos = close > VW;
Neg = !Pos;
}
#Labels
AddLabel(Sentiment == Sentiment.ContinuousCloseAboveBelowRatio, upval, Color.GREEN);
AddLabel(Sentiment == Sentiment.ContinuousCloseAboveBelowRatio, downval, Color.RED);
AddLabel(Sentiment == Sentiment.ContinuousCloseAboveBelowRatio, "Cycle Sentiment: " + Round(ContinuousCloseRatio, 2), if !IsInfinite(ContinuousCloseRatio) and ContinuousCloseRatio > 1 then Color.GREEN else if !IsInfinite(ContinuousCloseRatio) and ContinuousCloseRatio < 1 then Color.RED else Color.GRAY);
AddLabel(1, "Cycle Length: " + cyclelength[1], Color.GRAY);
AddLabel(1, "Prev Cycle Length: " + cyclehigh, Color.GRAY);
AddLabel(1, "Cycle Avg: " + cycleavg, Color.GRAY);
AddLabel(1, "Cycles Since Start: " + min, Color.GRAY);
AddLabel(1, "Secs " + secondselapsed + "/" + aggregationInSeconds + " " + percntelapsed + "%", Color.YELLOW);
AddLabel(1, "CVol: " + vc, Color.WHITE);
AddLabel(1, "Prev CVol: " + prevcumulativehigh, Color.WHITE);
AddLabel(1, "x" + Round(vc / prevcumulativehigh, 2) + " Prev CVol", Color.WHITE);
AddLabel(1, "Proj Vol: " + Round(projection, 0), Color.DARK_ORANGE);
AddLabel(1, "Proj Multiplier x" + Round(multiplier, 2), Color.DARK_ORANGE);
CVol.SetDefaultColor(Color.DARK_GRAY);
CVol.SetLineWeight(2);
prevchigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevchigh.SetDefaultColor(Color.YELLOW);
projection.SetDefaultColor(Color.DARK_ORANGE);
projection.AssignValueColor(if Pos then Color.GREEN else if Neg then Color.RED else Color.GRAY);
projection.SetLineWeight(2);
cvolpassprevsig.SetPaintingStrategy(PaintingStrategy.POINTS);
cvolpassprevsig.SetLineWeight(3);
AddCloud(projection, CVol, CreateColor(0, 100, 200), CreateColor(0, 100, 200));
AddCloud(CVol, 0, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(CVol, prevchigh, Color.YELLOW, Color.BLACK);