Hello everyone, I’m wanting to configure an alert on the cumulative tick, I want the indicator to alert when it ticks above or below the previous bar whether it’s above or below the zero line. Here is the code.
Code:
declare lower;
declare once_per_bar;
input showTimePivots = no;
def openTime = 0930;
def pivot1 = 1030;
def pivot2 = 1200;
def pivot3 = 1330;
def pivot4 = 1500;
input closeTime = 1555;
input TICK_SYMBOL = {default "$TICK", "$TICK/Q", "$TICKA", "$TICKAC", "$TICKAR","$TICKARC","$TICKC", "$TICKC/Q","$TIKI", "$TIKIC", "$TIKND", "$TIKNDC", "$TIKRL", "$TIKSP","$TICKSPC","$TIKUS", "$TIKUSC"};
def tickData = hlc3(TICK_SYMBOL);
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.RED
else Color.green);
cumulativeTick.SetLineWeight(3);
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) and showTimePivots then totalPDTAP1 / positiveDays else Double.NaN);
plot avePosTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots then totalPDTAP2 / positiveDays else Double.NaN);
plot avePosTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots then totalPDTAP3 / positiveDays else Double.NaN);
plot avePosTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close)and showTimePivots then totalPDTAP4 / positiveDays else Double.NaN);
plot aveNegTickAtPivot1 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots then totalNDTAP1 / negativeDays else Double.NaN);
plot aveNegTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots then totalNDTAP2 / negativeDays else Double.NaN);
plot aveNegTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots then totalNDTAP3 / negativeDays else Double.NaN);
plot aveNegTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) and showTimePivots 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.SHORT_DASH);
avePosTickAtPivot2.SetStyle(Curve.SHORT_DASH);
avePosTickAtPivot3.SetStyle(Curve.SHORT_DASH);
avePosTickAtPivot4.SetStyle(Curve.SHORT_DASH);
aveNegTickAtPivot1.SetStyle(Curve.SHORT_DASH);
aveNegTickAtPivot2.SetStyle(Curve.SHORT_DASH);
aveNegTickAtPivot3.SetStyle(Curve.SHORT_DASH);
aveNegTickAtPivot4.SetStyle(Curve.SHORT_DASH);
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() and showTimePivots, avePosTickAtPivot1, "+10:30", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, avePosTickAtPivot2, "+12:00", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, avePosTickAtPivot3, "+13:30", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, avePosTickAtPivot4, "+15:00", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, aveNegTickAtPivot1, "-10:30", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, aveNegTickAtPivot2, "-12:00", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, aveNegTickAtPivot3, "-13:30", Color.DARK_GRAY, yes);
AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay() and showTimePivots, aveNegTickAtPivot4, "-15:00", Color.DARK_GRAY, yes);
AddVerticalLine(SecondsTillTime(openTime) == 0 or (GetDay() != GetDay()[1] and (SecondsTillTime(0000) > 0)), "", Color.GRAY, 1);
#AssignPriceColor(if cumulativeTick < cumulativeTick [1] then Color.RED
#else Color.green);
#cumulativeTick.SetLineWeight(3);
Last edited by a moderator: