Repaints Consecutive Candles | Multi Timeframe For ThinkOrSwim

Repaints

Lerning2Code

New member
great script for market timing reversals
HdGSq5X.png


Here is the original Tradingview code:
https://www.tradingview.com/script/rHyTRtIx-Consecutive-Candles-Multi-Timeframe/

The new ThinkOrSwim code can be found in the next post.
 
Last edited by a moderator:

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

https://www.tradingview.com/script/rHyTRtIx-Consecutive-Candles-Multi-Timeframe/

Please convert this for use in thinkscript, great script for market timing reversals
check below:

CSS:
#// Indicator for TOS
#// @Yatagarasu_
#indicator(Consecutive Candles | Multi Timeframe "CC • Yata",     overlay = true,      timeframe = "")
# Converted by Sam4Cok@Samer800    - 11/2024

input timeframe = AggregationPeriod.MIN;
input showCount = {"1 to 9", default "6 to 9", "7 to 9", "8 and 9", "Only 9", "None"}; # "Show"
input ShowStealth9 = no; #, title="Show Stealth 9"
input ShowSupportAndResistance = yes; #"Show Support and Resistance"
input mode    = {"Standard", "Aggressive",default "Both Mode"}; # "Mode"
input show1To13 = yes; #"Show 1 to 13 |"
input only13 = yes; #"Only 13 |"


def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
def lastBar = close(Period = tf) == close;
def showCD = show1To13;
def lastCN = only13;
def both = mode == mode."Both Mode";

def n19 = showCount == showCount."1 to 9";
def n69 = showCount == showCount."6 to 9";
def n79 = showCount == showCount."7 to 9";
def n89 = showCount == showCount."8 and 9";
def n99 = showCount == showCount."Only 9";

def sellSet = if close(period = tf) > close(period = tf)[4] then if sellSet[1] == 9 then 1 else sellSet[1] + 1 else 0;
def buySet  = if close(period = tf) < close(period = tf)[4] then if buySet[1] == 9  then 1 else buySet[1] + 1 else 0;

plot buySet1 = if n19 and buySet == 1 and lastBar then 1 else na;
plot buySet2 = if n19 and buySet == 2 and lastBar then 2 else na;
plot buySet3 = if n19 and buySet == 3 and lastBar then 3 else na;
plot buySet4 = if n19 and buySet == 4 and lastBar then 4 else na;
plot buySet5 = if n19 and buySet == 5 and lastBar then 5 else na;

plot sellSet1 = if n19 and sellSet == 1 and lastBar then 1 else na;
plot sellSet2 = if n19 and sellSet == 2 and lastBar then 2 else na;
plot sellSet3 = if n19 and sellSet == 3 and lastBar then 3 else na;
plot sellSet4 = if n19 and sellSet == 4 and lastBar then 4 else na;
plot sellSet5 = if n19 and sellSet == 5 and lastBar then 5 else na;

buySet1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet4.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet5.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

sellSet1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet4.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet5.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

buySet1.AssignValueColor(CreateColor(0, 100, 100));
buySet2.AssignValueColor(CreateColor(0, 139, 139));
buySet3.AssignValueColor(CreateColor(0, 178, 178));
buySet4.AssignValueColor(CreateColor(0, 217, 217));
buySet5.AssignValueColor(CreateColor(0, 255, 255));

sellSet1.AssignValueColor(CreateColor(100, 0, 100));
sellSet2.AssignValueColor(CreateColor(139, 0, 139));
sellSet3.AssignValueColor(CreateColor(178, 0, 178));
sellSet4.AssignValueColor(CreateColor(217, 0, 217));
sellSet5.AssignValueColor(CreateColor(255, 0, 255));

AddChartBubble((n19 or n69) and buySet == 6 and lastBar , low, "6", CreateColor(0, 139, 139), no);
AddChartBubble((n19 or n69 or n79) and buySet == 7 and lastBar, low, "7", CreateColor(0, 178, 178), no);
AddChartBubble((n19 or n69 or n79 or n89) and buySet == 8 and lastBar, low, "8", CreateColor(0, 217, 217), no);
AddChartBubble((n19 or n69 or n79 or n89 or n99) and buySet == 9 and lastBar, low, "9", CreateColor(0, 255, 255), no);

AddChartBubble((n19 or n69) and sellSet == 6 and lastBar, high, "6", CreateColor(139, 0, 139));
AddChartBubble((n19 or n69 or n79) and sellSet == 7 and lastBar, high, "7", CreateColor(178, 0, 178));
AddChartBubble((n19 or n69 or n79 or n89) and sellSet == 8 and lastBar, high, "8", CreateColor(217, 0, 217));
AddChartBubble((n19 or n69 or n79 or n89 or n99) and sellSet == 9 and lastBar, high, "9", CreateColor(255, 0, 255));

#--
def barBuy  = if buySet == 8 then 0 else barBuy[1] + 1;
def barSell = if sellSet == 8 then 0 else barSell[1] + 1;
def stealthBuy  = barBuy <= 1 and sellSet == 1;
def stealthSell = barSell <= 1 and buySet == 1;

AddChartBubble(ShowStealth9 and stealthBuy and lastBar, low, "S9", Color.GREEN, no);
AddChartBubble(ShowStealth9 and stealthSell and lastBar, high, "S9", Color.RED);

#// -----------------------------------
def highest9 = highest(high(period = tf), 9);
def lowest9  = lowest(low(period = tf), 9);
def highTrendLine = if buySet == 9 then highest9 else if close(period = tf) > highTrendLine[1] then 0 else highTrendLine[1];
def lowTrendLine  = if sellSet == 9 then lowest9 else if close(period = tf) < lowTrendLine[1]  then 0 else lowTrendLine[1];

plot Sup = if !last and ShowSupportAndResistance and lowTrendLine then lowTrendLine else na;   # "Support"
plot Res = if !last and ShowSupportAndResistance and highTrendLine then highTrendLine else na; # "Resistance"

Sup.SetPaintingStrategy(PaintingStrategy.DASHES);
Res.SetPaintingStrategy(PaintingStrategy.DASHES);
Sup.SetDefaultColor(Color.GREEN);
Res.SetDefaultColor(Color.RED);

#// -----------------------------------
def buyCounCC;
def buyCounCC8Close;
def isBuyCounCC = close(period = tf) < low(period = tf)[2];
def nonBuy13 = isBuyCounCC and AbsValue(buyCounCC[1]) == 12 and low(period = tf) > buyCounCC8Close[1];
    buyCounCC = if buySet == 9 then if isBuyCounCC then 1 else 0 else
                if sellSet == 9 or highTrendLine == 0 then 14 else
                if nonBuy13 then -12 else if isBuyCounCC then AbsValue(buyCounCC[1]) + 1 else -AbsValue(buyCounCC[1]);
def nonQBuy13 = nonBuy13 and buyCounCC == -12;
    buyCounCC8Close = if buyCounCC == 8 then close(period = tf) else buyCounCC8Close[1];

def sellCounCC;
def sellCounCC8Close;
def isSellCounCC = close(period = tf) > high(period = tf)[2];
def nonSell13    = isSellCounCC and AbsValue(sellCounCC[1]) == 12 and high(period = tf) < sellCounCC8Close[1];
    sellCounCC  = if sellSet == 9 then if isSellCounCC then 1 else 0 else
                  if buySet == 9 or lowTrendLine == 0 then 14 else
                  if nonSell13 then -12 else if isSellCounCC then AbsValue(sellCounCC[1]) + 1 else -AbsValue(sellCounCC[1]);
def nonQSell13  = nonSell13 and sellCounCC == -12;
sellCounCC8Close = if sellCounCC == 8 then close(period = tf) else sellCounCC8Close[1];

def isAggressiveBuy = low(period = tf) < low(period = tf)[2];
def aggressiveBuy = if buySet == 9 then if isAggressiveBuy then 1 else 0 else
                    if sellSet == 9 or highTrendLine == 0 then 14 else
                    if isAggressiveBuy then AbsValue(aggressiveBuy[1]) + 1 else -AbsValue(aggressiveBuy[1]);
def isAggressiveSell = high(period = tf) > high(period = tf)[2];
def aggressiveSell   = if sellSet == 9 then if isAggressiveSell then 1 else 0 else
                       if buySet == 9 or lowTrendLine == 0 then 14 else
                       if isAggressiveSell then AbsValue(aggressiveSell[1]) + 1 else -AbsValue(aggressiveSell[1]);

def showStandardCounCC   = mode == mode."Standard";
def showAggressiveCounCC = mode == mode."Aggressive";
def sellCounCCNumber;
def buyCounCCNumber;

Switch (mode) {
Case "Aggressive" :
    sellCounCCNumber = aggressiveSell;
    buyCounCCNumber = aggressiveBuy;
Default :
    sellCounCCNumber = sellCounCC;
    buyCounCCNumber = buyCounCC;
}

plot modeP = if showCD and !lastCN and nonQSell13 and showStandardCounCC and lastBar then high else na;
plot modeN = if showCD and !lastCN and nonQBuy13 and showStandardCounCC and lastBar then low else na;

modeP.SetDefaultColor(Color.RED);
modeN.SetDefaultColor(Color.GREEN);
modeP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
modeN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);


AddChartBubble(showCD and lastCN and sellCounCC == 13 and showStandardCounCC or showCD and lastCN and sellCounCC == 13 and showAggressiveCounCC and both and lastBar, high, "13", Color.ORANGE);
AddChartBubble(showCD and lastCN and aggressiveSell == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveSell == 13 and showStandardCounCC and both and lastBar, high, "a13", Color.ORANGE);

AddChartBubble(showCD and lastCN and buyCounCC == 13 and showStandardCounCC or showCD and lastCN and buyCounCC == 13 and showAggressiveCounCC and both and lastBar, low, "13", Color.BLUE, no);
AddChartBubble(showCD and lastCN and aggressiveBuy == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveBuy == 13 and showStandardCounCC and both and lastBar, low, "a13", Color.BLUE, no);


AddChartBubble(showCD and !lastCN and sellCounCCNumber == 1 and lastBar, high, "1", CreateColor(99, 99, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 2 and lastBar, high, "2", CreateColor(111, 111, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 3 and lastBar, high, "3", CreateColor(123, 123, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 4 and lastBar, high, "4", CreateColor(135, 135, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 5 and lastBar, high, "5", CreateColor(147, 147, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 6 and lastBar, high, "6", CreateColor(159, 159, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 7 and lastBar, high, "7", CreateColor(171, 171, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 8 and lastBar, high, "8", CreateColor(183, 183, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 9 and lastBar, high, "9", CreateColor(195, 195, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 10 and lastBar, high, "10", CreateColor(207, 207, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 11 and lastBar, high, "11", CreateColor(219, 219, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 12 and lastBar, high, "12", CreateColor(231, 231, 0));
AddChartBubble(showCD and !lastCN and sellCounCCNumber == 13 and lastBar, high, "13", CreateColor(255, 0, 0));

AddChartBubble(showCD and !lastCN and buyCounCCNumber == 1 and lastBar, low, "1", CreateColor(99, 99, 99), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 2 and lastBar, low, "2", CreateColor(111, 111, 111), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 3 and lastBar, low, "3", CreateColor(123, 123, 123), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 4 and lastBar, low, "4", CreateColor(135, 135, 135), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 5 and lastBar, low, "5", CreateColor(147, 147, 147), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 6 and lastBar, low, "6", CreateColor(159, 159, 159), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 7 and lastBar, low, "7", CreateColor(171, 171, 171), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 8 and lastBar, low, "8", CreateColor(183, 183, 183), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 9 and lastBar, low, "9", CreateColor(195, 195, 195), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 10 and lastBar, low, "10", CreateColor(207, 207, 207), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 11 and lastBar, low, "11", CreateColor(219, 219, 219), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 12 and lastBar, low, "12", CreateColor(231, 231, 231), no);
AddChartBubble(showCD and !lastCN and buyCounCCNumber == 13 and lastBar, low, "13", CreateColor(0, 255, 0), no);

#-- END of CODE
 
@samer800 Can these bubbles be converted to arrows ? These bubbles don’t show up in mobile app
check this if can help:

CSS:
#// Indicator for TOS
#// @Yatagarasu_
#indicator(Consecutive Candles | Multi Timeframe "CC • Yata",     overlay = true,      timeframe = "")
# Converted by Sam4Cok@Samer800    - 11/2024

input timeframe = AggregationPeriod.MIN;
input showCount = {"1 to 9", default "6 to 9", "7 to 9", "8 and 9", "Only 9", "None"}; # "Show"
input ShowStealth9 = no; #, title="Show Stealth 9"
input ShowSupportAndResistance = yes; #"Show Support and Resistance"
input mode    = {"Standard", "Aggressive",default "Both Mode"}; # "Mode"
input show1To13 = yes; #"Show 1 to 13 |"
input only13 = yes; #"Only 13 |"


def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
def lastBar = close(Period = tf) == close;
def showCD = show1To13;
def lastCN = only13;
def both = mode == mode."Both Mode";

def n19 = showCount == showCount."1 to 9";
def n69 = showCount == showCount."6 to 9";
def n79 = showCount == showCount."7 to 9";
def n89 = showCount == showCount."8 and 9";
def n99 = showCount == showCount."Only 9";

def sellSet = if close(period = tf) > close(period = tf)[4] then if sellSet[1] == 9 then 1 else sellSet[1] + 1 else 0;
def buySet  = if close(period = tf) < close(period = tf)[4] then if buySet[1] == 9  then 1 else buySet[1] + 1 else 0;

plot buySet1 = if n19 and buySet == 1 and lastBar then 1 else na;
plot buySet2 = if n19 and buySet == 2 and lastBar then 2 else na;
plot buySet3 = if n19 and buySet == 3 and lastBar then 3 else na;
plot buySet4 = if n19 and buySet == 4 and lastBar then 4 else na;
plot buySet5 = if n19 and buySet == 5 and lastBar then 5 else na;
plot buySet6 = if (n19 or n69) and buySet == 6 and lastBar then buySet else na;
plot buySet7 = if (n19 or n69 or n79) and buySet == 7 and lastBar then buySet else na;
plot buySet8 = if (n19 or n69 or n79 or n89) and buySet == 8 and lastBar then buySet else na;
plot buySet9 = if (n19 or n69 or n79 or n89 or n99) and buySet == 9 and lastBar then buySet else na;

plot sellSet1 = if n19 and sellSet == 1 and lastBar then 1 else na;
plot sellSet2 = if n19 and sellSet == 2 and lastBar then 2 else na;
plot sellSet3 = if n19 and sellSet == 3 and lastBar then 3 else na;
plot sellSet4 = if n19 and sellSet == 4 and lastBar then 4 else na;
plot sellSet5 = if n19 and sellSet == 5 and lastBar then 5 else na;
plot sellSet6 = if (n19 or n69) and sellSet == 6 and lastBar then sellSet else na;
plot sellSet7 = if (n19 or n69 or n79) and sellSet == 7 and lastBar then sellSet else na;
plot sellSet8 = if (n19 or n69 or n79 or n89) and sellSet == 8 and lastBar then sellSet else na;
plot sellSet9 = if (n19 or n69 or n79 or n89 or n99) and sellSet == 9 and lastBar then sellSet else na;

buySet1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet4.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet5.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet6.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet7.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet8.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet9.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

sellSet1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet4.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet5.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet6.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet7.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet8.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet9.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

buySet1.AssignValueColor(CreateColor(0, 100, 100));
buySet2.AssignValueColor(CreateColor(0, 139, 139));
buySet3.AssignValueColor(CreateColor(0, 178, 178));
buySet4.AssignValueColor(CreateColor(0, 217, 217));
buySet5.AssignValueColor(CreateColor(0, 255, 255));
buySet6.AssignValueColor(CreateColor(0, 139, 139));
buySet7.AssignValueColor(CreateColor(0, 178, 178));
buySet8.AssignValueColor(CreateColor(0, 217, 217));
buySet9.AssignValueColor(CreateColor(0, 255, 255));

sellSet1.AssignValueColor(CreateColor(100, 0, 100));
sellSet2.AssignValueColor(CreateColor(139, 0, 139));
sellSet3.AssignValueColor(CreateColor(178, 0, 178));
sellSet4.AssignValueColor(CreateColor(217, 0, 217));
sellSet5.AssignValueColor(CreateColor(255, 0, 255));
sellSet6.AssignValueColor(CreateColor(139, 0, 139));
sellSet7.AssignValueColor(CreateColor(178, 0, 178));
sellSet8.AssignValueColor(CreateColor(217, 0, 217));
sellSet9.AssignValueColor(CreateColor(255, 0, 255));

#AddChartBubble((n19 or n69) and buySet == 6 and lastBar , low, "6", CreateColor(0, 139, 139), no);
#AddChartBubble((n19 or n69 or n79) and buySet == 7 and lastBar, low, "7", CreateColor(0, 178, 178), no);
#AddChartBubble((n19 or n69 or n79 or n89) and buySet == 8 and lastBar, low, "8", CreateColor(0, 217, 217), no);
#AddChartBubble((n19 or n69 or n79 or n89 or n99) and buySet == 9 and lastBar, low, "9", CreateColor(0, 255, 255), no);


#AddChartBubble((n19 or n69) and sellSet == 6 and lastBar, high, "6", CreateColor(139, 0, 139));
#AddChartBubble((n19 or n69 or n79) and sellSet == 7 and lastBar, high, "7", CreateColor(178, 0, 178));
#AddChartBubble((n19 or n69 or n79 or n89) and sellSet == 8 and lastBar, high, "8", CreateColor(217, 0, 217));
#AddChartBubble((n19 or n69 or n79 or n89 or n99) and sellSet == 9 and lastBar, high, "9", CreateColor(255, 0, 255));

#--
def barBuy  = if buySet == 8 then 0 else barBuy[1] + 1;
def barSell = if sellSet == 8 then 0 else barSell[1] + 1;
def stealthBuy  = barBuy <= 1 and sellSet == 1;
def stealthSell = barSell <= 1 and buySet == 1;

plot stealth9Buy = if ShowStealth9 and stealthBuy and lastBar then low else na;
plot stealth9Sell = if ShowStealth9 and stealthSell and lastBar then high else na;

stealth9Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
stealth9Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
stealth9Buy.SetDefaultColor(Color.GREEN);
stealth9Sell.SetDefaultColor(Color.RED);
#AddChartBubble(ShowStealth9 and stealthBuy and lastBar, low, "S9", Color.GREEN, no);
#AddChartBubble(ShowStealth9 and stealthSell and lastBar, high, "S9", Color.RED);

#// -----------------------------------
def highest9 = highest(high(period = tf), 9);
def lowest9  = lowest(low(period = tf), 9);
def highTrendLine = if buySet == 9 then highest9 else if close(period = tf) > highTrendLine[1] then 0 else highTrendLine[1];
def lowTrendLine  = if sellSet == 9 then lowest9 else if close(period = tf) < lowTrendLine[1]  then 0 else lowTrendLine[1];

plot Sup = if !last and ShowSupportAndResistance and lowTrendLine then lowTrendLine else na;   # "Support"
plot Res = if !last and ShowSupportAndResistance and highTrendLine then highTrendLine else na; # "Resistance"

Sup.SetPaintingStrategy(PaintingStrategy.DASHES);
Res.SetPaintingStrategy(PaintingStrategy.DASHES);
Sup.SetDefaultColor(Color.GREEN);
Res.SetDefaultColor(Color.RED);

#// -----------------------------------
def buyCounCC;
def buyCounCC8Close;
def isBuyCounCC = close(period = tf) < low(period = tf)[2];
def nonBuy13 = isBuyCounCC and AbsValue(buyCounCC[1]) == 12 and low(period = tf) > buyCounCC8Close[1];
    buyCounCC = if buySet == 9 then if isBuyCounCC then 1 else 0 else
                if sellSet == 9 or highTrendLine == 0 then 14 else
                if nonBuy13 then -12 else if isBuyCounCC then AbsValue(buyCounCC[1]) + 1 else -AbsValue(buyCounCC[1]);
def nonQBuy13 = nonBuy13 and buyCounCC == -12;
    buyCounCC8Close = if buyCounCC == 8 then close(period = tf) else buyCounCC8Close[1];

def sellCounCC;
def sellCounCC8Close;
def isSellCounCC = close(period = tf) > high(period = tf)[2];
def nonSell13    = isSellCounCC and AbsValue(sellCounCC[1]) == 12 and high(period = tf) < sellCounCC8Close[1];
    sellCounCC  = if sellSet == 9 then if isSellCounCC then 1 else 0 else
                  if buySet == 9 or lowTrendLine == 0 then 14 else
                  if nonSell13 then -12 else if isSellCounCC then AbsValue(sellCounCC[1]) + 1 else -AbsValue(sellCounCC[1]);
def nonQSell13  = nonSell13 and sellCounCC == -12;
sellCounCC8Close = if sellCounCC == 8 then close(period = tf) else sellCounCC8Close[1];

def isAggressiveBuy = low(period = tf) < low(period = tf)[2];
def aggressiveBuy = if buySet == 9 then if isAggressiveBuy then 1 else 0 else
                    if sellSet == 9 or highTrendLine == 0 then 14 else
                    if isAggressiveBuy then AbsValue(aggressiveBuy[1]) + 1 else -AbsValue(aggressiveBuy[1]);
def isAggressiveSell = high(period = tf) > high(period = tf)[2];
def aggressiveSell   = if sellSet == 9 then if isAggressiveSell then 1 else 0 else
                       if buySet == 9 or lowTrendLine == 0 then 14 else
                       if isAggressiveSell then AbsValue(aggressiveSell[1]) + 1 else -AbsValue(aggressiveSell[1]);

def showStandardCounCC   = mode == mode."Standard";
def showAggressiveCounCC = mode == mode."Aggressive";
def sellCounCCNumber;
def buyCounCCNumber;

Switch (mode) {
Case "Aggressive" :
    sellCounCCNumber = aggressiveSell;
    buyCounCCNumber = aggressiveBuy;
Default :
    sellCounCCNumber = sellCounCC;
    buyCounCCNumber = buyCounCC;
}

plot modeP = if showCD and !lastCN and nonQSell13 and showStandardCounCC and lastBar then high else na;
plot modeN = if showCD and !lastCN and nonQBuy13 and showStandardCounCC and lastBar then low else na;

modeP.SetDefaultColor(Color.RED);
modeN.SetDefaultColor(Color.GREEN);
modeP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
modeN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

plot buySet13 = if showCD and lastCN and buyCounCC == 13 and showStandardCounCC or showCD and lastCN and buyCounCC == 13 and showAggressiveCounCC and both and lastBar then low else na;
plot buySet13a = if showCD and lastCN and aggressiveBuy == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveBuy == 13 and showStandardCounCC and both and lastBar then low else na;

plot sellSet13 = if showCD and lastCN and sellCounCC == 13 and showStandardCounCC or showCD and lastCN and sellCounCC == 13 and showAggressiveCounCC and both and lastBar then high else na;
plot sellSet13a = if showCD and lastCN and aggressiveSell == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveSell == 13 and showStandardCounCC and both and lastBar then high else na;

buySet13a.SetLineWeight(2);
sellSet13a.SetLineWeight(2);
buySet13.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buySet13a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
sellSet13.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sellSet13a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

buySet13.SetDefaultColor(Color.BLUE);
buySet13a.SetDefaultColor(Color.VIOLET);
sellSet13.SetDefaultColor(Color.DARK_ORANGE);
sellSet13a.SetDefaultColor(Color.ORANGE);
#AddChartBubble(showCD and lastCN and sellCounCC == 13 and showStandardCounCC or showCD and lastCN and sellCounCC == 13 and showAggressiveCounCC and both and lastBar, high, "13", Color.ORANGE);
#AddChartBubble(showCD and lastCN and aggressiveSell == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveSell == 13 and showStandardCounCC and both and lastBar, high, "a13", Color.ORANGE);

#AddChartBubble(showCD and lastCN and buyCounCC == 13 and showStandardCounCC or showCD and lastCN and buyCounCC == 13 and showAggressiveCounCC and both and lastBar, low, "13", Color.BLUE, no);
#AddChartBubble(showCD and lastCN and aggressiveBuy == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveBuy == 13 and showStandardCounCC and both and lastBar, low, "a13", Color.BLUE, no);

plot buyCD1  = if showCD and !lastCN and buyCounCCNumber == 1 and lastBar then buyCounCCNumber else na;
plot buyCD2  = if showCD and !lastCN and buyCounCCNumber == 2 and lastBar then buyCounCCNumber else na;
plot buyCD3  = if showCD and !lastCN and buyCounCCNumber == 3 and lastBar then buyCounCCNumber else na;
plot buyCD4  = if showCD and !lastCN and buyCounCCNumber == 4 and lastBar then buyCounCCNumber else na;
plot buyCD5  = if showCD and !lastCN and buyCounCCNumber == 5 and lastBar then buyCounCCNumber else na;
plot buyCD6  = if showCD and !lastCN and buyCounCCNumber == 6 and lastBar then buyCounCCNumber else na;
plot buyCD7  = if showCD and !lastCN and buyCounCCNumber == 7 and lastBar then buyCounCCNumber else na;
plot buyCD8  = if showCD and !lastCN and buyCounCCNumber == 8 and lastBar then buyCounCCNumber else na;
plot buyCD9  = if showCD and !lastCN and buyCounCCNumber == 9 and lastBar then buyCounCCNumber else na;
plot buyCD10 = if showCD and !lastCN and buyCounCCNumber == 10 and lastBar then buyCounCCNumber else na;
plot buyCD11 = if showCD and !lastCN and buyCounCCNumber == 11 and lastBar then buyCounCCNumber else na;
plot buyCD12 = if showCD and !lastCN and buyCounCCNumber == 12 and lastBar then buyCounCCNumber else na;
plot buyCD13 = if showCD and !lastCN and buyCounCCNumber == 13 and lastBar then buyCounCCNumber else na;

plot sellCD1 = if showCD and !lastCN and sellCounCCNumber == 1 and lastBar then sellCounCCNumber else na;
plot sellCD2 = if showCD and !lastCN and sellCounCCNumber == 2 and lastBar then sellCounCCNumber else na;
plot sellCD3 = if showCD and !lastCN and sellCounCCNumber == 3 and lastBar then sellCounCCNumber else na;
plot sellCD4 = if showCD and !lastCN and sellCounCCNumber == 4 and lastBar then sellCounCCNumber else na;
plot sellCD5 = if showCD and !lastCN and sellCounCCNumber == 5 and lastBar then sellCounCCNumber else na;
plot sellCD6 = if showCD and !lastCN and sellCounCCNumber == 6 and lastBar then sellCounCCNumber else na;
plot sellCD7 = if showCD and !lastCN and sellCounCCNumber == 7 and lastBar then sellCounCCNumber else na;
plot sellCD8 = if showCD and !lastCN and sellCounCCNumber == 8 and lastBar then sellCounCCNumber else na;
plot sellCD9 = if showCD and !lastCN and sellCounCCNumber == 9 and lastBar then sellCounCCNumber else na;
plot sellCD10 = if showCD and !lastCN and sellCounCCNumber == 10 and lastBar then sellCounCCNumber else na;
plot sellCD11 = if showCD and !lastCN and sellCounCCNumber == 11 and lastBar then sellCounCCNumber else na;
plot sellCD12 = if showCD and !lastCN and sellCounCCNumber == 12 and lastBar then sellCounCCNumber else na;
plot sellCD13 = if showCD and !lastCN and sellCounCCNumber == 13 and lastBar then sellCounCCNumber else na;

buyCD1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD4.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD5.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD6.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD7.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD8.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD9.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD10.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD11.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD12.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD13.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

sellCD1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD4.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD5.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD6.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD7.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD8.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD9.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD10.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD11.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD12.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD13.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

buyCD1.SetDefaultColor(CreateColor(99, 99, 99));
buyCD2.SetDefaultColor(CreateColor(111, 111, 111));
buyCD3.SetDefaultColor(CreateColor(123, 123, 123));
buyCD4.SetDefaultColor(CreateColor(135, 135, 135));
buyCD5.SetDefaultColor(CreateColor(147, 147, 147));
buyCD6.SetDefaultColor(CreateColor(159, 159, 159));
buyCD7.SetDefaultColor(CreateColor(171, 171, 171));
buyCD8.SetDefaultColor(CreateColor(183, 183, 183));
buyCD9.SetDefaultColor(CreateColor(195, 195, 195));
buyCD10.SetDefaultColor(CreateColor(207, 207, 207));
buyCD11.SetDefaultColor(CreateColor(219, 219, 219));
buyCD12.SetDefaultColor(CreateColor(231, 231, 231));
buyCD13.SetDefaultColor(CreateColor(0, 255, 0));

sellCD1.SetDefaultColor(CreateColor(99, 99, 0));
sellCD2.SetDefaultColor(CreateColor(111, 111, 0));
sellCD3.SetDefaultColor(CreateColor(123, 123, 0));
sellCD4.SetDefaultColor(CreateColor(135, 135, 0));
sellCD5.SetDefaultColor(CreateColor(147, 147, 0));
sellCD6.SetDefaultColor(CreateColor(159, 159, 0));
sellCD7.SetDefaultColor(CreateColor(171, 171, 0));
sellCD8.SetDefaultColor(CreateColor(183, 183, 0));
sellCD9.SetDefaultColor(CreateColor(195, 195, 0));
sellCD10.SetDefaultColor(CreateColor(207, 207, 0));
sellCD11.SetDefaultColor(CreateColor(219, 219, 0));
sellCD12.SetDefaultColor(CreateColor(231, 231, 0));
sellCD13.SetDefaultColor(CreateColor(255, 0, 0));

#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 1 and lastBar, high, "1", CreateColor(99, 99, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 2 and lastBar, high, "2", CreateColor(111, 111, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 3 and lastBar, high, "3", CreateColor(123, 123, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 4 and lastBar, high, "4", CreateColor(135, 135, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 5 and lastBar, high, "5", CreateColor(147, 147, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 6 and lastBar, high, "6", CreateColor(159, 159, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 7 and lastBar, high, "7", CreateColor(171, 171, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 8 and lastBar, high, "8", CreateColor(183, 183, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 9 and lastBar, high, "9", CreateColor(195, 195, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 10 and lastBar, high, "10", CreateColor(207, 207, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 11 and lastBar, high, "11", CreateColor(219, 219, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 12 and lastBar, high, "12", CreateColor(231, 231, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 13 and lastBar, high, "13", CreateColor(255, 0, 0));

#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 1 and lastBar, low, "1", CreateColor(99, 99, 99), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 2 and lastBar, low, "2", CreateColor(111, 111, 111), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 3 and lastBar, low, "3", CreateColor(123, 123, 123), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 4 and lastBar, low, "4", CreateColor(135, 135, 135), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 5 and lastBar, low, "5", CreateColor(147, 147, 147), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 6 and lastBar, low, "6", CreateColor(159, 159, 159), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 7 and lastBar, low, "7", CreateColor(171, 171, 171), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 8 and lastBar, low, "8", CreateColor(183, 183, 183), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 9 and lastBar, low, "9", CreateColor(195, 195, 195), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 10 and lastBar, low, "10", CreateColor(207, 207, 207), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 11 and lastBar, low, "11", CreateColor(219, 219, 219), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 12 and lastBar, low, "12", CreateColor(231, 231, 231), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 13 and lastBar, low, "13", CreateColor(0, 255, 0), no);


#-- END of CODE
 
check this if can help:

CSS:
#// Indicator for TOS
#// @Yatagarasu_
#indicator(Consecutive Candles | Multi Timeframe "CC • Yata",     overlay = true,      timeframe = "")
# Converted by Sam4Cok@Samer800    - 11/2024

input timeframe = AggregationPeriod.MIN;
input showCount = {"1 to 9", default "6 to 9", "7 to 9", "8 and 9", "Only 9", "None"}; # "Show"
input ShowStealth9 = no; #, title="Show Stealth 9"
input ShowSupportAndResistance = yes; #"Show Support and Resistance"
input mode    = {"Standard", "Aggressive",default "Both Mode"}; # "Mode"
input show1To13 = yes; #"Show 1 to 13 |"
input only13 = yes; #"Only 13 |"


def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
def lastBar = close(Period = tf) == close;
def showCD = show1To13;
def lastCN = only13;
def both = mode == mode."Both Mode";

def n19 = showCount == showCount."1 to 9";
def n69 = showCount == showCount."6 to 9";
def n79 = showCount == showCount."7 to 9";
def n89 = showCount == showCount."8 and 9";
def n99 = showCount == showCount."Only 9";

def sellSet = if close(period = tf) > close(period = tf)[4] then if sellSet[1] == 9 then 1 else sellSet[1] + 1 else 0;
def buySet  = if close(period = tf) < close(period = tf)[4] then if buySet[1] == 9  then 1 else buySet[1] + 1 else 0;

plot buySet1 = if n19 and buySet == 1 and lastBar then 1 else na;
plot buySet2 = if n19 and buySet == 2 and lastBar then 2 else na;
plot buySet3 = if n19 and buySet == 3 and lastBar then 3 else na;
plot buySet4 = if n19 and buySet == 4 and lastBar then 4 else na;
plot buySet5 = if n19 and buySet == 5 and lastBar then 5 else na;
plot buySet6 = if (n19 or n69) and buySet == 6 and lastBar then buySet else na;
plot buySet7 = if (n19 or n69 or n79) and buySet == 7 and lastBar then buySet else na;
plot buySet8 = if (n19 or n69 or n79 or n89) and buySet == 8 and lastBar then buySet else na;
plot buySet9 = if (n19 or n69 or n79 or n89 or n99) and buySet == 9 and lastBar then buySet else na;

plot sellSet1 = if n19 and sellSet == 1 and lastBar then 1 else na;
plot sellSet2 = if n19 and sellSet == 2 and lastBar then 2 else na;
plot sellSet3 = if n19 and sellSet == 3 and lastBar then 3 else na;
plot sellSet4 = if n19 and sellSet == 4 and lastBar then 4 else na;
plot sellSet5 = if n19 and sellSet == 5 and lastBar then 5 else na;
plot sellSet6 = if (n19 or n69) and sellSet == 6 and lastBar then sellSet else na;
plot sellSet7 = if (n19 or n69 or n79) and sellSet == 7 and lastBar then sellSet else na;
plot sellSet8 = if (n19 or n69 or n79 or n89) and sellSet == 8 and lastBar then sellSet else na;
plot sellSet9 = if (n19 or n69 or n79 or n89 or n99) and sellSet == 9 and lastBar then sellSet else na;

buySet1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet4.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet5.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet6.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet7.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet8.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buySet9.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

sellSet1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet4.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet5.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet6.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet7.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet8.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellSet9.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

buySet1.AssignValueColor(CreateColor(0, 100, 100));
buySet2.AssignValueColor(CreateColor(0, 139, 139));
buySet3.AssignValueColor(CreateColor(0, 178, 178));
buySet4.AssignValueColor(CreateColor(0, 217, 217));
buySet5.AssignValueColor(CreateColor(0, 255, 255));
buySet6.AssignValueColor(CreateColor(0, 139, 139));
buySet7.AssignValueColor(CreateColor(0, 178, 178));
buySet8.AssignValueColor(CreateColor(0, 217, 217));
buySet9.AssignValueColor(CreateColor(0, 255, 255));

sellSet1.AssignValueColor(CreateColor(100, 0, 100));
sellSet2.AssignValueColor(CreateColor(139, 0, 139));
sellSet3.AssignValueColor(CreateColor(178, 0, 178));
sellSet4.AssignValueColor(CreateColor(217, 0, 217));
sellSet5.AssignValueColor(CreateColor(255, 0, 255));
sellSet6.AssignValueColor(CreateColor(139, 0, 139));
sellSet7.AssignValueColor(CreateColor(178, 0, 178));
sellSet8.AssignValueColor(CreateColor(217, 0, 217));
sellSet9.AssignValueColor(CreateColor(255, 0, 255));

#AddChartBubble((n19 or n69) and buySet == 6 and lastBar , low, "6", CreateColor(0, 139, 139), no);
#AddChartBubble((n19 or n69 or n79) and buySet == 7 and lastBar, low, "7", CreateColor(0, 178, 178), no);
#AddChartBubble((n19 or n69 or n79 or n89) and buySet == 8 and lastBar, low, "8", CreateColor(0, 217, 217), no);
#AddChartBubble((n19 or n69 or n79 or n89 or n99) and buySet == 9 and lastBar, low, "9", CreateColor(0, 255, 255), no);


#AddChartBubble((n19 or n69) and sellSet == 6 and lastBar, high, "6", CreateColor(139, 0, 139));
#AddChartBubble((n19 or n69 or n79) and sellSet == 7 and lastBar, high, "7", CreateColor(178, 0, 178));
#AddChartBubble((n19 or n69 or n79 or n89) and sellSet == 8 and lastBar, high, "8", CreateColor(217, 0, 217));
#AddChartBubble((n19 or n69 or n79 or n89 or n99) and sellSet == 9 and lastBar, high, "9", CreateColor(255, 0, 255));

#--
def barBuy  = if buySet == 8 then 0 else barBuy[1] + 1;
def barSell = if sellSet == 8 then 0 else barSell[1] + 1;
def stealthBuy  = barBuy <= 1 and sellSet == 1;
def stealthSell = barSell <= 1 and buySet == 1;

plot stealth9Buy = if ShowStealth9 and stealthBuy and lastBar then low else na;
plot stealth9Sell = if ShowStealth9 and stealthSell and lastBar then high else na;

stealth9Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
stealth9Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
stealth9Buy.SetDefaultColor(Color.GREEN);
stealth9Sell.SetDefaultColor(Color.RED);
#AddChartBubble(ShowStealth9 and stealthBuy and lastBar, low, "S9", Color.GREEN, no);
#AddChartBubble(ShowStealth9 and stealthSell and lastBar, high, "S9", Color.RED);

#// -----------------------------------
def highest9 = highest(high(period = tf), 9);
def lowest9  = lowest(low(period = tf), 9);
def highTrendLine = if buySet == 9 then highest9 else if close(period = tf) > highTrendLine[1] then 0 else highTrendLine[1];
def lowTrendLine  = if sellSet == 9 then lowest9 else if close(period = tf) < lowTrendLine[1]  then 0 else lowTrendLine[1];

plot Sup = if !last and ShowSupportAndResistance and lowTrendLine then lowTrendLine else na;   # "Support"
plot Res = if !last and ShowSupportAndResistance and highTrendLine then highTrendLine else na; # "Resistance"

Sup.SetPaintingStrategy(PaintingStrategy.DASHES);
Res.SetPaintingStrategy(PaintingStrategy.DASHES);
Sup.SetDefaultColor(Color.GREEN);
Res.SetDefaultColor(Color.RED);

#// -----------------------------------
def buyCounCC;
def buyCounCC8Close;
def isBuyCounCC = close(period = tf) < low(period = tf)[2];
def nonBuy13 = isBuyCounCC and AbsValue(buyCounCC[1]) == 12 and low(period = tf) > buyCounCC8Close[1];
    buyCounCC = if buySet == 9 then if isBuyCounCC then 1 else 0 else
                if sellSet == 9 or highTrendLine == 0 then 14 else
                if nonBuy13 then -12 else if isBuyCounCC then AbsValue(buyCounCC[1]) + 1 else -AbsValue(buyCounCC[1]);
def nonQBuy13 = nonBuy13 and buyCounCC == -12;
    buyCounCC8Close = if buyCounCC == 8 then close(period = tf) else buyCounCC8Close[1];

def sellCounCC;
def sellCounCC8Close;
def isSellCounCC = close(period = tf) > high(period = tf)[2];
def nonSell13    = isSellCounCC and AbsValue(sellCounCC[1]) == 12 and high(period = tf) < sellCounCC8Close[1];
    sellCounCC  = if sellSet == 9 then if isSellCounCC then 1 else 0 else
                  if buySet == 9 or lowTrendLine == 0 then 14 else
                  if nonSell13 then -12 else if isSellCounCC then AbsValue(sellCounCC[1]) + 1 else -AbsValue(sellCounCC[1]);
def nonQSell13  = nonSell13 and sellCounCC == -12;
sellCounCC8Close = if sellCounCC == 8 then close(period = tf) else sellCounCC8Close[1];

def isAggressiveBuy = low(period = tf) < low(period = tf)[2];
def aggressiveBuy = if buySet == 9 then if isAggressiveBuy then 1 else 0 else
                    if sellSet == 9 or highTrendLine == 0 then 14 else
                    if isAggressiveBuy then AbsValue(aggressiveBuy[1]) + 1 else -AbsValue(aggressiveBuy[1]);
def isAggressiveSell = high(period = tf) > high(period = tf)[2];
def aggressiveSell   = if sellSet == 9 then if isAggressiveSell then 1 else 0 else
                       if buySet == 9 or lowTrendLine == 0 then 14 else
                       if isAggressiveSell then AbsValue(aggressiveSell[1]) + 1 else -AbsValue(aggressiveSell[1]);

def showStandardCounCC   = mode == mode."Standard";
def showAggressiveCounCC = mode == mode."Aggressive";
def sellCounCCNumber;
def buyCounCCNumber;

Switch (mode) {
Case "Aggressive" :
    sellCounCCNumber = aggressiveSell;
    buyCounCCNumber = aggressiveBuy;
Default :
    sellCounCCNumber = sellCounCC;
    buyCounCCNumber = buyCounCC;
}

plot modeP = if showCD and !lastCN and nonQSell13 and showStandardCounCC and lastBar then high else na;
plot modeN = if showCD and !lastCN and nonQBuy13 and showStandardCounCC and lastBar then low else na;

modeP.SetDefaultColor(Color.RED);
modeN.SetDefaultColor(Color.GREEN);
modeP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
modeN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

plot buySet13 = if showCD and lastCN and buyCounCC == 13 and showStandardCounCC or showCD and lastCN and buyCounCC == 13 and showAggressiveCounCC and both and lastBar then low else na;
plot buySet13a = if showCD and lastCN and aggressiveBuy == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveBuy == 13 and showStandardCounCC and both and lastBar then low else na;

plot sellSet13 = if showCD and lastCN and sellCounCC == 13 and showStandardCounCC or showCD and lastCN and sellCounCC == 13 and showAggressiveCounCC and both and lastBar then high else na;
plot sellSet13a = if showCD and lastCN and aggressiveSell == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveSell == 13 and showStandardCounCC and both and lastBar then high else na;

buySet13a.SetLineWeight(2);
sellSet13a.SetLineWeight(2);
buySet13.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buySet13a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
sellSet13.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sellSet13a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

buySet13.SetDefaultColor(Color.BLUE);
buySet13a.SetDefaultColor(Color.VIOLET);
sellSet13.SetDefaultColor(Color.DARK_ORANGE);
sellSet13a.SetDefaultColor(Color.ORANGE);
#AddChartBubble(showCD and lastCN and sellCounCC == 13 and showStandardCounCC or showCD and lastCN and sellCounCC == 13 and showAggressiveCounCC and both and lastBar, high, "13", Color.ORANGE);
#AddChartBubble(showCD and lastCN and aggressiveSell == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveSell == 13 and showStandardCounCC and both and lastBar, high, "a13", Color.ORANGE);

#AddChartBubble(showCD and lastCN and buyCounCC == 13 and showStandardCounCC or showCD and lastCN and buyCounCC == 13 and showAggressiveCounCC and both and lastBar, low, "13", Color.BLUE, no);
#AddChartBubble(showCD and lastCN and aggressiveBuy == 13 and showAggressiveCounCC or showCD and lastCN and aggressiveBuy == 13 and showStandardCounCC and both and lastBar, low, "a13", Color.BLUE, no);

plot buyCD1  = if showCD and !lastCN and buyCounCCNumber == 1 and lastBar then buyCounCCNumber else na;
plot buyCD2  = if showCD and !lastCN and buyCounCCNumber == 2 and lastBar then buyCounCCNumber else na;
plot buyCD3  = if showCD and !lastCN and buyCounCCNumber == 3 and lastBar then buyCounCCNumber else na;
plot buyCD4  = if showCD and !lastCN and buyCounCCNumber == 4 and lastBar then buyCounCCNumber else na;
plot buyCD5  = if showCD and !lastCN and buyCounCCNumber == 5 and lastBar then buyCounCCNumber else na;
plot buyCD6  = if showCD and !lastCN and buyCounCCNumber == 6 and lastBar then buyCounCCNumber else na;
plot buyCD7  = if showCD and !lastCN and buyCounCCNumber == 7 and lastBar then buyCounCCNumber else na;
plot buyCD8  = if showCD and !lastCN and buyCounCCNumber == 8 and lastBar then buyCounCCNumber else na;
plot buyCD9  = if showCD and !lastCN and buyCounCCNumber == 9 and lastBar then buyCounCCNumber else na;
plot buyCD10 = if showCD and !lastCN and buyCounCCNumber == 10 and lastBar then buyCounCCNumber else na;
plot buyCD11 = if showCD and !lastCN and buyCounCCNumber == 11 and lastBar then buyCounCCNumber else na;
plot buyCD12 = if showCD and !lastCN and buyCounCCNumber == 12 and lastBar then buyCounCCNumber else na;
plot buyCD13 = if showCD and !lastCN and buyCounCCNumber == 13 and lastBar then buyCounCCNumber else na;

plot sellCD1 = if showCD and !lastCN and sellCounCCNumber == 1 and lastBar then sellCounCCNumber else na;
plot sellCD2 = if showCD and !lastCN and sellCounCCNumber == 2 and lastBar then sellCounCCNumber else na;
plot sellCD3 = if showCD and !lastCN and sellCounCCNumber == 3 and lastBar then sellCounCCNumber else na;
plot sellCD4 = if showCD and !lastCN and sellCounCCNumber == 4 and lastBar then sellCounCCNumber else na;
plot sellCD5 = if showCD and !lastCN and sellCounCCNumber == 5 and lastBar then sellCounCCNumber else na;
plot sellCD6 = if showCD and !lastCN and sellCounCCNumber == 6 and lastBar then sellCounCCNumber else na;
plot sellCD7 = if showCD and !lastCN and sellCounCCNumber == 7 and lastBar then sellCounCCNumber else na;
plot sellCD8 = if showCD and !lastCN and sellCounCCNumber == 8 and lastBar then sellCounCCNumber else na;
plot sellCD9 = if showCD and !lastCN and sellCounCCNumber == 9 and lastBar then sellCounCCNumber else na;
plot sellCD10 = if showCD and !lastCN and sellCounCCNumber == 10 and lastBar then sellCounCCNumber else na;
plot sellCD11 = if showCD and !lastCN and sellCounCCNumber == 11 and lastBar then sellCounCCNumber else na;
plot sellCD12 = if showCD and !lastCN and sellCounCCNumber == 12 and lastBar then sellCounCCNumber else na;
plot sellCD13 = if showCD and !lastCN and sellCounCCNumber == 13 and lastBar then sellCounCCNumber else na;

buyCD1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD4.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD5.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD6.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD7.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD8.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD9.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD10.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD11.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD12.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
buyCD13.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

sellCD1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD4.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD5.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD6.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD7.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD8.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD9.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD10.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD11.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD12.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
sellCD13.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

buyCD1.SetDefaultColor(CreateColor(99, 99, 99));
buyCD2.SetDefaultColor(CreateColor(111, 111, 111));
buyCD3.SetDefaultColor(CreateColor(123, 123, 123));
buyCD4.SetDefaultColor(CreateColor(135, 135, 135));
buyCD5.SetDefaultColor(CreateColor(147, 147, 147));
buyCD6.SetDefaultColor(CreateColor(159, 159, 159));
buyCD7.SetDefaultColor(CreateColor(171, 171, 171));
buyCD8.SetDefaultColor(CreateColor(183, 183, 183));
buyCD9.SetDefaultColor(CreateColor(195, 195, 195));
buyCD10.SetDefaultColor(CreateColor(207, 207, 207));
buyCD11.SetDefaultColor(CreateColor(219, 219, 219));
buyCD12.SetDefaultColor(CreateColor(231, 231, 231));
buyCD13.SetDefaultColor(CreateColor(0, 255, 0));

sellCD1.SetDefaultColor(CreateColor(99, 99, 0));
sellCD2.SetDefaultColor(CreateColor(111, 111, 0));
sellCD3.SetDefaultColor(CreateColor(123, 123, 0));
sellCD4.SetDefaultColor(CreateColor(135, 135, 0));
sellCD5.SetDefaultColor(CreateColor(147, 147, 0));
sellCD6.SetDefaultColor(CreateColor(159, 159, 0));
sellCD7.SetDefaultColor(CreateColor(171, 171, 0));
sellCD8.SetDefaultColor(CreateColor(183, 183, 0));
sellCD9.SetDefaultColor(CreateColor(195, 195, 0));
sellCD10.SetDefaultColor(CreateColor(207, 207, 0));
sellCD11.SetDefaultColor(CreateColor(219, 219, 0));
sellCD12.SetDefaultColor(CreateColor(231, 231, 0));
sellCD13.SetDefaultColor(CreateColor(255, 0, 0));

#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 1 and lastBar, high, "1", CreateColor(99, 99, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 2 and lastBar, high, "2", CreateColor(111, 111, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 3 and lastBar, high, "3", CreateColor(123, 123, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 4 and lastBar, high, "4", CreateColor(135, 135, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 5 and lastBar, high, "5", CreateColor(147, 147, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 6 and lastBar, high, "6", CreateColor(159, 159, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 7 and lastBar, high, "7", CreateColor(171, 171, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 8 and lastBar, high, "8", CreateColor(183, 183, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 9 and lastBar, high, "9", CreateColor(195, 195, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 10 and lastBar, high, "10", CreateColor(207, 207, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 11 and lastBar, high, "11", CreateColor(219, 219, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 12 and lastBar, high, "12", CreateColor(231, 231, 0));
#AddChartBubble(showCD and !lastCN and sellCounCCNumber == 13 and lastBar, high, "13", CreateColor(255, 0, 0));

#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 1 and lastBar, low, "1", CreateColor(99, 99, 99), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 2 and lastBar, low, "2", CreateColor(111, 111, 111), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 3 and lastBar, low, "3", CreateColor(123, 123, 123), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 4 and lastBar, low, "4", CreateColor(135, 135, 135), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 5 and lastBar, low, "5", CreateColor(147, 147, 147), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 6 and lastBar, low, "6", CreateColor(159, 159, 159), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 7 and lastBar, low, "7", CreateColor(171, 171, 171), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 8 and lastBar, low, "8", CreateColor(183, 183, 183), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 9 and lastBar, low, "9", CreateColor(195, 195, 195), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 10 and lastBar, low, "10", CreateColor(207, 207, 207), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 11 and lastBar, low, "11", CreateColor(219, 219, 219), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 12 and lastBar, low, "12", CreateColor(231, 231, 231), no);
#AddChartBubble(showCD and !lastCN and buyCounCCNumber == 13 and lastBar, low, "13", CreateColor(0, 255, 0), no);


#-- END of CODE
Thanks @samer800 . Appreciated !!. But now when I try to scan these Buy and Sell signals, thinkorswim crashes. Is there a way to make scan work ?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
422 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