Cant get arrows right on study

I'm making an ADR CCI study, and am really just putting finishing touches on. I have a lower and upper study, and the upper study is supposed to show arrows on price, but there are too many, and I want the code to turn off arrows that are 1 bar after an arrow signal that already fired. I've been able to accomplish this with past studies and I'm not sure where I'm going wrong. The piece of code I'm looking at is immediately below, and I've included the whole study below that for reference. Can someone please help me?

#Lower Study Arrows Off by Default#
plot UpSignalOS_lt = if !lt_overOS125[1] and lt_overOS125 then CCI_Lt
else double.nan;
plot UpSignal_lt = if !UpSignalOS_lt[1] and (OSlb_lt and !OSlb_lt[1]) then CCI_Lt
else Double.NaN;

plot DownSignalOB_lt = if !lt_underOB125[1] and lt_underOB125 then CCI_Lt
else double.nan;
plot DownSignal_lt = if ShowLTBreakoutSignals and ShowLT_OBBreakoutSignals and (OBlb_lt and !OBlb_lt[1]) and !DownSignalOB_lt[1] then CCI_Lt
else Double.NaN;

Whole Code:
Ruby:
declare upper;



input length = 20;
input ShowATR = no;
input ShowADR = no;
input ShowADRpercent = no;
input ShowADRpercentReal = no;
input ShowADRdiff = no;


def agg = AggregationPeriod.DAY;
def Pd = close(period = agg);
def hi = high(period = AggregationPeriod.DAY);
def lo = low(period = AggregationPeriod.DAY);

plot ATR = MovingAverage(AverageType.WILDERS, TrueRange(hi, Pd, lo), length);
ATR.SetDefaultColor(Color.GRAY);
ATR.SetHiding(!ShowATR);

##AddLabel (yes, "ATR:" + Round((ATR / close) * 100, 3) + "%", Color.LIGHT_GRAY);


##AddLabel (yes, "ATR:" + round((ATR) , 3), Color.LIGHT_GRAY);


plot ADR = MovingAverage(AverageType.WILDERS, hi - lo, length);
ADR.SetDefaultColor(Color.BLACK);
ADR.SetHiding(!ShowADR);

plot ADRpercent = Round((ADR / Pd) * 100, 2);
ADRpercent.SetDefaultColor(Color.BLUE);
ADRpercent.SetLineWeight(1);
ADRpercent.SetHiding(!ShowADRpercent);


###"today %" higher than the " Avg %" DOES IT WORK??

def ADRover = (((Pd[0] - Pd[1]) / Pd[1]) * 100) > ADRpercent;
def ADRunder = (((Pd[0] - Pd[1]) / Pd[1]) * 100) < ADRpercent;

#AddCloud(ADRover, ADRunder, Color.GREEN, Color.RED);

def ADRpercentReal = ((Pd - Pd[1]) / Pd[1] * 100);

##############################################################################################
##############################################################################################
# def average of %ADR Raw compared to %ADR 20 day Average

def ADRpD = ADRpercentReal;
input ba_length = 2;
input ba_type =  AverageType.EXPONENTIAL;
def ba = MovingAverage(ba_type, ADRpD, ba_length);


def BaseAvg = ba;

##############################################################################################
####### Tema on 2 period EMA of %ADR Raw ##################################

input ADRdevT_length_lt = 68;
def ADRdevT_lt = TEMA(BaseAvg, ADRdevT_length_lt);

input ADRdevT_length_mt = 22;
def ADRdevT_mt = TEMA(BaseAvg, ADRdevT_length_mt);

input ADRdevT_length_st = 10;
def ADRdevT_st = TEMA(BaseAvg, ADRdevT_length_st);

#################################################################################################
###CCI Lengths ST, MT, LT###
input show_LT_CCI = yes;
input show_MT_CCI = yes;
input show_ST_CCI = yes;

input ccilength_lt = 51;
input ccilength_mt = 17;
input ccilength_st = 10;

input over_sold = -100;
input over_bought = 100;

def "-125" = -125;
#OBpos.SetDefaultColor(Color.DARK_GREEN);
#OBpos.SetStyle(Curve.FIRM);
#OBpos.SetLineWeight(2);

def "-145" = -145;
#lowpos.SetDefaultColor(Color.GREEN);
#lowpos.SetStyle(Curve.MEDIUM_DASH);
#lowpos.SetLineWeight(1);

def "+125" = 125;
#lowestpos.SetDefaultColor(Color.BLACK);
#lowestpos.SetStyle(Curve.POINTS);
#lowestpos.SetLineWeight(1);

def "+145" = 145;
#OSneg.SetDefaultColor(Color.DARK_RED);
#OSneg.SetStyle(Curve.FIRM);
#OSneg.SetLineWeight(2);

input showLT_OSBreakoutSignals = yes;
input showLT_OBBreakoutSignals = yes;
input showLTBreakoutSignals = yes;
input showMT_OSBreakoutSignals = no;
input showMT_OBBreakoutSignals = no;
input showMTBreakoutSignals = no;
input showST_OSBreakoutSignals = no;
input showST_OBBreakoutSignals = no;
input showSTBreakoutSignals = no;

##LT CCI Line##
def cciclose = ADRdevT_lt * 100;
def price_lt = cciclose + lo + hi;
def linDev_lt = LinDev(price_lt, ccilength_lt);
plot CCI_lt = if linDev_lt == 0 then 0 else (price_lt - Average(price_lt, ccilength_lt)) / linDev_lt / 0.015;
CCI_lt.SetDefaultColor(Color.DARK_GREEN);
CCI_lt.SetStyle(Curve.LONG_DASH);
CCI_lt.SetLineWeight(3);
CCI_lt.SetHiding(!show_LT_CCI);

def cciclose_mt = ADRdevT_mt * 100;
def price_mt = cciclose_mt + lo + hi;
def linDev_mt = LinDev(price_mt, ccilength_mt);
plot CCI_mt = if linDev_mt == 0 then 0 else (price_mt - Average(price_mt, ccilength_mt)) / linDev_mt / 0.015;
CCI_mt.SetDefaultColor(Color.BLUE);
CCI_mt.SetStyle(Curve.MEDIUM_DASH);
CCI_mt.SetLineWeight(2);
CCI_mt.SetHiding(!show_MT_CCI);

def cciclose_st = ADRdevT_st * 100;
def price_st = cciclose_st + lo + hi;
def linDev_st = LinDev(price_st, ccilength_st);
plot CCI_st = if linDev_st == 0 then 0 else (price_st - Average(price_st, ccilength_st)) / linDev_st / 0.015;
CCI_st.SetDefaultColor(Color.RED);
CCI_st.SetStyle(Curve.FIRM);
CCI_st.SetLineWeight(2);
CCI_st.SetHiding(!show_ST_CCI);

########
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.BLACK);

plot OverBought = over_bought;
plot OverSold = over_sold;


#CCI_lt.SetDefaultColor(color.black);
#CCI_mt.SetDefaultColor(color.green);
#CCI_st.SetDefaultColor(color.red);

#ADRdevTema.AssignValueColor(
#    if ADRdevTema[0] >= zero and ADRdevTema[1] < zero then Color.GREEN
#    else if ADRdevTema[0] < zero and ADRdevTema[1] >= zero then Color.RED     
    
#else if ADRdevTema >= ADRdevTema[1] and ADRdevTema >= OverBought then Color.CYAN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= Overbought and ADRdevTema >= zero then #Color.GREEN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= zero and ADRdevTema > OverSold then #Color.Dark_GREEN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= OverSold then Color.Cyan


#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema >= Overbought then Color.ORANGE
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= OverBought and ADRdevTema >= zero then #Color.dark_red
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= zero and ADRdevTema > OverSold then #Color.red
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= Oversold then Color.Dark_Orange
#    else Color.GRAY);
#ADRdevTema.SetLineWeight(3);

####################################################################################
#Create an smoothed MA on CCIs for signal
input show_avg_Signal = no;
input show_LT_Signal = no;
input show_MT_Signal = no;
input show_ST_Signal = no;
def avg_signallines = (CCI_st+CCI_mt+CCI_lt)/3;

#LT#
input lt_Signal_length = 2;
plot lt_Signal = Average(CCI_lt, lt_Signal_length);
lt_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
lt_Signal.SetDefaultColor(Color.BLACK);
lt_Signal.SetLineWeight(2);
lt_Signal.SetHiding(!show_LT_Signal);


#MT#
input mt_Signal_length = 2;
plot mt_Signal = Average(CCI_mt, mt_Signal_length);
mt_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
mt_Signal.SetDefaultColor(Color.GREEN);
mt_Signal.SetLineWeight(2);
mt_Signal.SetHiding(!show_MT_Signal);


#ST#
input st_Signal_length = 2;
plot st_Signal = Average(CCI_st, lt_Signal_length);
st_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
st_Signal.SetDefaultColor(Color.RED);
st_Signal.SetLineWeight(2);
st_Signal.SetHiding(!show_ST_Signal);

#Create an combined Signal MA
input avg_Signal_length = 2;
plot avg_Signal = Average(avg_signallines, avg_Signal_length);
avg_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
avg_Signal.SetDefaultColor(Color.black);
avg_Signal.SetLineWeight(3);
avg_Signal.SetHiding(!show_Avg_Signal);

####################################################################################


#Data#
def lt_overOS125 = ((CCI_lt[1] < "-125") and CCI_lt >= "-125");
def lt_overOS125lb = ((CCI_lt[2] < "-125") and CCI_lt[1] >= "-125");
def mt_overOS125 = ((CCI_mt[1] < "-125") and CCI_mt >= "-125");
def mt_overOS125lb = ((CCI_mt[2] < "-125") and CCI_mt[1] >= "-125");
def st_overOS125 = ((CCI_st[1] < "-125") and CCI_st > "-125");
def st_overOS125lb = ((CCI_st[2] < "-125") and CCI_st[1] >= "-125");

def lt_underOB125 = ((CCI_lt[1] >= "+125") and CCI_lt < "+125");
def mt_underOB125 = ((CCI_mt[1] >= "+125") and CCI_mt < "+125");
def st_underOB125 = ((CCI_st[1] >= "+125") and CCI_st < "+125");

def OSlb_lt = (CCI_lt[1] <= OverSold) and (CCI_lt > OverSold);
def OBlb_lt = (CCI_lt[1] >= OverBought) and (CCI_lt < OverBought);
def lowlb_lt = (CCI_lt[1] <= -50) and (CCI_lt > -50);
def highlb_lt = (CCI_lt[1] >= 50) and (CCI_lt < 50);
def xozerolb_lt = (CCI_lt[1] <= -20) and (CCI_lt > -20);
def xuzerolb_lt = (CCI_lt[1] >= 20) and (CCI_lt < 20);

def OSlb_mt = (CCI_mt[1] <= OverSold) and (CCI_mt > OverSold);
def OBlb_mt = (CCI_mt[1] >= OverBought) and (CCI_mt < OverBought);
def lowlb_mt = (CCI_mt[1] <= -50) and (CCI_mt > -50);
def highlb_mt = (CCI_mt[1] >= 50) and (CCI_mt < 50);
def xozerolb_mt = (CCI_mt[1] <= -20) and (CCI_mt > -20);
def xuzerolb_mt = (CCI_mt[1] >= 20) and (CCI_mt < 20);

def OSlb_st = (CCI_st[1] <= OverSold) and (CCI_st > OverSold);
def OBlb_st = (CCI_st[1] >= OverBought) and (CCI_st < OverBought);
def lowlb_st = (CCI_st[1] <= -50) and (CCI_st > -50);
def highlb_st = (CCI_st[1] >= 50) and (CCI_st < 50);
def xozerolb_st = (CCI_st[1] <= -20) and (CCI_st > -20);
def xuzerolb_st = (CCI_st[1] >= 20) and (CCI_st < 20);



#Lower Study Arrows Off by Default#
plot UpSignalOS_lt = if !lt_overOS125[1] and lt_overOS125 then CCI_Lt
        else double.nan;
plot UpSignal_lt = if !UpSignalOS_lt[1] and (OSlb_lt and !OSlb_lt[1]) then CCI_Lt
        else Double.NaN;

plot DownSignalOB_lt = if !lt_underOB125[1] and lt_underOB125 then CCI_Lt
        else double.nan;
plot DownSignal_lt = if ShowLTBreakoutSignals and ShowLT_OBBreakoutSignals and (OBlb_lt and !OBlb_lt[1]) and !DownSignalOB_lt[1] then CCI_Lt
        else Double.NaN;


plot UpSignalOS_mt = if !mt_overOS125[1] and mt_overOS125 then (CCI_mt)
        else double.nan;
plot UpSignal_mt = if !UpSignalOS_mt[1] and (OSlb_mt and !OSlb_mt[1]) then CCI_mt
        else Double.NaN;

plot DownSignalOB_mt = if !mt_underOB125[1] and mt_underOB125 then CCI_mt
        else double.nan;
plot DownSignal_mt = if (OBlb_mt and !OBlb_mt[1]) then CCI_mt
        else Double.NaN;


plot UpSignalOS_st = if !st_overOS125[1] and st_overOS125 then CCI_st
        else double.nan;
plot UpSignal_st = if (OSlb_st and !OSlb_st[1]) then CCI_st
        else Double.NaN;

plot DownSignalOB_st = if !st_underOB125[1] and st_underOB125 then CCI_st
        else double.nan;
plot DownSignal_st = if (OBlb_st and !OBlb_st[1]) then CCI_st
        else Double.NaN;


UpSignalOS_lt.SetHiding(!showLT_OSBreakoutSignals);
DownSignalOB_lt.SetHiding(!showLT_OBBreakoutSignals);
UpSignal_lt.SetHiding(!showLTBreakoutSignals);
DownSignal_lt.SetHiding(!showLTBreakoutSignals);

UpSignalOS_mt.SetHiding(!showMT_OSBreakoutSignals);
DownSignalOB_mt.SetHiding(!showMT_OBBreakoutSignals);
UpSignal_mt.SetHiding(!showMTBreakoutSignals);
DownSignal_mt.SetHiding(!showMTBreakoutSignals);

UpSignalOS_st.SetHiding(!showST_OSBreakoutSignals);
DownSignalOB_st.SetHiding(!showST_OBBreakoutSignals);
UpSignal_st.SetHiding(!showSTBreakoutSignals);
DownSignal_st.SetHiding(!showSTBreakoutSignals);

UpSignalOS_lt.SetDefaultColor(Color.black);
UpSignalOS_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_lt.SetLineWeight(3);

DownSignalOB_lt.SetDefaultColor(Color.black);
DownSignalOB_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_lt.SetLineWeight(3);

UpSignal_lt.SetDefaultColor(Color.black);
UpSignal_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_lt.SetDefaultColor(Color.black);
DownSignal_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

UpSignalOS_mt.SetDefaultColor(Color.BLUE);
UpSignalOS_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_mt.SetLineWeight(3);
DownSignalOB_mt.SetDefaultColor(Color.BLUE);
DownSignalOB_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_mt.SetLineWeight(3);

UpSignal_mt.SetDefaultColor(Color.BLUE);
UpSignal_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_mt.SetDefaultColor(Color.BLUE);
DownSignal_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


UpSignalOS_st.SetDefaultColor(Color.RED);
UpSignalOS_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_st.SetLineWeight(3);
DownSignalOB_st.SetDefaultColor(Color.RED);
DownSignalOB_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_st.SetLineWeight(3);

UpSignal_st.SetDefaultColor(Color.RED);
UpSignal_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_st.SetDefaultColor(Color.RED);
DownSignal_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#####################################################
#Clouds#
#Avg_Signal Cloud
AddCloud(Avg_Signal, (-100), Color.green, Color.red);

#ST - LT CCI diff Cloud to Visualize Security Momentum
#AddCloud(CCI_st, avg_signal, Color.green, Color.red);

#Clouds for OB/OS#
OverBought.SetDefaultColor(GetColor(7));
#AddCloud(OverBought, CCI_lt, Color.white, Color.light_gray);
#AddCloud(OverBought, CCI_mt, Color.white, Color.light_gray);
#AddCloud(OverBought, CCI_st, Color.white, Color.light_gray);
OverSold.SetDefaultColor(GetColor(7));
#AddCloud(OverSold,  CCI_lt, Color.light_gray, Color.white);
#AddCloud(OverSold,  CCI_mt, Color.light_gray, Color.white);
#AddCloud(OverSold,  CCI_st, Color.light_gray, Color.white);

######################################################
#LT, MT, ST CCI Highlights

CCI_LT.AssignValueColor(if CCI_LT >=50 and CCI_LT >= CCI_LT[1] and CCI_MT >= CCI_MT[1] then color.green
        else if CCI_LT <=-50 and CCI_MT <= CCI_MT[1] then color.orange
        else color.dark_green);

####################################################################################
 
Solution
I'm making an ADR CCI study, and am really just putting finishing touches on. I have a lower and upper study, and the upper study is supposed to show arrows on price, but there are too many, and I want the code to turn off arrows that are 1 bar after an arrow signal that already fired. I've been able to accomplish this with past studies and I'm not sure where I'm going wrong. The piece of code I'm looking at is immediately below, and I've included the whole study below that for reference. Can someone please help me?

#Lower Study Arrows Off by Default#
plot UpSignalOS_lt = if !lt_overOS125[1] and lt_overOS125 then CCI_Lt
else double.nan;
plot UpSignal_lt = if !UpSignalOS_lt[1] and (OSlb_lt and !OSlb_lt[1]) then...
I'm making an ADR CCI study, and am really just putting finishing touches on. I have a lower and upper study, and the upper study is supposed to show arrows on price, but there are too many, and I want the code to turn off arrows that are 1 bar after an arrow signal that already fired. I've been able to accomplish this with past studies and I'm not sure where I'm going wrong. The piece of code I'm looking at is immediately below, and I've included the whole study below that for reference. Can someone please help me?

#Lower Study Arrows Off by Default#
plot UpSignalOS_lt = if !lt_overOS125[1] and lt_overOS125 then CCI_Lt
else double.nan;
plot UpSignal_lt = if !UpSignalOS_lt[1] and (OSlb_lt and !OSlb_lt[1]) then CCI_Lt
else Double.NaN;

plot DownSignalOB_lt = if !lt_underOB125[1] and lt_underOB125 then CCI_Lt
else double.nan;
plot DownSignal_lt = if ShowLTBreakoutSignals and ShowLT_OBBreakoutSignals and (OBlb_lt and !OBlb_lt[1]) and !DownSignalOB_lt[1] then CCI_Lt
else Double.NaN;

Whole Code:
Ruby:
declare upper;



input length = 20;
input ShowATR = no;
input ShowADR = no;
input ShowADRpercent = no;
input ShowADRpercentReal = no;
input ShowADRdiff = no;


def agg = AggregationPeriod.DAY;
def Pd = close(period = agg);
def hi = high(period = AggregationPeriod.DAY);
def lo = low(period = AggregationPeriod.DAY);

plot ATR = MovingAverage(AverageType.WILDERS, TrueRange(hi, Pd, lo), length);
ATR.SetDefaultColor(Color.GRAY);
ATR.SetHiding(!ShowATR);

##AddLabel (yes, "ATR:" + Round((ATR / close) * 100, 3) + "%", Color.LIGHT_GRAY);


##AddLabel (yes, "ATR:" + round((ATR) , 3), Color.LIGHT_GRAY);


plot ADR = MovingAverage(AverageType.WILDERS, hi - lo, length);
ADR.SetDefaultColor(Color.BLACK);
ADR.SetHiding(!ShowADR);

plot ADRpercent = Round((ADR / Pd) * 100, 2);
ADRpercent.SetDefaultColor(Color.BLUE);
ADRpercent.SetLineWeight(1);
ADRpercent.SetHiding(!ShowADRpercent);


###"today %" higher than the " Avg %" DOES IT WORK??

def ADRover = (((Pd[0] - Pd[1]) / Pd[1]) * 100) > ADRpercent;
def ADRunder = (((Pd[0] - Pd[1]) / Pd[1]) * 100) < ADRpercent;

#AddCloud(ADRover, ADRunder, Color.GREEN, Color.RED);

def ADRpercentReal = ((Pd - Pd[1]) / Pd[1] * 100);

##############################################################################################
##############################################################################################
# def average of %ADR Raw compared to %ADR 20 day Average

def ADRpD = ADRpercentReal;
input ba_length = 2;
input ba_type =  AverageType.EXPONENTIAL;
def ba = MovingAverage(ba_type, ADRpD, ba_length);


def BaseAvg = ba;

##############################################################################################
####### Tema on 2 period EMA of %ADR Raw ##################################

input ADRdevT_length_lt = 68;
def ADRdevT_lt = TEMA(BaseAvg, ADRdevT_length_lt);

input ADRdevT_length_mt = 22;
def ADRdevT_mt = TEMA(BaseAvg, ADRdevT_length_mt);

input ADRdevT_length_st = 10;
def ADRdevT_st = TEMA(BaseAvg, ADRdevT_length_st);

#################################################################################################
###CCI Lengths ST, MT, LT###
input show_LT_CCI = yes;
input show_MT_CCI = yes;
input show_ST_CCI = yes;

input ccilength_lt = 51;
input ccilength_mt = 17;
input ccilength_st = 10;

input over_sold = -100;
input over_bought = 100;

def "-125" = -125;
#OBpos.SetDefaultColor(Color.DARK_GREEN);
#OBpos.SetStyle(Curve.FIRM);
#OBpos.SetLineWeight(2);

def "-145" = -145;
#lowpos.SetDefaultColor(Color.GREEN);
#lowpos.SetStyle(Curve.MEDIUM_DASH);
#lowpos.SetLineWeight(1);

def "+125" = 125;
#lowestpos.SetDefaultColor(Color.BLACK);
#lowestpos.SetStyle(Curve.POINTS);
#lowestpos.SetLineWeight(1);

def "+145" = 145;
#OSneg.SetDefaultColor(Color.DARK_RED);
#OSneg.SetStyle(Curve.FIRM);
#OSneg.SetLineWeight(2);

input showLT_OSBreakoutSignals = yes;
input showLT_OBBreakoutSignals = yes;
input showLTBreakoutSignals = yes;
input showMT_OSBreakoutSignals = no;
input showMT_OBBreakoutSignals = no;
input showMTBreakoutSignals = no;
input showST_OSBreakoutSignals = no;
input showST_OBBreakoutSignals = no;
input showSTBreakoutSignals = no;

##LT CCI Line##
def cciclose = ADRdevT_lt * 100;
def price_lt = cciclose + lo + hi;
def linDev_lt = LinDev(price_lt, ccilength_lt);
plot CCI_lt = if linDev_lt == 0 then 0 else (price_lt - Average(price_lt, ccilength_lt)) / linDev_lt / 0.015;
CCI_lt.SetDefaultColor(Color.DARK_GREEN);
CCI_lt.SetStyle(Curve.LONG_DASH);
CCI_lt.SetLineWeight(3);
CCI_lt.SetHiding(!show_LT_CCI);

def cciclose_mt = ADRdevT_mt * 100;
def price_mt = cciclose_mt + lo + hi;
def linDev_mt = LinDev(price_mt, ccilength_mt);
plot CCI_mt = if linDev_mt == 0 then 0 else (price_mt - Average(price_mt, ccilength_mt)) / linDev_mt / 0.015;
CCI_mt.SetDefaultColor(Color.BLUE);
CCI_mt.SetStyle(Curve.MEDIUM_DASH);
CCI_mt.SetLineWeight(2);
CCI_mt.SetHiding(!show_MT_CCI);

def cciclose_st = ADRdevT_st * 100;
def price_st = cciclose_st + lo + hi;
def linDev_st = LinDev(price_st, ccilength_st);
plot CCI_st = if linDev_st == 0 then 0 else (price_st - Average(price_st, ccilength_st)) / linDev_st / 0.015;
CCI_st.SetDefaultColor(Color.RED);
CCI_st.SetStyle(Curve.FIRM);
CCI_st.SetLineWeight(2);
CCI_st.SetHiding(!show_ST_CCI);

########
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.BLACK);

plot OverBought = over_bought;
plot OverSold = over_sold;


#CCI_lt.SetDefaultColor(color.black);
#CCI_mt.SetDefaultColor(color.green);
#CCI_st.SetDefaultColor(color.red);

#ADRdevTema.AssignValueColor(
#    if ADRdevTema[0] >= zero and ADRdevTema[1] < zero then Color.GREEN
#    else if ADRdevTema[0] < zero and ADRdevTema[1] >= zero then Color.RED    
   
#else if ADRdevTema >= ADRdevTema[1] and ADRdevTema >= OverBought then Color.CYAN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= Overbought and ADRdevTema >= zero then #Color.GREEN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= zero and ADRdevTema > OverSold then #Color.Dark_GREEN
#    else if ADRdevTema >= ADRdevTema[1] and ADRdevTema <= OverSold then Color.Cyan


#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema >= Overbought then Color.ORANGE
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= OverBought and ADRdevTema >= zero then #Color.dark_red
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= zero and ADRdevTema > OverSold then #Color.red
#    else if ADRdevTema <= ADRdevTema[1] and ADRdevTema <= Oversold then Color.Dark_Orange
#    else Color.GRAY);
#ADRdevTema.SetLineWeight(3);

####################################################################################
#Create an smoothed MA on CCIs for signal
input show_avg_Signal = no;
input show_LT_Signal = no;
input show_MT_Signal = no;
input show_ST_Signal = no;
def avg_signallines = (CCI_st+CCI_mt+CCI_lt)/3;

#LT#
input lt_Signal_length = 2;
plot lt_Signal = Average(CCI_lt, lt_Signal_length);
lt_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
lt_Signal.SetDefaultColor(Color.BLACK);
lt_Signal.SetLineWeight(2);
lt_Signal.SetHiding(!show_LT_Signal);


#MT#
input mt_Signal_length = 2;
plot mt_Signal = Average(CCI_mt, mt_Signal_length);
mt_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
mt_Signal.SetDefaultColor(Color.GREEN);
mt_Signal.SetLineWeight(2);
mt_Signal.SetHiding(!show_MT_Signal);


#ST#
input st_Signal_length = 2;
plot st_Signal = Average(CCI_st, lt_Signal_length);
st_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
st_Signal.SetDefaultColor(Color.RED);
st_Signal.SetLineWeight(2);
st_Signal.SetHiding(!show_ST_Signal);

#Create an combined Signal MA
input avg_Signal_length = 2;
plot avg_Signal = Average(avg_signallines, avg_Signal_length);
avg_Signal.SetPaintingStrategy(PaintingStrategy.LINE);
avg_Signal.SetDefaultColor(Color.black);
avg_Signal.SetLineWeight(3);
avg_Signal.SetHiding(!show_Avg_Signal);

####################################################################################


#Data#
def lt_overOS125 = ((CCI_lt[1] < "-125") and CCI_lt >= "-125");
def lt_overOS125lb = ((CCI_lt[2] < "-125") and CCI_lt[1] >= "-125");
def mt_overOS125 = ((CCI_mt[1] < "-125") and CCI_mt >= "-125");
def mt_overOS125lb = ((CCI_mt[2] < "-125") and CCI_mt[1] >= "-125");
def st_overOS125 = ((CCI_st[1] < "-125") and CCI_st > "-125");
def st_overOS125lb = ((CCI_st[2] < "-125") and CCI_st[1] >= "-125");

def lt_underOB125 = ((CCI_lt[1] >= "+125") and CCI_lt < "+125");
def mt_underOB125 = ((CCI_mt[1] >= "+125") and CCI_mt < "+125");
def st_underOB125 = ((CCI_st[1] >= "+125") and CCI_st < "+125");

def OSlb_lt = (CCI_lt[1] <= OverSold) and (CCI_lt > OverSold);
def OBlb_lt = (CCI_lt[1] >= OverBought) and (CCI_lt < OverBought);
def lowlb_lt = (CCI_lt[1] <= -50) and (CCI_lt > -50);
def highlb_lt = (CCI_lt[1] >= 50) and (CCI_lt < 50);
def xozerolb_lt = (CCI_lt[1] <= -20) and (CCI_lt > -20);
def xuzerolb_lt = (CCI_lt[1] >= 20) and (CCI_lt < 20);

def OSlb_mt = (CCI_mt[1] <= OverSold) and (CCI_mt > OverSold);
def OBlb_mt = (CCI_mt[1] >= OverBought) and (CCI_mt < OverBought);
def lowlb_mt = (CCI_mt[1] <= -50) and (CCI_mt > -50);
def highlb_mt = (CCI_mt[1] >= 50) and (CCI_mt < 50);
def xozerolb_mt = (CCI_mt[1] <= -20) and (CCI_mt > -20);
def xuzerolb_mt = (CCI_mt[1] >= 20) and (CCI_mt < 20);

def OSlb_st = (CCI_st[1] <= OverSold) and (CCI_st > OverSold);
def OBlb_st = (CCI_st[1] >= OverBought) and (CCI_st < OverBought);
def lowlb_st = (CCI_st[1] <= -50) and (CCI_st > -50);
def highlb_st = (CCI_st[1] >= 50) and (CCI_st < 50);
def xozerolb_st = (CCI_st[1] <= -20) and (CCI_st > -20);
def xuzerolb_st = (CCI_st[1] >= 20) and (CCI_st < 20);



#Lower Study Arrows Off by Default#
plot UpSignalOS_lt = if !lt_overOS125[1] and lt_overOS125 then CCI_Lt
        else double.nan;
plot UpSignal_lt = if !UpSignalOS_lt[1] and (OSlb_lt and !OSlb_lt[1]) then CCI_Lt
        else Double.NaN;

plot DownSignalOB_lt = if !lt_underOB125[1] and lt_underOB125 then CCI_Lt
        else double.nan;
plot DownSignal_lt = if ShowLTBreakoutSignals and ShowLT_OBBreakoutSignals and (OBlb_lt and !OBlb_lt[1]) and !DownSignalOB_lt[1] then CCI_Lt
        else Double.NaN;


plot UpSignalOS_mt = if !mt_overOS125[1] and mt_overOS125 then (CCI_mt)
        else double.nan;
plot UpSignal_mt = if !UpSignalOS_mt[1] and (OSlb_mt and !OSlb_mt[1]) then CCI_mt
        else Double.NaN;

plot DownSignalOB_mt = if !mt_underOB125[1] and mt_underOB125 then CCI_mt
        else double.nan;
plot DownSignal_mt = if (OBlb_mt and !OBlb_mt[1]) then CCI_mt
        else Double.NaN;


plot UpSignalOS_st = if !st_overOS125[1] and st_overOS125 then CCI_st
        else double.nan;
plot UpSignal_st = if (OSlb_st and !OSlb_st[1]) then CCI_st
        else Double.NaN;

plot DownSignalOB_st = if !st_underOB125[1] and st_underOB125 then CCI_st
        else double.nan;
plot DownSignal_st = if (OBlb_st and !OBlb_st[1]) then CCI_st
        else Double.NaN;


UpSignalOS_lt.SetHiding(!showLT_OSBreakoutSignals);
DownSignalOB_lt.SetHiding(!showLT_OBBreakoutSignals);
UpSignal_lt.SetHiding(!showLTBreakoutSignals);
DownSignal_lt.SetHiding(!showLTBreakoutSignals);

UpSignalOS_mt.SetHiding(!showMT_OSBreakoutSignals);
DownSignalOB_mt.SetHiding(!showMT_OBBreakoutSignals);
UpSignal_mt.SetHiding(!showMTBreakoutSignals);
DownSignal_mt.SetHiding(!showMTBreakoutSignals);

UpSignalOS_st.SetHiding(!showST_OSBreakoutSignals);
DownSignalOB_st.SetHiding(!showST_OBBreakoutSignals);
UpSignal_st.SetHiding(!showSTBreakoutSignals);
DownSignal_st.SetHiding(!showSTBreakoutSignals);

UpSignalOS_lt.SetDefaultColor(Color.black);
UpSignalOS_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_lt.SetLineWeight(3);

DownSignalOB_lt.SetDefaultColor(Color.black);
DownSignalOB_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_lt.SetLineWeight(3);

UpSignal_lt.SetDefaultColor(Color.black);
UpSignal_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_lt.SetDefaultColor(Color.black);
DownSignal_lt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

UpSignalOS_mt.SetDefaultColor(Color.BLUE);
UpSignalOS_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_mt.SetLineWeight(3);
DownSignalOB_mt.SetDefaultColor(Color.BLUE);
DownSignalOB_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_mt.SetLineWeight(3);

UpSignal_mt.SetDefaultColor(Color.BLUE);
UpSignal_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_mt.SetDefaultColor(Color.BLUE);
DownSignal_mt.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


UpSignalOS_st.SetDefaultColor(Color.RED);
UpSignalOS_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignalOS_st.SetLineWeight(3);
DownSignalOB_st.SetDefaultColor(Color.RED);
DownSignalOB_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignalOB_st.SetLineWeight(3);

UpSignal_st.SetDefaultColor(Color.RED);
UpSignal_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal_st.SetDefaultColor(Color.RED);
DownSignal_st.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#####################################################
#Clouds#
#Avg_Signal Cloud
AddCloud(Avg_Signal, (-100), Color.green, Color.red);

#ST - LT CCI diff Cloud to Visualize Security Momentum
#AddCloud(CCI_st, avg_signal, Color.green, Color.red);

#Clouds for OB/OS#
OverBought.SetDefaultColor(GetColor(7));
#AddCloud(OverBought, CCI_lt, Color.white, Color.light_gray);
#AddCloud(OverBought, CCI_mt, Color.white, Color.light_gray);
#AddCloud(OverBought, CCI_st, Color.white, Color.light_gray);
OverSold.SetDefaultColor(GetColor(7));
#AddCloud(OverSold,  CCI_lt, Color.light_gray, Color.white);
#AddCloud(OverSold,  CCI_mt, Color.light_gray, Color.white);
#AddCloud(OverSold,  CCI_st, Color.light_gray, Color.white);

######################################################
#LT, MT, ST CCI Highlights

CCI_LT.AssignValueColor(if CCI_LT >=50 and CCI_LT >= CCI_LT[1] and CCI_MT >= CCI_MT[1] then color.green
        else if CCI_LT <=-50 and CCI_MT <= CCI_MT[1] then color.orange
        else color.dark_green);

####################################################################################

if there is a condition you want to act on before other ones, put it first in an if-then.
your variable names are too similar and confusing, so i'll make a generic example.

if you don't want 2 arrows in a row, make the first condition check if the previous and current triggers are both true.

def trigger =
plot arrow1 = if (trigger and trigger[1]) then double.nan
else if trigger then .....
else double.nan;
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

To add to what @halcyonguy said, you can get rid of some arrows by looking for changes:
if your series looks like this (pseudocode for simplicity):
Code:
F, F, F, F, F, F, T, T, T, T, T, T, T, F, F, F, F, F
you look for places where the change happens.
Code:
changed = series[1] != series
which when applied to the first series of T/F looks like this:
Code:
X, F, F, F, F, F, T, F, F, F, F, F, F, T, F, F, F, F
if you use that series to plot arrows, you can see that it will only plot on the T values and you'll only have two arrows for when the initial series changed value.

It's a bit abstract, but I think you'll be able to apply the logic to you series of conditions.

hope that helps,
mashume
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
370 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top