#[email protected]
#Thanks to YungTraderFromMontana and evanevans for the ideas
#v8.25.2020
declare lower;
def NA = Double.NaN;
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;
#tick sentiment test
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];
AddLabel(1, upval, Color.GREEN);
AddLabel(1, downval, Color.RED);
def cycleticksentiment = upval / downval;
addlabel(1,"Cycle Sentiment: " +Round(cycleticksentiment,2), if !isinfinite(cycleticksentiment) and cycleticksentiment > 1 then Color.GREEN else if !isinfinite(cycleticksentiment) and cycleticksentiment < 1 then Color.RED else Color.GRAY);
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, " CVol " + prevcumulativehigh, Color.GRAY, Curve.FIRM);
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 bull then Color.GREEN else if bear then Color.RED else if neutral then Color.GRAY else Color.CURRENT);
projection.AssignValueColor(if !isinfinite(cycleticksentiment) and cycleticksentiment > 1 then Color.GREEN else if !isinfinite(cycleticksentiment) and cycleticksentiment < 1 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);