#[email protected]
#Volume Profile All-In-One
##########################
#Seconds based for TICK charts
#High Volume Deviations
#Regular Trading Hours
#Extended Trading Hours
#Every X Number of Bars
#Anchored at Date/Time
#Moving Average Crossover
#RSI OverBought/OverSold
#CCI OverBought/OverSold
#v8.30.2020
declare upper;
def NA = Double.NaN;
input VolumeProfileTrigger = {SecondsBasedForTick, VolumeDeviations, default RegularTradingHours, ExtendedTradingHours, EveryXNumberOfBars, AnchorAtDateTime, MovingAverageCross, RSI_OBOS, CCI_OBOS};
input aggregationInSeconds = 300;
input start = 0930;
input end = 1600;
def YYYYMMDD = GetYYYYMMDD();
def RTH = SecondsFromTime(start) >=0 and SecondsFromTime(end) <=0;
def o = open;
def h = high;
def c = close;
def l = low;
def v = volume;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def test = min != min[1];
############################################
#Deviations in Volume
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
def VolAvg = MovingAverage(volAverageType, V, avgVolLength);
#2Sigma and 3Sigma Vol Filter
input Sigma2Deviation = 2.0;
input Sigma3Deviation = 3.0;
def averageType = AverageType.SIMPLE;
def sDev = StDev(data = V, length = avgVolLength);
def VolSigma2 = VolAvg + Sigma2Deviation * sDev;
def VolSigma3 = VolAvg + Sigma3Deviation * sDev;
############################################
#Every X Number of Bars
input everyXNumberBars = 40;
def bn = barNumber();
def cnt = if isnan(cnt[1]) then 1 else if cnt[1] <= everyXNumberBars then cnt[1]+ 1 else 1;
def xcnttest = if cnt[1] == everyXNumberBars then 1 else 0;
############################################
#Anchored Date/Time
input dateAnchor = 20200827;
input timeAnchor = 0930;
def dateTest = if YYYYMMDD == dateAnchor then 1 else 0;
def timeTest = if SecondsTillTime(timeAnchor) ==0 then 1 else 0;
############################################
#Moving Average Crosses
input movAvg1Price = close;
input movAvg2Price = close;
input movAvg1Type = AverageType.SIMPLE;
input movAvg2Type = AverageType.SIMPLE;
input movAvg1Length = 18;
input movAvg2Length = 50;
def movAvg1 = MovingAverage(movAvg1Type, movAvg1Price, movAvg1Length);
def movAvg2 = MovingAverage(movAvg2Type, movAvg2Price, movAvg2Length);
def MAtest = if (movAvg1 crosses below movAvg2) or (movAvg1 crosses above movAvg2) then 1 else 0;
############################################
#RSI
input rsiLength = 14;
input rsiOverBought = 75;
input rsiOverSold = 25;
input rsiPrice = close;
input rsiAvgType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, rsiPrice - rsiPrice[1], rsiLength);
def TotChgAvg = MovingAverage(averageType, AbsValue(rsiPrice - rsiPrice[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIOBtest = RSI >= rsiOverBought;
def RSIOStest = RSI <= rsiOverSold;
############################################
#CCI
input CCIlength = 14;
input cciOverBought = 140;
input cciOverSold = -140;
def cciPrice = c + l + h;
def linDev = lindev(cciPrice, CCIlength);
def CCI = if linDev == 0 then 0 else (cciPrice - Average(cciPrice, CCIlength)) / linDev / 0.015;
def cciOBtest = CCI >= cciOverBought;
def cciOStest = CCI <= cciOverSold;
############################################
#Volume Profile
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 50;
input height = .25;
def vcond;
switch(VolumeProfileTrigger){
case SecondsBasedForTick:
vcond = if test then 1 else 0;
case VolumeDeviations:
vcond = if v > VolSigma2 or v > VolSigma3 then 1 else 0;
case RegularTradingHours:
vcond = if !RTH and RTH[1] then 1 else if !RTH then 1 else 0;
case ExtendedTradingHours:
vcond = if RTH and !RTH[1] then 1 else if RTH then 1 else 0;
case EveryXNumberOfBars:
vcond = if xcnttest then 1 else 0;
case AnchorAtDateTime:
vcond = if dateTest and timeTest then 1 else 0;
case MovingAverageCross:
vcond = if MAtest then 1 else 0;
case RSI_OBOS:
vcond = if RSIOBtest or RSIOStest then 1 else 0;
case CCI_OBOS:
vcond = if cciOBtest or cciOStest then 1 else 0;
};
profile vol = VolumeProfile("startNewProfile" = vcond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc = if IsNaN(vol.GetPointOfControl()) and con then pc[1] else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea()) and con then hVA[1] else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea()) and con then lVA[1] else vol.GetLowestValueArea();
def hProfile = if IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(c) == onExpansion;
plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;
DefineGlobalColor("Profile", Color.DARK_GRAY);
DefineGlobalColor("Point Of Control", Color.DARK_ORANGE);
DefineGlobalColor("Value Area", Color.GRAY);
vol.Show(GlobalColor("Profile"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(Color.GRAY);
ProfileLow.SetDefaultColor(Color.GRAY);
ProfileHigh.Hide();
ProfileLow.Hide();