Would it be possible to make this TickQ Oscillator and the Cummulative tick to work on Extended hours?
# $TICK/Q Oscillator with Divergence
# Mobius
# V01.03.2020
declare lower;
input length = 5;
input AvgType = AverageType.HULL;
def o = open("$TICK/Q ");
def h = high("$TICK/Q ");
def l = low("$TICK/Q ");
def c = close("$TICK/Q ");
def x = BarNumber();
def nan = Double.NaN;
AddChart(h, l, c, o, ChartType.CANDLE, Color.YELLOW);
AddChart(h, l, o, c, ChartType.CANDLE, Color.CYAN);
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingEnd(GetYYYYMMDD());
plot "0" = if !RTH then Double.NaN else 0;
"0".SetDefaultColor(Color.MAGENTA);
"0".HideBubble();
"0".HideTitle();
plot avg = MovingAverage(AvgType, c, length);
avg.AssignValueColor(if avg < 0
then color.red
else color.green);
avg.HideBubble();
avg.HideTitle();
addCloud(0, avg, color.red, color.green);
plot upArrow = if avg crosses above 0
then l
else double.nan;
upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
upArrow.SetDefaultColor(Color.Green);
upArrow.SetLineWeight(3);
upArrow.HideBubble();
upArrow.HideTitle();
plot dnArrow = if avg crosses below 0
then h
else double.nan;
dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
dnArrow.SetDefaultColor(Color.Red);
dnArrow.SetLineWeight(3);
dnArrow.HideBubble();
dnArrow.HideTitle();
def hh = if avg crosses above 0
then h
else if avg > 0 and h > hh[1]
then h
else hh[1];
def xh = if h == hh
then x
else xh[1];
plot hp = if x == highestAll(xh)
then hh
else nan;
hp.SetStyle(Curve.Points);
hp.SetDefaultColor(Color.red);
hp.SetLineWeight(3);
hp.HideBubble();
hp.HideTitle();
def xh1 = if !isNaN(dnArrow)
then getValue(xh, 2)
else xh1[1];
plot hp1 = if x == highestAll(xh1)
then h
else nan;
hp1.SetStyle(Curve.Points);
hp1.SetDefaultColor(Color.red);
hp1.SetLineWeight(3);
hp1.HideBubble();
hp1.HideTitle();
plot hd = if x == highestAll(xh1)
then h
else if x == highestAll(xh)
then h
else nan;
hd.EnableApproximation();
hd.SetDefaultColor(Color.red);
hd.HideBubble();
hd.HideTitle();
def ll = if avg crosses below 0
then l
else if avg < 0 and l < ll[1]
then l
else ll[1];
def xl = if l == ll
then x
else xl[1];
plot lp = if x == highestAll(xl)
then ll
else nan;
lp.SetStyle(Curve.Points);
lp.SetDefaultColor(Color.green);
lp.SetLineWeight(3);
lp.HideBubble();
lp.HideTitle();
def xl1 = if !isNaN(dnArrow)
then xl[1]
else xl1[1];
plot lp1 = if x == highestAll(xl1)
then l
else nan;
lp1.SetStyle(Curve.Points);
lp1.SetDefaultColor(Color.green);
lp1.SetLineWeight(3);
lp1.HideBubble();
lp1.HideTitle();
plot ld = if x == highestAll(xl1)
then l
else if x == highestAll(xl)
then l
else nan;
ld.EnableApproximation();
ld.SetDefaultColor(Color.green);
ld.HideBubble();
ld.HideTitle();
# End Code TICK/Q Oscillator with Divergence
========================================================================
========================================================================
#CummulativeTick
#hint: The CumulativeTick indicator is designed to be run on a 20 day 5 minute chart of the /ES, /NQ, /TF, or /YM. Running the chart on other instruments may result in the loss of the average lines.
declare lower;
declare once_per_bar;
def openTime = 0930;
def pivot1 = 1030;
def pivot2 = 1200;
def pivot3 = 1330;
def pivot4 = 1500;
input closeTime = 1600;
def tickData = hlc3("$TICK");
rec CT = if GetDay() != GetDay()[1] then 0 else if SecondsTillTime(openTime) <= 0 and SecondsTillTime(closeTime) >= 0 then CT[1] + tickData else 0;
plot cumulativeTick = if !IsNaN(tickData) then CT else Double.NaN;
cumulativeTick.SetStyle(curve.POINTS);
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
cumulativeTick.AssignValueColor(if cumulativeTick < cumulativeTick [1] then Color.MAGENTA
else Color.CYAN);
cumulativeTick.SetLineWeight(1);
rec ticksAtPivot1 = if SecondsTillTime(pivot1) <= 0 and SecondsTillTime(pivot1)[1] > 0 then cumulativeTick else ticksAtPivot1[1];
rec ticksAtPivot2 = if SecondsTillTime(pivot2) <= 0 and SecondsTillTime(pivot2)[1] > 0 then cumulativeTick else ticksAtPivot2[1];
rec ticksAtPivot3 = if SecondsTillTime(pivot3) <= 0 and SecondsTillTime(pivot3)[1] > 0 then cumulativeTick else ticksAtPivot3[1];
rec ticksAtPivot4 = if SecondsTillTime(pivot4) <= 0 and SecondsTillTime(pivot4)[1] > 0 then cumulativeTick else ticksAtPivot4[1];
rec ticksAtClose = if SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0 then cumulativeTick else ticksAtClose[1];
def positiveDay = if (SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0) and cumulativeTick > 0 then 1 else 0;
def negativeDay = if SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0 and cumulativeTick < 0 then 1 else 0;
def positiveDayTicksAtPivot1 = if positiveDay then ticksAtPivot1 else 0;
def positiveDayTicksAtPivot2 = if positiveDay then ticksAtPivot2 else 0;
def positiveDayTicksAtPivot3 = if positiveDay then ticksAtPivot3 else 0;
def positiveDayTicksAtPivot4 = if positiveDay then ticksAtPivot4 else 0;
def negativeDayTicksAtPivot1 = if negativeDay then ticksAtPivot1 else 0;
def negativeDayTicksAtPivot2 = if negativeDay then ticksAtPivot2 else 0;
def negativeDayTicksAtPivot3 = if negativeDay then ticksAtPivot3 else 0;
def negativeDayTicksAtPivot4 = if negativeDay then ticksAtPivot4 else 0;
rec totalPDTAP1 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP1[1] + positiveDayTicksAtPivot1 else totalPDTAP1[1] else totalPDTAP1[1];
rec totalPDTAP2 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP2[1] + positiveDayTicksAtPivot2 else totalPDTAP2[1] else totalPDTAP2[1];
rec totalPDTAP3 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP3[1] + positiveDayTicksAtPivot3 else totalPDTAP3[1] else totalPDTAP3[1];
rec totalPDTAP4 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP4[1] + positiveDayTicksAtPivot4 else totalPDTAP4[1] else totalPDTAP4[1];
rec totalNDTAP1 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP1[1] + negativeDayTicksAtPivot1 else totalNDTAP1[1] else totalNDTAP1[1];
rec totalNDTAP2 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP2[1] + negativeDayTicksAtPivot2 else totalNDTAP2[1] else totalNDTAP2[1];
rec totalNDTAP3 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP3[1] + negativeDayTicksAtPivot3 else totalNDTAP3[1] else totalNDTAP3[1];
rec totalNDTAP4 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP4[1] + negativeDayTicksAtPivot4 else totalNDTAP4[1] else totalNDTAP4[1];
rec positiveDays = if !IsNaN(cumulativeTick) then if positiveDay then positiveDays[1] + 1 else positiveDays[1] else positiveDays[1];
rec negativeDays = if !IsNaN(cumulativeTick) then if negativeDay then negativeDays[1] + 1 else negativeDays[1] else negativeDays[1];
plot avePosTickAtPivot1 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP1 / positiveDays else Double.NaN);
plot avePosTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP2 / positiveDays else Double.NaN);
plot avePosTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP3 / positiveDays else Double.NaN);
plot avePosTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP4 / positiveDays else Double.NaN);
plot aveNegTickAtPivot1 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP1 / negativeDays else Double.NaN);
plot aveNegTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP2 / negativeDays else Double.NaN);
plot aveNegTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP3 / negativeDays else Double.NaN);
plot aveNegTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP4 / negativeDays else Double.NaN);
avePosTickAtPivot1.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot2.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot3.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot4.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot1.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot2.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot3.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot4.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot1.SetStyle(Curve.FIRM);
avePosTickAtPivot2.SetStyle(Curve.FIRM);
avePosTickAtPivot3.SetStyle(Curve.FIRM);
avePosTickAtPivot4.SetStyle(Curve.FIRM);
aveNegTickAtPivot1.SetStyle(Curve.FIRM);
aveNegTickAtPivot2.SetStyle(Curve.FIRM);
aveNegTickAtPivot3.SetStyle(Curve.FIRM);
aveNegTickAtPivot4.SetStyle(Curve.FIRM);
avePosTickAtPivot1.HideBubble();
avePosTickAtPivot2.HideBubble();
avePosTickAtPivot3.HideBubble();
avePosTickAtPivot4.HideBubble();
aveNegTickAtPivot1.HideBubble();
aveNegTickAtPivot2.HideBubble();
aveNegTickAtPivot3.HideBubble();
aveNegTickAtPivot4.HideBubble();
avePosTickAtPivot1.HideTitle();
avePosTickAtPivot2.HideTitle();
avePosTickAtPivot3.HideTitle();
avePosTickAtPivot4.HideTitle();
aveNegTickAtPivot1.HideTitle();
aveNegTickAtPivot2.HideTitle();
aveNegTickAtPivot3.HideTitle();
aveNegTickAtPivot4.HideTitle();
#AddChartBubble( SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot1, "+10:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot2, "+12:00", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot3, "+13:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot4, "+15:00", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot1, "-10:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot2, "-12:00", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot3, "-13:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot4, "-15:00", Color.DARK_GRAY, yes);
AddVerticalLine(SecondsTillTime(openTime) == 0 or (GetDay() != GetDay()[1] and (SecondsTillTime(0000) > 0)), "", Color.GRAY, 1);
# AI Adds
def lastHP = if x == highestAll(xh)
then xh else lastHP[1];
def lastHP1 = if x == highestAll(xh1)
then xh1 else lastHP[1];
def lastLP = if x == highestAll(xl)
then xl else lastLP[1];
def lastLP1 = if x == highestAll(xl1)
then xl1 else lastLP1[1];
Addlabel(lastHP1<lastHP,"Divergent",color.red);
Addlabel(lastLP1>lastLP,"Divergent",color.green);