Repaints Scalping High Low Trading Tool For ThinkOrSwim

Repaints

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

pls test the below

CSS:
# // Original Author: JustUncleL
#study(title = "Scalping Swing Trading Tool R1-6 by JustUncleL", shorttitle = "SCALPSWING R1-6", overlay = true)
# Converted by Sam4Cok@Samer800    - 12/2023
input movAvgType = AverageType.EXPONENTIAL;
input source      = close;
input ShowPriceActionChannel = yes;        # "Show Price Action Channel (PAC)")
input colorBars   = yes;                   # "Show coloured Bars close relative on PAC")
input HighLowLength = 10;                  # "High Low PAC Length"
input showPriceActionSwingArrows = no;     # "Show PAC Swing Alerts"
input useMovAvg200Filter =  yes;           # "Filter PAC Alerts with 200ema"
input ShowMovAvg12Channel =  yes;
input ShowMovAvg36Channel =  yes;
input ShowPivotPoints  =  yes;
input ShowPivotLabels =  yes;
input ShowHhLlBubbles = no;
input ShowFractals_ =  yes;
input ShowFractalLevels = no;
input filterPristineFractals = no;        # "Filter for Pristine (Ideal) Fractals"

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(91,156,246));
DefineGlobalColor("dup", CreateColor(10, 79, 174));

def ShowPAC = if HighLowLength > 30 then if ShowMovAvg36Channel then no else ShowPriceActionChannel else
              if ShowMovAvg12Channel then no else ShowPriceActionChannel;
def ShowHHLL = if ShowPivotPoints then no else ShowHhLlBubbles;
def ShowFractals = if ShowPivotPoints then no else ShowFractals_;
#// Need Williams Filter for Pivots.
def filterBW = if ShowPivotPoints then yes else filterPristineFractals;

#/ --- SOURCES ---
def close_ = source;# //security(ticker, period, close,  barmerge.gaps_off, barmerge.lookahead_on)
def open_ = open;# //security(ticker, period, open, barmerge.gaps_off, barmerge.lookahead_on)
def high_ = high;# //security(ticker, period, high, barmerge.gaps_off, barmerge.lookahead_on)
def low_ = low;# //security(ticker, period, low, barmerge.gaps_off, barmerge.lookahead_on)
def exitClose = close_;# //UseHAexit ? security(heikinashi(tickerid), period, close) : close_
def exitOpen  = open_;# //UseHAexit ? security(heikinashi(tickerid), period, open)  : open_

#// --   Fractal Recognition Functions:  -----
script isRegularFractal {
    input mode = 1;
    input high_ = high;
    input low_ = low;
    def up = high_[5] < high_[4] and high_[4] < high_[3] and high_[3] > high_[2] and high_[2] > high_[1];
    def dn = low_[5] > low_[4] and low_[4] > low_[3] and low_[3] < low_[2] and low_[2] < low_[1];
    def RegFract = if mode == 1 then up else if mode == -1 then dn else no;
    plot out = RegFract;
}
script isBWFractal {
    input mode = 1;
    input high_ = high;
    input low_ = low;
    def up = high_[5] < high_[3] and high_[4] < high_[3] and high_[3] > high_[2] and high_[3] > high_[1];
    def dn = low_[5] > low_[3] and low_[4] > low_[3] and low_[3] < low_[2] and low_[3] < low_[1];
    def BWFract = if mode == 1 then up else if mode == -1 then dn else no;
    plot out = BWFract;
}
#/ MA Colour finder for EMA Ribbon plot.
script maColor {
    input maBase = close;
    input ma     = high;
    input maRef  = low;
    def maChange = ma - ma[1];
    def maColor = if maChange >= 0 and maBase > maRef then 2 else
                  if maChange < 0 and maBase > maRef then -1 else
                  if maChange <= 0 and maBase < maRef then -2 else
                  if maChange >= 0 and maBase < maRef then 1 else 0;
    plot out = maColor;
}

#// Price action channel
def pacC        = MovingAverage(movAvgType, close_, HighLowLength);
def pacL        = MovingAverage(movAvgType, low_, HighLowLength);
def pacU        = MovingAverage(movAvgType, high_, HighLowLength);

#// All other EMAs
def EMA05  = MovingAverage(movAvgType, close_, 05);
def EMA11  = MovingAverage(movAvgType, close_, 11);
def EMA12  = MovingAverage(movAvgType, close_, 12);
def EMA15  = MovingAverage(movAvgType, close_, 15);
def EMA18  = MovingAverage(movAvgType, close_, 18);
def EMA21  = MovingAverage(movAvgType, close_, 21);
def EMA24  = MovingAverage(movAvgType, close_, 24);
def EMA27  = MovingAverage(movAvgType, close_, 27);
def EMA30  = MovingAverage(movAvgType, close_, 30);
def EMA33  = MovingAverage(movAvgType, close_, 33);
def EMA36  = MovingAverage(movAvgType, close_, 36);
def EMA75  = MovingAverage(movAvgType, close_, 75);
def EMA89  = MovingAverage(movAvgType, close_, 89);
def EMA180 = MovingAverage(movAvgType, close_, 180);
def EMA200 = MovingAverage(movAvgType, close_, 200);
def EMA540 = MovingAverage(movAvgType, close_, 540);
def EMA633 = MovingAverage(movAvgType, close_, 633);

#// === PLOTTING ===
#// If selected, Plot the Price Action Channel (PAC) base on EMA high,low and close
plot L = if ShowPAC then pacL else na;#, color=gray, linewidth=1, title="High PAC EMA",transp=50)
plot U = if ShowPAC then pacU else na;#, color=gray, linewidth=1, title="Low PAC EMA",transp=50)
plot C = if ShowPAC then pacC else na;#, color=lime, linewidth=1, title="Close PAC EMA",transp=0)

AddCloud(L,U, Color.DARK_GRAY);#color=gray,transp=92,title="Fill HiLo PAC")

#// Colour bars according to the close position relative to the PAC selected.
def bColour = if close_>=pacU then 1 else if close_<=pacL then -1 else 0;
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bColour > 0 then Color.DARK_GREEN else
                 if bColour < 0 then Color.DARK_RED else Color.DARK_GRAY);    # "Bar Colours"

#// Draw the EMA12 ribbon
def ema05Line = if ShowMovAvg12Channel then EMA05 else na;#,  color=blue,linewidth=1,transp=92,title="EMA05")
def ema11Line = if ShowMovAvg12Channel then EMA11 else na;#,  color=blue,linewidth=1,transp=92,title="EMA11")

#ema05Line.SetDefaultColor(Color.BLUE);
#ema11Line.SetDefaultColor(Color.BLUE);
AddCloud(ema05Line,ema11Line, Color.DARK_GRAY, Color.DARK_GRAY);#color=blue,transp=92,title="Fill EMA5-12")

#// If this is the 1min Time Frame select 15* EMAs
def currentAgg = GetAggregationPeriod();
def isintraday = currentAgg < AggregationPeriod.DAY;
def interval = currentAgg == AggregationPeriod.MIN;
def emaFast   = if isintraday then if interval then EMA75 else EMA89 else EMA89;
def emaMedium = if isintraday then if interval then EMA180 else EMA200 else EMA200;
def emaSlow   = if isintraday then if interval then EMA540 else EMA633 else EMA633;

plot fastEMA = emaFast;#,  color=green,linewidth=3,transp=20,title="EMA fast")
plot medEMA = emaMedium;#, color=blue,linewidth=3,transp=20,title="EMA medium")
plot slowEMA = emaSlow;#, color=black,linewidth=3,transp=20,title="EMA slow")
fastEMA.SetDefaultColor(Color.GREEN);
medEMA.SetDefaultColor(Color.BLUE);
slowEMA.SetDefaultColor(Color.DARK_GRAY);

#/ Draw the EMA36 ribbon
def col1 = maColor(EMA12,EMA12,EMA36);#, style=line, title="MA12", linewidth=2,transp=20)
def col2 = maColor(EMA12,EMA15,EMA36);#, style=line, title="MA15", linewidth=1,transp=20)
def col3 = maColor(EMA12,EMA18,EMA36);#, style=line, title="MA18", linewidth=1,transp=20)
def col4 = maColor(EMA12,EMA21,EMA36);#, style=line, title="MA21", linewidth=1,transp=20)
def col5 = maColor(EMA12,EMA24,EMA36);#, style=line, title="MA24", linewidth=1,transp=20)
def col6 = maColor(EMA12,EMA27,EMA36);#, style=line, title="MA27", linewidth=1,transp=20)
def col7 = maColor(EMA12,EMA30,EMA36);#, style=line, title="MA30", linewidth=1,transp=20)
def col8 = maColor(EMA12,EMA33,EMA36);#, style=line, title="MA33", linewidth=1,transp=20)
def col9 = maColor(EMA12,EMA36,EMA36);#:red, style=line, title="MA36", linewidth=2,transp=20)

#/ Draw the EMA36 ribbon
plot MA12 = if ShowMovAvg36Channel then EMA12 else na;#  title="MA12", linewidth=2,transp=20)
plot MA15 = if ShowMovAvg36Channel then EMA15 else na;#, title="MA15", linewidth=1,transp=20)
plot MA18 = if ShowMovAvg36Channel then EMA18 else na;#, title="MA18", linewidth=1,transp=20)
plot MA21 = if ShowMovAvg36Channel then EMA21 else na;#, title="MA21", linewidth=1,transp=20)
plot MA24 = if ShowMovAvg36Channel then EMA24 else na;#, title="MA24", linewidth=1,transp=20)
plot MA27 = if ShowMovAvg36Channel then EMA27 else na;#, title="MA27", linewidth=1,transp=20)
plot MA30 = if ShowMovAvg36Channel then EMA30 else na;#, title="MA30", linewidth=1,transp=20)
plot MA33 = if ShowMovAvg36Channel then EMA33 else na;#, title="MA33", linewidth=1,transp=20)
plot MA36 = EMA36;#, color=ShowEMA36_Ribbon?maColor(EMA12,EMA36,EMA36):red, , title="MA36", linewidth=2,transp=20)

MA12.AssignValueColor(if col1==2 then GlobalColor("up") else
                      if col1==1 then GlobalColor("dup") else
                      if col1==-1 then Color.PLUM else
                      if col1==-2 then Color.MAGENTA else Color.GRAY);
MA15.AssignValueColor(if col2==2 then  GlobalColor("up") else
                      if col2==1 then GlobalColor("dup") else
                      if col2==-1 then Color.PLUM else
                      if col2==-2 then Color.MAGENTA else Color.GRAY);
MA18.AssignValueColor(if col3==2 then  GlobalColor("up") else
                      if col3==1 then  GlobalColor("dup") else
                      if col3==-1 then Color.PLUM else
                      if col3==-2 then Color.MAGENTA else Color.GRAY);
MA21.AssignValueColor(if col4==2 then  GlobalColor("up") else
                      if col4==1 then  GlobalColor("dup") else
                      if col4==-1 then Color.PLUM else
                      if col4==-2 then Color.MAGENTA else Color.GRAY);
MA24.AssignValueColor(if col5==2 then  GlobalColor("up") else
                      if col5==1 then GlobalColor("dup") else
                      if col5==-1 then Color.PLUM else
                      if col5==-2 then Color.MAGENTA else Color.GRAY);
MA27.AssignValueColor(if col6==2 then  GlobalColor("up") else
                      if col6==1 then  GlobalColor("dup") else
                      if col6==-1 then Color.PLUM else
                      if col6==-2 then Color.MAGENTA else Color.GRAY);
MA30.AssignValueColor(if col7==2 then  GlobalColor("up") else
                      if col7==1 then  GlobalColor("dup") else
                      if col7==-1 then Color.PLUM else
                      if col7==-2 then Color.MAGENTA else Color.GRAY);
MA33.AssignValueColor(if col8==2 then  GlobalColor("up") else
                      if col8==1 then  GlobalColor("dup") else
                      if col8==-1 then Color.PLUM else
                      if col8==-2 then Color.MAGENTA else Color.GRAY);
MA36.AssignValueColor(if ShowMovAvg36Channel then
                      if col9==2 then  GlobalColor("up") else
                      if col9==1 then  GlobalColor("dup") else
                      if col9==-1 then Color.PLUM else
                      if col9==-2 then Color.MAGENTA else Color.GRAY else Color.RED);

#//  ||---   Fractal Recognition:
def filteredtopf = if filterBW then isRegularFractal(1, high_, Low_) else isBWFractal(1, high_, Low_);
def filteredbotf = if filterBW then isRegularFractal(-1, high_, Low_) else isBWFractal(-1, high_, Low_);
def topf = filteredtopf;
def botf = filteredbotf;
plot fractTop = if ShowFractals then topf[-3] else na;#, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=red, offset=-3,transp=0)
plot fractBot = if ShowFractals then botf[-3] else na;#, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=lime, offset=-3,transp=0)
fractTop.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
fractBot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
fractTop.SetDefaultColor(Color.RED);
fractBot.SetDefaultColor(Color.GREEN);

def topfractals = if topf then high_[3] else topfractals[1];
def botfractals = if botf then low_[3] else botfractals[1];

def topfcolor = topfractals == topfractals[1];# then 0 else green
def botfcolor = botfractals == botfractals[1];# ? na : red

plot fractLvlTop = if ShowFractalLevels and topfcolor then topfractals else na;
plot fractLvlBot = if ShowFractalLevels and botfcolor then botfractals else na;
fractLvlTop.SetStyle(Curve.SHORT_DASH);
fractLvlBot.SetStyle(Curve.SHORT_DASH);
fractLvlTop.SetDefaultColor(Color.GREEN);
fractLvlBot.SetDefaultColor(Color.RED);

#//  ||---   Higher Highs, Lower Highs, Higher Lows, Lower Lows  ---
def hh0 = if topf then high_[3] else hh0[1];
def hh1 = if hh0!=hh0[1] then hh0[1] else hh1[1];
def hh2 = if hh1!=hh1[1] then hh1[1] else hh2[1];
def ll0 = if botf then low_[3] else ll0[1];
def ll1 = if ll0!=ll0[1] then ll0[1] else ll1[1];
def ll2 = if ll1!=ll1[1] then ll1[1] else ll2[1];

def higherhigh = if !topf then no else
                (hh1 < hh0 and (ShowPivotPoints or (hh2 < hh0)));
def lowerhigh = if !topf then no else
                (hh1 > hh0 and (ShowPivotPoints or (hh2 > hh0)));
def higherlow = if !botf then no else
                (ll1 < ll0 and (ShowPivotPoints or (ll2 < ll0)));
def lowerlow = if !botf then no else
                (ll1 > ll0 and (ShowPivotPoints or (ll2 > ll0)));

#// If selected show HH/LL on top/below candles.
AddChartBubble(ShowHHLL and higherhigh[-3], high, "HH", Color.RED);#style=shape.square, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and lowerhigh[-3], high, "LH", Color.DARK_RED);#style=shape.square, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and higherlow[-3], low, "HL", Color.DARK_GREEN, no);#style=shape.square, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and lowerlow[-3], low, "LL", Color.GREEN, no);#style=shape.square, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)

#// If selected display Pivot points
AddChartBubble(ShowPivotPoints and ShowPivotLabels and higherhigh[-3], high, "HH\nPVT", Color.RED);
plot hhPlus = if ShowPivotPoints and !ShowPivotLabels and higherhigh[-3] then high else na;
hhPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
hhPlus.SetDefaultColor(Color.RED);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and lowerhigh[-3], high, "LH\nPVT", Color.DARK_RED);
plot lhPlus = if ShowPivotPoints and !ShowPivotLabels and lowerhigh[-3] then high else na;
lhPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
lhPlus.SetDefaultColor(Color.DARK_RED);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and higherlow[-3], low, "PVT\nHL", Color.DARK_GREEN, no);
plot hlPlus = if ShowPivotPoints and !ShowPivotLabels and higherlow[-3] then low else na;
hlPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
hlPlus.SetDefaultColor(Color.DARK_GREEN);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and lowerlow[-3], low, "PVT\nLL", Color.GREEN, no);
plot llPlus = if ShowPivotPoints and !ShowPivotLabels and lowerlow[-3] then low else na;
llPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
llPlus.SetDefaultColor(Color.GREEN);
#//
#// Number candles on Pivot patterns.
plot hi1u = if ShowPivotPoints and filteredtopf[-5] then 1 else na;
plot hi2u = if ShowPivotPoints and filteredtopf[-4] then 2 else na;
plot hi2d = if ShowPivotPoints and filteredtopf[-2] then 2 else na;
plot hi1d = if ShowPivotPoints and filteredtopf[-1] then 1 else na;

plot lo1u = if ShowPivotPoints and filteredbotf[-5] then 1 else na;
plot lo2u = if ShowPivotPoints and filteredbotf[-4] then 2 else na;
plot lo2d = if ShowPivotPoints and filteredbotf[-2] then 2 else na;
plot lo1d = if ShowPivotPoints and filteredbotf[-1] then 1 else na;

hi1u.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi2u.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi2d.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi1d.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi1u.SetDefaultColor(Color.RED);
hi2u.SetDefaultColor(Color.RED);
hi2d.SetDefaultColor(Color.RED);
hi1d.SetDefaultColor(Color.RED);

lo1u.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo2u.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo2d.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo1d.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo1u.SetDefaultColor(Color.GREEN);
lo2u.SetDefaultColor(Color.GREEN);
lo2d.SetDefaultColor(Color.GREEN);
lo1d.SetDefaultColor(Color.GREEN);

#/ === ALERTS ===
#// Check for 1st Heikin Ashi Bar exit the PAC
def isup = exitClose>exitOpen and exitClose>pacU and exitClose[1]<pacU[1]
        and (!useMovAvg200Filter or pacC>emaMedium);
def isdn = exitClose<exitOpen and exitClose<pacL and exitClose[1]>pacL[1]
        and (!useMovAvg200Filter or pacC<emaMedium);

#// Check have alert
def up_alert = if isup then if !up_alert[1] then 1 else up_alert[1]+1 else 0;
def dn_alert = if isdn then if !dn_alert[1] then 1 else dn_alert[1]+1 else 0;
#//
plot ArrowUp = if showPriceActionSwingArrows and up_alert[1]==1 then low else na;
plot ArrowDn = if showPriceActionSwingArrows and dn_alert[1]==1 then high else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowDn.SetDefaultColor(Color.ORANGE);

#-- END of CODE
 
pls test the below

CSS:
# // Original Author: JustUncleL
#study(title = "Scalping Swing Trading Tool R1-6 by JustUncleL", shorttitle = "SCALPSWING R1-6", overlay = true)
# Converted by Sam4Cok@Samer800    - 12/2023
input movAvgType = AverageType.EXPONENTIAL;
input source      = close;
input ShowPriceActionChannel = yes;        # "Show Price Action Channel (PAC)")
input colorBars   = yes;                   # "Show coloured Bars close relative on PAC")
input HighLowLength = 10;                  # "High Low PAC Length"
input showPriceActionSwingArrows = no;     # "Show PAC Swing Alerts"
input useMovAvg200Filter =  yes;           # "Filter PAC Alerts with 200ema"
input ShowMovAvg12Channel =  yes;
input ShowMovAvg36Channel =  yes;
input ShowPivotPoints  =  yes;
input ShowPivotLabels =  yes;
input ShowHhLlBubbles = no;
input ShowFractals_ =  yes;
input ShowFractalLevels = no;
input filterPristineFractals = no;        # "Filter for Pristine (Ideal) Fractals"

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(91,156,246));
DefineGlobalColor("dup", CreateColor(10, 79, 174));

def ShowPAC = if HighLowLength > 30 then if ShowMovAvg36Channel then no else ShowPriceActionChannel else
              if ShowMovAvg12Channel then no else ShowPriceActionChannel;
def ShowHHLL = if ShowPivotPoints then no else ShowHhLlBubbles;
def ShowFractals = if ShowPivotPoints then no else ShowFractals_;
#// Need Williams Filter for Pivots.
def filterBW = if ShowPivotPoints then yes else filterPristineFractals;

#/ --- SOURCES ---
def close_ = source;# //security(ticker, period, close,  barmerge.gaps_off, barmerge.lookahead_on)
def open_ = open;# //security(ticker, period, open, barmerge.gaps_off, barmerge.lookahead_on)
def high_ = high;# //security(ticker, period, high, barmerge.gaps_off, barmerge.lookahead_on)
def low_ = low;# //security(ticker, period, low, barmerge.gaps_off, barmerge.lookahead_on)
def exitClose = close_;# //UseHAexit ? security(heikinashi(tickerid), period, close) : close_
def exitOpen  = open_;# //UseHAexit ? security(heikinashi(tickerid), period, open)  : open_

#// --   Fractal Recognition Functions:  -----
script isRegularFractal {
    input mode = 1;
    input high_ = high;
    input low_ = low;
    def up = high_[5] < high_[4] and high_[4] < high_[3] and high_[3] > high_[2] and high_[2] > high_[1];
    def dn = low_[5] > low_[4] and low_[4] > low_[3] and low_[3] < low_[2] and low_[2] < low_[1];
    def RegFract = if mode == 1 then up else if mode == -1 then dn else no;
    plot out = RegFract;
}
script isBWFractal {
    input mode = 1;
    input high_ = high;
    input low_ = low;
    def up = high_[5] < high_[3] and high_[4] < high_[3] and high_[3] > high_[2] and high_[3] > high_[1];
    def dn = low_[5] > low_[3] and low_[4] > low_[3] and low_[3] < low_[2] and low_[3] < low_[1];
    def BWFract = if mode == 1 then up else if mode == -1 then dn else no;
    plot out = BWFract;
}
#/ MA Colour finder for EMA Ribbon plot.
script maColor {
    input maBase = close;
    input ma     = high;
    input maRef  = low;
    def maChange = ma - ma[1];
    def maColor = if maChange >= 0 and maBase > maRef then 2 else
                  if maChange < 0 and maBase > maRef then -1 else
                  if maChange <= 0 and maBase < maRef then -2 else
                  if maChange >= 0 and maBase < maRef then 1 else 0;
    plot out = maColor;
}

#// Price action channel
def pacC        = MovingAverage(movAvgType, close_, HighLowLength);
def pacL        = MovingAverage(movAvgType, low_, HighLowLength);
def pacU        = MovingAverage(movAvgType, high_, HighLowLength);

#// All other EMAs
def EMA05  = MovingAverage(movAvgType, close_, 05);
def EMA11  = MovingAverage(movAvgType, close_, 11);
def EMA12  = MovingAverage(movAvgType, close_, 12);
def EMA15  = MovingAverage(movAvgType, close_, 15);
def EMA18  = MovingAverage(movAvgType, close_, 18);
def EMA21  = MovingAverage(movAvgType, close_, 21);
def EMA24  = MovingAverage(movAvgType, close_, 24);
def EMA27  = MovingAverage(movAvgType, close_, 27);
def EMA30  = MovingAverage(movAvgType, close_, 30);
def EMA33  = MovingAverage(movAvgType, close_, 33);
def EMA36  = MovingAverage(movAvgType, close_, 36);
def EMA75  = MovingAverage(movAvgType, close_, 75);
def EMA89  = MovingAverage(movAvgType, close_, 89);
def EMA180 = MovingAverage(movAvgType, close_, 180);
def EMA200 = MovingAverage(movAvgType, close_, 200);
def EMA540 = MovingAverage(movAvgType, close_, 540);
def EMA633 = MovingAverage(movAvgType, close_, 633);

#// === PLOTTING ===
#// If selected, Plot the Price Action Channel (PAC) base on EMA high,low and close
plot L = if ShowPAC then pacL else na;#, color=gray, linewidth=1, title="High PAC EMA",transp=50)
plot U = if ShowPAC then pacU else na;#, color=gray, linewidth=1, title="Low PAC EMA",transp=50)
plot C = if ShowPAC then pacC else na;#, color=lime, linewidth=1, title="Close PAC EMA",transp=0)

AddCloud(L,U, Color.DARK_GRAY);#color=gray,transp=92,title="Fill HiLo PAC")

#// Colour bars according to the close position relative to the PAC selected.
def bColour = if close_>=pacU then 1 else if close_<=pacL then -1 else 0;
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bColour > 0 then Color.DARK_GREEN else
                 if bColour < 0 then Color.DARK_RED else Color.DARK_GRAY);    # "Bar Colours"

#// Draw the EMA12 ribbon
def ema05Line = if ShowMovAvg12Channel then EMA05 else na;#,  color=blue,linewidth=1,transp=92,title="EMA05")
def ema11Line = if ShowMovAvg12Channel then EMA11 else na;#,  color=blue,linewidth=1,transp=92,title="EMA11")

#ema05Line.SetDefaultColor(Color.BLUE);
#ema11Line.SetDefaultColor(Color.BLUE);
AddCloud(ema05Line,ema11Line, Color.DARK_GRAY, Color.DARK_GRAY);#color=blue,transp=92,title="Fill EMA5-12")

#// If this is the 1min Time Frame select 15* EMAs
def currentAgg = GetAggregationPeriod();
def isintraday = currentAgg < AggregationPeriod.DAY;
def interval = currentAgg == AggregationPeriod.MIN;
def emaFast   = if isintraday then if interval then EMA75 else EMA89 else EMA89;
def emaMedium = if isintraday then if interval then EMA180 else EMA200 else EMA200;
def emaSlow   = if isintraday then if interval then EMA540 else EMA633 else EMA633;

plot fastEMA = emaFast;#,  color=green,linewidth=3,transp=20,title="EMA fast")
plot medEMA = emaMedium;#, color=blue,linewidth=3,transp=20,title="EMA medium")
plot slowEMA = emaSlow;#, color=black,linewidth=3,transp=20,title="EMA slow")
fastEMA.SetDefaultColor(Color.GREEN);
medEMA.SetDefaultColor(Color.BLUE);
slowEMA.SetDefaultColor(Color.DARK_GRAY);

#/ Draw the EMA36 ribbon
def col1 = maColor(EMA12,EMA12,EMA36);#, style=line, title="MA12", linewidth=2,transp=20)
def col2 = maColor(EMA12,EMA15,EMA36);#, style=line, title="MA15", linewidth=1,transp=20)
def col3 = maColor(EMA12,EMA18,EMA36);#, style=line, title="MA18", linewidth=1,transp=20)
def col4 = maColor(EMA12,EMA21,EMA36);#, style=line, title="MA21", linewidth=1,transp=20)
def col5 = maColor(EMA12,EMA24,EMA36);#, style=line, title="MA24", linewidth=1,transp=20)
def col6 = maColor(EMA12,EMA27,EMA36);#, style=line, title="MA27", linewidth=1,transp=20)
def col7 = maColor(EMA12,EMA30,EMA36);#, style=line, title="MA30", linewidth=1,transp=20)
def col8 = maColor(EMA12,EMA33,EMA36);#, style=line, title="MA33", linewidth=1,transp=20)
def col9 = maColor(EMA12,EMA36,EMA36);#:red, style=line, title="MA36", linewidth=2,transp=20)

#/ Draw the EMA36 ribbon
plot MA12 = if ShowMovAvg36Channel then EMA12 else na;#  title="MA12", linewidth=2,transp=20)
plot MA15 = if ShowMovAvg36Channel then EMA15 else na;#, title="MA15", linewidth=1,transp=20)
plot MA18 = if ShowMovAvg36Channel then EMA18 else na;#, title="MA18", linewidth=1,transp=20)
plot MA21 = if ShowMovAvg36Channel then EMA21 else na;#, title="MA21", linewidth=1,transp=20)
plot MA24 = if ShowMovAvg36Channel then EMA24 else na;#, title="MA24", linewidth=1,transp=20)
plot MA27 = if ShowMovAvg36Channel then EMA27 else na;#, title="MA27", linewidth=1,transp=20)
plot MA30 = if ShowMovAvg36Channel then EMA30 else na;#, title="MA30", linewidth=1,transp=20)
plot MA33 = if ShowMovAvg36Channel then EMA33 else na;#, title="MA33", linewidth=1,transp=20)
plot MA36 = EMA36;#, color=ShowEMA36_Ribbon?maColor(EMA12,EMA36,EMA36):red, , title="MA36", linewidth=2,transp=20)

MA12.AssignValueColor(if col1==2 then GlobalColor("up") else
                      if col1==1 then GlobalColor("dup") else
                      if col1==-1 then Color.PLUM else
                      if col1==-2 then Color.MAGENTA else Color.GRAY);
MA15.AssignValueColor(if col2==2 then  GlobalColor("up") else
                      if col2==1 then GlobalColor("dup") else
                      if col2==-1 then Color.PLUM else
                      if col2==-2 then Color.MAGENTA else Color.GRAY);
MA18.AssignValueColor(if col3==2 then  GlobalColor("up") else
                      if col3==1 then  GlobalColor("dup") else
                      if col3==-1 then Color.PLUM else
                      if col3==-2 then Color.MAGENTA else Color.GRAY);
MA21.AssignValueColor(if col4==2 then  GlobalColor("up") else
                      if col4==1 then  GlobalColor("dup") else
                      if col4==-1 then Color.PLUM else
                      if col4==-2 then Color.MAGENTA else Color.GRAY);
MA24.AssignValueColor(if col5==2 then  GlobalColor("up") else
                      if col5==1 then GlobalColor("dup") else
                      if col5==-1 then Color.PLUM else
                      if col5==-2 then Color.MAGENTA else Color.GRAY);
MA27.AssignValueColor(if col6==2 then  GlobalColor("up") else
                      if col6==1 then  GlobalColor("dup") else
                      if col6==-1 then Color.PLUM else
                      if col6==-2 then Color.MAGENTA else Color.GRAY);
MA30.AssignValueColor(if col7==2 then  GlobalColor("up") else
                      if col7==1 then  GlobalColor("dup") else
                      if col7==-1 then Color.PLUM else
                      if col7==-2 then Color.MAGENTA else Color.GRAY);
MA33.AssignValueColor(if col8==2 then  GlobalColor("up") else
                      if col8==1 then  GlobalColor("dup") else
                      if col8==-1 then Color.PLUM else
                      if col8==-2 then Color.MAGENTA else Color.GRAY);
MA36.AssignValueColor(if ShowMovAvg36Channel then
                      if col9==2 then  GlobalColor("up") else
                      if col9==1 then  GlobalColor("dup") else
                      if col9==-1 then Color.PLUM else
                      if col9==-2 then Color.MAGENTA else Color.GRAY else Color.RED);

#//  ||---   Fractal Recognition:
def filteredtopf = if filterBW then isRegularFractal(1, high_, Low_) else isBWFractal(1, high_, Low_);
def filteredbotf = if filterBW then isRegularFractal(-1, high_, Low_) else isBWFractal(-1, high_, Low_);
def topf = filteredtopf;
def botf = filteredbotf;
plot fractTop = if ShowFractals then topf[-3] else na;#, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=red, offset=-3,transp=0)
plot fractBot = if ShowFractals then botf[-3] else na;#, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=lime, offset=-3,transp=0)
fractTop.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
fractBot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
fractTop.SetDefaultColor(Color.RED);
fractBot.SetDefaultColor(Color.GREEN);

def topfractals = if topf then high_[3] else topfractals[1];
def botfractals = if botf then low_[3] else botfractals[1];

def topfcolor = topfractals == topfractals[1];# then 0 else green
def botfcolor = botfractals == botfractals[1];# ? na : red

plot fractLvlTop = if ShowFractalLevels and topfcolor then topfractals else na;
plot fractLvlBot = if ShowFractalLevels and botfcolor then botfractals else na;
fractLvlTop.SetStyle(Curve.SHORT_DASH);
fractLvlBot.SetStyle(Curve.SHORT_DASH);
fractLvlTop.SetDefaultColor(Color.GREEN);
fractLvlBot.SetDefaultColor(Color.RED);

#//  ||---   Higher Highs, Lower Highs, Higher Lows, Lower Lows  ---
def hh0 = if topf then high_[3] else hh0[1];
def hh1 = if hh0!=hh0[1] then hh0[1] else hh1[1];
def hh2 = if hh1!=hh1[1] then hh1[1] else hh2[1];
def ll0 = if botf then low_[3] else ll0[1];
def ll1 = if ll0!=ll0[1] then ll0[1] else ll1[1];
def ll2 = if ll1!=ll1[1] then ll1[1] else ll2[1];

def higherhigh = if !topf then no else
                (hh1 < hh0 and (ShowPivotPoints or (hh2 < hh0)));
def lowerhigh = if !topf then no else
                (hh1 > hh0 and (ShowPivotPoints or (hh2 > hh0)));
def higherlow = if !botf then no else
                (ll1 < ll0 and (ShowPivotPoints or (ll2 < ll0)));
def lowerlow = if !botf then no else
                (ll1 > ll0 and (ShowPivotPoints or (ll2 > ll0)));

#// If selected show HH/LL on top/below candles.
AddChartBubble(ShowHHLL and higherhigh[-3], high, "HH", Color.RED);#style=shape.square, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and lowerhigh[-3], high, "LH", Color.DARK_RED);#style=shape.square, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and higherlow[-3], low, "HL", Color.DARK_GREEN, no);#style=shape.square, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
AddChartBubble(ShowHHLL and lowerlow[-3], low, "LL", Color.GREEN, no);#style=shape.square, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)

#// If selected display Pivot points
AddChartBubble(ShowPivotPoints and ShowPivotLabels and higherhigh[-3], high, "HH\nPVT", Color.RED);
plot hhPlus = if ShowPivotPoints and !ShowPivotLabels and higherhigh[-3] then high else na;
hhPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
hhPlus.SetDefaultColor(Color.RED);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and lowerhigh[-3], high, "LH\nPVT", Color.DARK_RED);
plot lhPlus = if ShowPivotPoints and !ShowPivotLabels and lowerhigh[-3] then high else na;
lhPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
lhPlus.SetDefaultColor(Color.DARK_RED);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and higherlow[-3], low, "PVT\nHL", Color.DARK_GREEN, no);
plot hlPlus = if ShowPivotPoints and !ShowPivotLabels and higherlow[-3] then low else na;
hlPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
hlPlus.SetDefaultColor(Color.DARK_GREEN);
#//
AddChartBubble(ShowPivotPoints and ShowPivotLabels and lowerlow[-3], low, "PVT\nLL", Color.GREEN, no);
plot llPlus = if ShowPivotPoints and !ShowPivotLabels and lowerlow[-3] then low else na;
llPlus.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
llPlus.SetDefaultColor(Color.GREEN);
#//
#// Number candles on Pivot patterns.
plot hi1u = if ShowPivotPoints and filteredtopf[-5] then 1 else na;
plot hi2u = if ShowPivotPoints and filteredtopf[-4] then 2 else na;
plot hi2d = if ShowPivotPoints and filteredtopf[-2] then 2 else na;
plot hi1d = if ShowPivotPoints and filteredtopf[-1] then 1 else na;

plot lo1u = if ShowPivotPoints and filteredbotf[-5] then 1 else na;
plot lo2u = if ShowPivotPoints and filteredbotf[-4] then 2 else na;
plot lo2d = if ShowPivotPoints and filteredbotf[-2] then 2 else na;
plot lo1d = if ShowPivotPoints and filteredbotf[-1] then 1 else na;

hi1u.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi2u.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi2d.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi1d.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
hi1u.SetDefaultColor(Color.RED);
hi2u.SetDefaultColor(Color.RED);
hi2d.SetDefaultColor(Color.RED);
hi1d.SetDefaultColor(Color.RED);

lo1u.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo2u.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo2d.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo1d.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
lo1u.SetDefaultColor(Color.GREEN);
lo2u.SetDefaultColor(Color.GREEN);
lo2d.SetDefaultColor(Color.GREEN);
lo1d.SetDefaultColor(Color.GREEN);

#/ === ALERTS ===
#// Check for 1st Heikin Ashi Bar exit the PAC
def isup = exitClose>exitOpen and exitClose>pacU and exitClose[1]<pacU[1]
        and (!useMovAvg200Filter or pacC>emaMedium);
def isdn = exitClose<exitOpen and exitClose<pacL and exitClose[1]>pacL[1]
        and (!useMovAvg200Filter or pacC<emaMedium);

#// Check have alert
def up_alert = if isup then if !up_alert[1] then 1 else up_alert[1]+1 else 0;
def dn_alert = if isdn then if !dn_alert[1] then 1 else dn_alert[1]+1 else 0;
#//
plot ArrowUp = if showPriceActionSwingArrows and up_alert[1]==1 then low else na;
plot ArrowDn = if showPriceActionSwingArrows and dn_alert[1]==1 then high else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowDn.SetDefaultColor(Color.ORANGE);

#-- END of CODE
Thank you very much.
 
Amazing indicator. Can we get a scanner for this @MerryDay @samer800 @BenTen?

Also, I notice that the indicator paints the previous candle after the present candle is closed. Is anyone seeing the same thing. Is there a possible way to change that?
 
Last edited:
Amazing indicator. Can we get a scanner for this @MerryDay @samer800 @BenTen?

Also, I notice that the indicator paints the previous candle after the present candle is closed. Is anyone seeing the same thing. Is there a possible way to change that?

Good catch! Yes, this indicator waits 3 bars into the future for pivot confirmation and then goes back and repaints the bars.

No, repainters cannot be made to not repaint.
Scanning for future bars is an act of frustration as scans happen in real time, but the bars were painted 3 bars ago.

You can go back in time, and find the repainted bars, but the lag makes the trade unprofitable for scalpers and short daytraders.

If you still want it; here is how to set up your scan:
1. set up your scan: https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
2. change your filter to "within 3 bars"
This will go back in time and look for the repainted signals.

Workaround: adding "within x bars" to your signal, goes back in time and finds repainted signals, but be warned, you really don't want to do this. The lag for scalpers is not tolerable.
You will possibly end up running into the "Too Complex" error. Or you will time out; Or get squirrelly results.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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