ToS addChartBubble into arrow/label code help

sandeep1976

New member
Hi All,

I am looking to convert the bubble on this indicator to Label/ Arrow so that I can use the Label/Arrow in my watchlist or scanner. Any help is much appreciated. I did tried to look to bubble to label/arrow code but could not crack it.

The current code with bubble that needs to be converted into Label/Arrows is listed below:

Example 1:

# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def BBar = bar == HighestAll(bar);
# Parent High
def ParentHigh = HighestAll(h);
def ParentHBarOrigin = if h == ParentHigh
then bar
else ParentHBarOrigin[1];
def ParentHBarID = bar - ParentHBarOrigin;
def PHBarID = bar - PHBarOrigin;
# R1
def hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -i);
def PivotH = if (bar > n and
h == Highest(h, n) and
hh)
then h
else Double.NaN;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue[1];
def PHBarOrigin = if !IsNaN(PivotH)
then bar
else PHBarOrigin[1];
# Plots
plot PR1 = LinePlot(BarID = ParentHBarID,
Value = ParentHigh,
BarOrigin = ParentHBarOrigin);
PR1.SetDefaultColor(Color.GREEN);
plot R1 = LinePlot(BarID = PHBarID,
Value = PHValue,
BarOrigin = PHBarOrigin);

AddChartBubble(Bar == HighestAll(ParentHBarOrigin), ParentHigh, "B", Color.Yellow, 0);
# how to convert this above addChartBubble into arrow/label so that I can get the B label in my watchlist on the stock

Example 2 from the same code:
plot PS1 = LinePlot(BarID = ParentLBarID,
Value = ParentLow,
BarOrigin = ParentLBarOrigin);
PS1.SetDefaultColor(Color.RED);
AddChartBubble(Bar == HighestAll(ParentLBarOrigin), ParentLow, "A", Color.Yellow, 0);
plot S1 = LinePlot(BarID = PLBarID,
Value = PLValue,
BarOrigin = PLBarOrigin);
#S1.SetDefaultColor(Color.RED);
S1.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(PLBarOrigin), PLvalue, "S1", Color.OranGE, 0);
# how to convert this above addChartBubble into arrow/label so that I can get the A or S1 label in my watchlist on the stock

The overall code can be imported into Thinkorswim by using the link: https://tos.mx/0LUZBA

Regards
Sandeep
 
Solution
@sandeep1976
My edits to the code are commented to explain behavior.

Code:
# Fractal Pivot Array 11 deep - (Start For Elliott Wave Code)
# Mobius
# V02.01.2017
# Added some information on Basic Wave Structure and labels to hold wave data started

# User Inputs
input n = 10;
input WaveLabel = yes;
input ShowWaves = yes;

# Internal Script Reference
script LinePlot {
    input BarID = 0;
    input Value = 0;
    input BarOrigin = 0;
    def ThisBar = HighestAll(BarOrigin);
    def ValueLine = if BarOrigin == ThisBar
                then Value
                else Double.NaN;
    plot P = if ThisBar - BarID <= BarOrigin
             then HighestAll(ValueLine)
             else Double.NaN;
}
# Variables
def o = open;
def h = high;
def l...
@sandeep1976
My edits to the code are commented to explain behavior.

Code:
# Fractal Pivot Array 11 deep - (Start For Elliott Wave Code)
# Mobius
# V02.01.2017
# Added some information on Basic Wave Structure and labels to hold wave data started

# User Inputs
input n = 10;
input WaveLabel = yes;
input ShowWaves = yes;

# Internal Script Reference
script LinePlot {
    input BarID = 0;
    input Value = 0;
    input BarOrigin = 0;
    def ThisBar = HighestAll(BarOrigin);
    def ValueLine = if BarOrigin == ThisBar
                then Value
                else Double.NaN;
    plot P = if ThisBar - BarID <= BarOrigin
             then HighestAll(ValueLine)
             else Double.NaN;
}
# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def BBar = bar == HighestAll(bar);
# Parent High
def ParentHigh = HighestAll(h);
def ParentHBarOrigin = if h == ParentHigh
                       then bar
                       else ParentHBarOrigin[1];
def ParentHBarID = bar - ParentHBarOrigin;
# R1
def hh = fold i = 1 to n + 1
         with p = 1
         while p
         do h > GetValue(h, -i);
def PivotH = if (bar > n and
                 h == Highest(h, n) and
                 hh)
            then h
            else Double.NaN;
def PHValue = if !IsNaN(PivotH)
              then PivotH
              else PHValue[1];
def PHBarOrigin = if !IsNaN(PivotH)
                  then bar
                  else PHBarOrigin[1];
def PHBarID = bar - PHBarOrigin;
# R2
def R2PHValue = if PHValue != PHValue[1]
              then PHValue[1]
              else R2PHValue[1];
def R2PHBarOrigin = if PHBarOrigin != PHBarOrigin[1]
                  then PHBarOrigin[1]
                  else R2PHBarOrigin[1];
def R2PHBarID = bar - R2PHBarOrigin;
# R3
def R3PHValue = if R2PHValue != R2PHValue[1]
              then R2PHValue[1]
              else R3PHValue[1];
def R3PHBarOrigin = if R2PHBarOrigin != R2PHBarOrigin[1]
                  then R2PHBarOrigin[1]
                  else R3PHBarOrigin[1];
def R3PHBarID = bar - R3PHBarOrigin;
# R4
def R4PHValue = if R3PHValue != R3PHValue[1]
              then R3PHValue[1]
              else R4PHValue[1];
def R4PHBarOrigin = if R3PHBarOrigin != R3PHBarOrigin[1]
                  then R3PHBarOrigin[1]
                  else R4PHBarOrigin[1];
def R4PHBarID = bar - R4PHBarOrigin;
# R5
def R5PHValue = if R4PHValue != R4PHValue[1]
              then R4PHValue[1]
              else R5PHValue[1];
def R5PHBarOrigin = if R4PHBarOrigin != R4PHBarOrigin[1]
                  then R4PHBarOrigin[1]
                  else R5PHBarOrigin[1];
def R5PHBarID = bar - R5PHBarOrigin;
# R6
def R6PHValue = if R5PHValue != R5PHValue[1]
              then R5PHValue[1]
              else R6PHValue[1];
def R6PHBarOrigin = if R5PHBarOrigin != R5PHBarOrigin[1]
                  then R5PHBarOrigin[1]
                  else R6PHBarOrigin[1];
def R6PHBarID = bar - R6PHBarOrigin;
# R5
def R7PHValue = if R6PHValue != R6PHValue[1]
              then R6PHValue[1]
              else R7PHValue[1];
def R7PHBarOrigin = if R6PHBarOrigin != R6PHBarOrigin[1]
                  then R6PHBarOrigin[1]
                  else R7PHBarOrigin[1];
def R7PHBarID = bar - R7PHBarOrigin;
# R8
def R8PHValue = if R7PHValue != R7PHValue[1]
              then R7PHValue[1]
              else R8PHValue[1];
def R8PHBarOrigin = if R7PHBarOrigin != R7PHBarOrigin[1]
                  then R7PHBarOrigin[1]
                  else R8PHBarOrigin[1];
def R8PHBarID = bar - R8PHBarOrigin;
# R9
def R9PHValue = if R8PHValue != R8PHValue[1]
              then R8PHValue[1]
              else R9PHValue[1];
def R9PHBarOrigin = if R8PHBarOrigin != R8PHBarOrigin[1]
                  then R8PHBarOrigin[1]
                  else R9PHBarOrigin[1];
def R9PHBarID = bar - R9PHBarOrigin;
# R10
def R10PHValue = if R9PHValue != R9PHValue[1]
              then R9PHValue[1]
              else R10PHValue[1];
def R10PHBarOrigin = if R9PHBarOrigin != R9PHBarOrigin[1]
                  then R9PHBarOrigin[1]
                  else R10PHBarOrigin[1];
def R10PHBarID = bar - R10PHBarOrigin;

# Parent Low
def ParentLow = LowestAll(l);
def ParentLBarOrigin = if l == ParentLow
                       then bar
                       else ParentLBarOrigin[1];
def ParentLBarID = bar - ParentLBarOrigin;
# S1
def ll = fold j = 1 to n + 1
         with q = 1
         while q
         do l < GetValue(l, -j);
def PivotL = if (bar > n and
                 l == Lowest(l, n) and
                 ll)
             then l
             else Double.NaN;
def PLValue = if !IsNaN(PivotL)
              then PivotL
              else PLValue[1];
def PLBarOrigin = if !IsNaN(PivotL)
                  then bar
                  else PLBarOrigin[1];
def PLBarID = bar - PLBarOrigin;
# S2
def S2PLValue = if PLValue != PLValue[1]
              then PLValue[1]
              else S2PLValue[1];
def S2PLBarOrigin = if PLBarOrigin != PLBarOrigin[1]
                  then PLBarOrigin[1]
                  else S2PLBarOrigin[1];
def S2PLBarID = bar - S2PLBarOrigin;
# S3
def S3PLValue = if S2PLValue != S2PLValue[1]
              then S2PLValue[1]
              else S3PLValue[1];
def S3PLBarOrigin = if S2PLBarOrigin != S2PLBarOrigin[1]
                  then S2PLBarOrigin[1]
                  else S3PLBarOrigin[1];
def S3PLBarID = bar - S3PLBarOrigin;
# S4
def S4PLValue = if S3PLValue != S3PLValue[1]
              then S3PLValue[1]
              else S4PLValue[1];
def S4PLBarOrigin = if S3PLBarOrigin != S3PLBarOrigin[1]
                  then S3PLBarOrigin[1]
                  else S4PLBarOrigin[1];
def S4PLBarID = bar - S4PLBarOrigin;
# S5
def S5PLValue = if S4PLValue != S4PLValue[1]
              then S4PLValue[1]
              else S5PLValue[1];
def S5PLBarOrigin = if S4PLBarOrigin != S4PLBarOrigin[1]
                  then S4PLBarOrigin[1]
                  else S5PLBarOrigin[1];
def S5PLBarID = bar - S5PLBarOrigin;
# S6
def S6PLValue = if S5PLValue != S5PLValue[1]
              then S5PLValue[1]
              else S6PLValue[1];
def S6PLBarOrigin = if S5PLBarOrigin != S5PLBarOrigin[1]
                  then S5PLBarOrigin[1]
                  else S6PLBarOrigin[1];
def S6PLBarID = bar - S6PLBarOrigin;
# S7
def S7PLValue = if S6PLValue != S6PLValue[1]
              then S6PLValue[1]
              else S7PLValue[1];
def S7PLBarOrigin = if S6PLBarOrigin != S6PLBarOrigin[1]
                  then S6PLBarOrigin[1]
                  else S7PLBarOrigin[1];
def S7PLBarID = bar - S7PLBarOrigin;
# S8
def S8PLValue = if S7PLValue != S7PLValue[1]
              then S7PLValue[1]
              else S8PLValue[1];
def S8PLBarOrigin = if S7PLBarOrigin != S7PLBarOrigin[1]
                  then S7PLBarOrigin[1]
                  else S8PLBarOrigin[1];
def S8PLBarID = bar - S8PLBarOrigin;
# S9
def S9PLValue = if S8PLValue != S8PLValue[1]
              then S8PLValue[1]
              else S9PLValue[1];
def S9PLBarOrigin = if S8PLBarOrigin != S8PLBarOrigin[1]
                  then S8PLBarOrigin[1]
                  else S9PLBarOrigin[1];
def S9PLBarID = bar - S9PLBarOrigin;
# S10
def S10PLValue = if S9PLValue != S9PLValue[1]
              then S9PLValue[1]
              else S10PLValue[1];
def S10PLBarOrigin = if S9PLBarOrigin != S9PLBarOrigin[1]
                  then S9PLBarOrigin[1]
                  else S10PLBarOrigin[1];
def S10PLBarID = bar - S10PLBarOrigin;
 
# Plots
plot PR1 = LinePlot(BarID = ParentHBarID,
                    Value = ParentHigh,
                    BarOrigin = ParentHBarOrigin);
PR1.SetDefaultColor(Color.GREEN);
AddChartBubble(Bar == HighestAll(ParentHBarOrigin), ParentHigh, "B", Color.Yellow, 1);

##############################################
#Edit by Svanoy
#Plot arrow at Parent Bar "B".
plot PR1P = if Bar == HighestAll(ParentHBarOrigin) then ParentHigh else Double.NaN;
PR1P.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
PR1P.SetDefaultColor(Color.Yellow);
PR1P.SetLineWeight(3);
##############################################

plot R1 = LinePlot(BarID = PHBarID,
                   Value = PHValue,
                   BarOrigin = PHBarOrigin);
R1.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(PHBarOrigin), PHvalue, "R1", color.green, 1);

##############################################
#Edit by Svanoy
#Plot arrow atan "R1".
plot R1P = if Bar == HighestAll(PHBarOrigin) then PHvalue else Double.NaN;
R1P.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
R1P.SetDefaultColor(Color.GREEN);
R1P.SetLineWeight(3);
##############################################

plot R2 = LinePlot(BarID = R2PHBarID,
                   Value = R2PHValue,
                   BarOrigin = R2PHBarOrigin);
R2.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R2PHBarOrigin), PHvalue, "R2", color.green, 1);
plot R3 = LinePlot(BarID = R3PHBarID,
                   Value = R3PHValue,
                   BarOrigin = R3PHBarOrigin);
R3.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R3PHBarOrigin), PHvalue, "R3", color.green, 1);
plot R4 = LinePlot(BarID = R4PHBarID,
                   Value = R4PHValue,
                   BarOrigin = R4PHBarOrigin);
R4.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R4PHBarOrigin), PHvalue, "R4", color.green, 1);
plot R5 = LinePlot(BarID = R5PHBarID,
                   Value = R5PHValue,
                   BarOrigin = R5PHBarOrigin);
R5.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R5PHBarOrigin), PHvalue, "R5", color.green, 1);
plot R6 = LinePlot(BarID = R6PHBarID,
                   Value = R6PHValue,
                   BarOrigin = R6PHBarOrigin);
R6.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R6PHBarOrigin), PHvalue, "R6", color.green, 1);
plot R7 = LinePlot(BarID = R7PHBarID,
                   Value = R7PHValue,
                   BarOrigin = R7PHBarOrigin);
R7.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R7PHBarOrigin), PHvalue, "R7", color.green, 1);
plot R8 = LinePlot(BarID = R8PHBarID,
                   Value = R8PHValue,
                   BarOrigin = R8PHBarOrigin);
R8.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R8PHBarOrigin), PHvalue, "R8", color.green, 1);
plot R9 = LinePlot(BarID = R9PHBarID,
                   Value = R9PHValue,
                   BarOrigin = R9PHBarOrigin);
R9.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R9PHBarOrigin), PHvalue, "R9", color.green, 1);
plot R10 = LinePlot(BarID = R10PHBarID,
                   Value = R10PHValue,
                   BarOrigin = R10PHBarOrigin);
R10.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R10PHBarOrigin), PHvalue, "R10", color.green, 1);

plot PS1 = LinePlot(BarID = ParentLBarID,
                   Value = ParentLow,
                   BarOrigin = ParentLBarOrigin);
PS1.SetDefaultColor(Color.RED);
AddChartBubble(Bar == HighestAll(ParentLBarOrigin), ParentLow, "A", Color.Yellow, 0);

##############################################
#Edit by Svanoy
#Plot arrow at Parent Bar "A".
plot PS1P = if Bar == HighestAll(ParentLBarOrigin) then ParentLow else Double.NaN;
PS1P.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
PS1P.SetDefaultColor(Color.YELLOW);
PS1P.SetLineWeight(3);
##############################################

plot S1 = LinePlot(BarID = PLBarID,
                   Value = PLValue,
                   BarOrigin = PLBarOrigin);
S1.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(PLBarOrigin), PLvalue, "S1", color.red, 0);

##############################################
#Edit by Svanoy
#Plot arrow at "S1"
plot S1P = if Bar == HighestAll(PLBarOrigin) then PLvalue else Double.NaN;
S1P.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
S1P.SetDefaultColor(Color.RED);
S1P.SetLineWeight(3);
##############################################

plot S2 = LinePlot(BarID = S2PLBarID,
                   Value = S2PLValue,
                   BarOrigin = S2PLBarOrigin);
S2.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S2PLBarOrigin), PLvalue, "S2", color.red, 0);
plot S3 = LinePlot(BarID = S3PLBarID,
                   Value = S3PLValue,
                   BarOrigin = S3PLBarOrigin);
S3.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S3PLBarOrigin), PLvalue, "S3", color.red, 0);
plot S4 = LinePlot(BarID = S4PLBarID,
                   Value = S4PLValue,
                   BarOrigin = S4PLBarOrigin);
S4.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S4PLBarOrigin), PLvalue, "S4", color.red, 0);
plot S5 = LinePlot(BarID = S5PLBarID,
                   Value = S5PLValue,
                   BarOrigin = S5PLBarOrigin);
S5.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S5PLBarOrigin), PLvalue, "S5", color.red, 0);
plot S6 = LinePlot(BarID = S6PLBarID,
                   Value = S6PLValue,
                   BarOrigin = S6PLBarOrigin);
S6.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S6PLBarOrigin), PLvalue, "S6", color.red, 0);
plot S7 = LinePlot(BarID = S7PLBarID,
                   Value = S7PLValue,
                   BarOrigin = S7PLBarOrigin);
S7.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S7PLBarOrigin), PLvalue, "S7", color.red, 0);
plot S8 = LinePlot(BarID = S8PLBarID,
                   Value = S8PLValue,
                   BarOrigin = S8PLBarOrigin);
S8.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S8PLBarOrigin), PLvalue, "S8", color.red, 0);
plot S9 = LinePlot(BarID = S9PLBarID,
                   Value = S9PLValue,
                   BarOrigin = S9PLBarOrigin);
addChartBubble(Bar == HighestAll(S9PLBarOrigin), PLvalue, "S9", color.red, 0);
S9.SetDefaultColor(Color.RED);
plot S10 = LinePlot(BarID = S10PLBarID,
                   Value = S10PLValue,
                   BarOrigin = S10PLBarOrigin);
S10.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S10PLBarOrigin), PLvalue, "S10", color.red, 0);


#######################################################
#Edit by Svanoy
#Labels switching between last parent support or resistance plotted
input Lookback_Period = 15;#<=== (Must be 11 or higher).

#Labels switching between last support or resistance plotted.
def SRSwitch = If PHBarOrigin == PHBarOrigin[1] and PLBarOrigin != PLBarOrigin[1] within Lookback_Period bars then 1
               else If PHBarOrigin != PHBarOrigin[1] within Lookback_Period bars and PLBarOrigin == PLBarOrigin[1] then 0
               else 2;

def PSRSwitch = If ParentHBarOrigin == ParentHBarOrigin[1] and ParentLBarOrigin != ParentLBarOrigin[1] within Lookback_Period bars and SRSwitch==1 then 1
                else If ParentHBarOrigin != ParentHBarOrigin[1] within Lookback_Period bars and ParentLBarOrigin == ParentLBarOrigin[1] and SRSwitch==0 then 0
                else 2;

AddLabel(yes, If PSRSwitch==1 then "A" else If PSRSwitch==0 then "B" else "Waiting", If PSRSwitch==1 or PSRSwitch==0 then color.YELLOW else color.BLACK);
AddLabel(yes, If PSRSwitch==1 then ParentLow else If PSRSwitch==0 then ParentHigh else 0, If PSRSwitch==2 then color.BLACK else color.YELLOW);
AddLabel(yes, If SRSwitch==1 then "S1" else If SRSwitch==0 then "R1" else "Waiting", If SRSwitch==1 then color.RED else If SRSwitch==0 then color.GREEN else color.BLACK);
AddLabel(yes, If SRSwitch==1 then PLValue else If SRSwitch==0 then PHValue else 0, If SRSwitch==1 then color.RED else If SRSwitch==0 then color.GREEN else color.BLACK);
#######################################################


# End Code Fractal Array 11 Deep
# Trend Line
def MaxSlopeBar = Max(HighestAll(PLBarOrigin), ParentLBarOrigin);
def MinSlopeBar = Min(LowestAll(PLBarOrigin), ParentLBarOrigin);
def SSlope = (HighestAll(PLValue) - ParentLow) /
             (MaxSlopeBar - MinSlopeBar);           
# (HighestAll(PLBarOrigin) - ParentLBarOrigin);
def SExtend = if bar == MaxSlopeBar #HighestAll(PLBarOrigin)
              then 1
              else SExtend[1];
plot SupportLine = if low == ParentLow
                   then ParentLow
                   else if low == HighestAll(PLvalue)
                        then PLvalue
                        else double.nan;
SupportLine.EnableApproximation();
SupportLine.SetDefaultColor(Color.Gray);
SupportLine.SetLineWeight(2);
SupportLine.SetStyle(Curve.LONG_DASH);
plot SupportExtension = if SExtend
            then (bar - PLBarOrigin) * SSlope + PLvalue
            else Double.NaN;
SupportExtension.SetDefaultColor(Color.Gray);
SupportExtension.SetStyle(Curve.LONG_DASH);
SupportExtension.SetLineWeight(2);
#AddChartBubble(WaveLabel and bar == HighestAll(bar),
#               HighestAll(High),
#"Basic Elliott Wave Rules:" + "\n" +
#"Wave (2) cannot retrace past the start of Wave (1)" + "\n" +
#"Wave (3) cannot be the shortest wave in a 5 wave sequence." + "\n" +
#"Wave (4) cannot retrace into Wave (1)" + "\n",
#color.white, 1);
plot waves = if !isNaN(PivotH)
             then PivotH
             else if !isNaN(PivotL)
                  then PivotL
                  else double.nan;
     waves.SetStyle(Curve.Firm);
     waves.EnableApproximation();
     waves.SetDefaultColor(Color.Cyan);
     waves.SetLineWeight(2);
     waves.SetHiding(!ShowWaves);
 
Last edited:
Solution

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

@@Svanoy. After doing some back testing, I keep getting "B" all the time even if "A" has arrived now or few bar ago. Could you please check to see where we might be going wrong or where I am wrong. I tried to change the code but still keep getting B (which had arrived yesterday instead of A which has arrive today). I am referring to your updated code:

#Edit by Svanoy
#Labels switching between last parent support or resistance plotted.
def PSRSwitch = If ParentHigh == ParentHigh[1] and ParentLow != ParentLow[1] then 1
else If ParentHigh != ParentHigh[1] and ParentLow == ParentLow[1] then 0
else PSRSwitch[1];
AddLabel(yes, If PSRSwitch==1 then "A" else "B", color.YELLOW);
AddLabel(yes, If PSRSwitch==1 then ParentLow else ParentHigh, color.YELLOW);


Question and additional help: In some instances, "A" and "S1/S2/S3/S4/S5" arrives on the same candle/bar, how can we code that so that we can get 2 different arrows for A and another for S1/S2/S3/S4/S5/S6/S7 on the same candle/bar.



Regards
Sandeep
 
@Svanoy :One more update: SRSwitch for switching between S1 and R1 is working great (when R1 is coming then it is giving R1 or it will give S1 (as soon as S1 arrives on the chart after R1)) as per your code below but PSRSwitch code is not working (it always gives "B" even if "A" has arrived)

#Labels switching between last support or resistance plotted.
def SRSwitch = If PHValue == PHValue[1] and PLValue != PLValue[1] then 1
else If PHValue != PHValue[1] and PLValue == PLValue[1] then 0
else SRSwitch[1];
AddLabel(yes, If SRSwitch==1 then "S1" else "R1", If SRSwitch==1 then color.RED else color.GREEN);
AddLabel(yes, If SRSwitch==1 then PLValue else PHValue, If SRSwitch==1 then color.RED else color.GREEN);


Regards
Sandeep
 
Thanks a ton @Svanoy. I really appreciate the help. I need one more additional help as listed below:

1) In some instances, "A" and "S1/S2/S3/S4/S5" arrives on the same candle/bar, how can we code that so that we can get 2 different arrows for A and another for S1/S2/S3/S4/S5/S6/S7 on the same candle/bar. I am trying to put this indicator into watchlist column so that I can get A and/or S1/S2/S3/S4/S5 at the same time on my 1D: 5 mins chart candle. Can it be done or not possible.

To give you more context, let me put some explanation:

1) Yesterday on one of my stock, I got A and S1 on my same 5 mins candle ( 9.40 am est). If I need to scanner or put in watchlist then what code I need to put so that A and S1 can come in the same watchlist column or one scanner custom code
2) Yesterday on another of my stock, I got A and S3 on my same 5 mins candle ( 10.20 am est). If I need to scanner or put in watchlist then what code I need to put so that A and S3 can come in the same watchlist column or one scanner custom code
3) Yesterday on another of my stock, I only got A but no S1/S2/S3/S4/S5 on my same 5 mins candle ( 13.30 am est). If I need to scanner or put in watchlist then what code I need to put so that A can come in the same watchlist column or one scanner custom code. This one id pretty easy and I can do it but not the above 2 scenarios.

Regards
Sandeep
 
@Svanoy. I was doing live trade monitoring using this indicator with your new updates and getting some strange issues in my watchlist. I have created 2 new columns to track when I am getting A/B or S1/R1. In the watchlist, I want to do the following as listed below:

1) On on A/B column (5 mins) in my watchlist, I want to get A/B only on last few bars or current bar. Right now, I am getting A/B in my column always and no blank, and it changes only when A becomes B or vice versa. If there are no A/B in last few 5 mins candle then I want the column to be blank and only bring A/B when we get S1/R1 in last few bar or current 5 mins bar. Can this be done? it will be very helpful.

Code for this watchlist:
#Labels switching between last parent support or resistance plotted
def PSRSwitch = If ParentHBarOrigin == ParentHBarOrigin[1] and ParentLBarOrigin != ParentLBarOrigin[1] then 1
else If ParentHBarOrigin != ParentHBarOrigin[1] and ParentLBarOrigin == ParentLBarOrigin[1] then 0
else PSRSwitch[1];
AddLabel(yes, If PSRSwitch==1 then "A" else "B", color.YELLOW);
AddLabel(yes, If PSRSwitch==1 then ParentLow else ParentHigh, color.YELLOW);

2) On on S1/R1 column (5 mins) in my watchlist, I want to get S1/R1 only on last few bars or current bar. Right now, I am getting S1/R1 in my column always and no blank, and it changes only when S1 becomes R1 or vice versa. If there are no S1/R1 in last few 5 mins candle then I want the column to be blank and only bring S1/R1 when we get S1/R1 in last few bar or current 5 mins bar. Can this be done? it will be very helpful.
Code for this watchlist:
#Labels switching between last support or resistance plotted.
def SRSwitch = If PHBarOrigin == PHBarOrigin[1] and PLBarOrigin != PLBarOrigin[1] then 1
else If PHBarOrigin != PHBarOrigin[1] and PLBarOrigin == PLBarOrigin[1] then 0
else SRSwitch[1];
AddLabel(yes, If SRSwitch==1 then "S1" else "R1", If SRSwitch==1 then color.RED else color.GREEN);
AddLabel(yes, If SRSwitch==1 then PLValue else PHValue, If SRSwitch==1 then color.RED else color.GREEN);

Any help will be really appreciated. I am really grateful that you created the new code that helped me get the arrows from the bubble.

Sandeep
 
@Svanoy. I did the testing after putting the new updated code into the watchlists but not getting signal on time at all.
1) On one stock both S1 and A came just at 10.10 am but the watchlist still showing waiting . I used your same loopback period of 15 and also tried to decrease the Lookback_Period to 11, 8, 6, 4 and 2 but still the watchlist was showing waiting and signal did not arrived on time
2) On one stock both S1 and A came at 11.00 am but the watchlist showed the signal at 12.00 noon (after 1 hour delay). On my watchlist and my chart, I am using 1D:5 mins timeline. All signal are coming on the watchlist after 1 hour delay.
3) Don't know what might work to get the S1/R1 and A/B signal sooner.
 
@Svanoy. My S1 or R1 watchlist column code with your updates
#input Lookback_Period = 15;#<=== (Must be 11 or higher).
input Lookback_Period = 12;#<=== (Must be 11 or higher).
#input Lookback_Period = 6;#<=== (Must be 11 or higher).
def SRSwitch = If PHBarOrigin == PHBarOrigin[1] and PLBarOrigin != PLBarOrigin[1] within Lookback_Period bars then 1
else If PHBarOrigin != PHBarOrigin[1] within Lookback_Period bars and PLBarOrigin == PLBarOrigin[1] then 0
else 2;
def PSRSwitch = If ParentHBarOrigin == ParentHBarOrigin[1] and ParentLBarOrigin != ParentLBarOrigin[1] within Lookback_Period bars and SRSwitch==1 then 1
else If ParentHBarOrigin != ParentHBarOrigin[1] within Lookback_Period bars and ParentLBarOrigin == ParentLBarOrigin[1] and SRSwitch==0 then 0
else 2;

AddLabel(yes, If PSRSwitch==1 then "A" else If PSRSwitch==0 then "B" else "Waiting", If PSRSwitch==1 or PSRSwitch==0 then color.YELLOW else color.BLACK);
#AddLabel(yes, If PSRSwitch==1 then ParentLow else If PSRSwitch==0 then ParentHigh else 0, If PSRSwitch==2 then color.BLACK else color.YELLOW);

My A or B watchlist column code with your updates

# Sandeep new code starts
#input Lookback_Period = 15;#<=== (Must be 11 or higher).
#input Lookback_Period = 6;#<=== (Must be 11 or higher).
input Lookback_Period = 12;#<=== (Must be 11 or higher).
def SRSwitch = If PHBarOrigin == PHBarOrigin[1] and PLBarOrigin != PLBarOrigin[1] within Lookback_Period bars then 1
else If PHBarOrigin != PHBarOrigin[1] within Lookback_Period bars and PLBarOrigin == PLBarOrigin[1] then 0
else 2;
def PSRSwitch = If ParentHBarOrigin == ParentHBarOrigin[1] and ParentLBarOrigin != ParentLBarOrigin[1] within Lookback_Period bars and SRSwitch==1 then 1
else If ParentHBarOrigin != ParentHBarOrigin[1] within Lookback_Period bars and ParentLBarOrigin == ParentLBarOrigin[1] and SRSwitch==0 then 0
else 2;

AddLabel(yes, If PSRSwitch==1 then "A" else If PSRSwitch==0 then "B" else "Waiting", If PSRSwitch==1 or PSRSwitch==0 then color.YELLOW else color.BLACK);
#AddLabel(yes, If PSRSwitch==1 then ParentLow else If PSRSwitch==0 then ParentHigh else 0, If PSRSwitch==2 then color.BLACK else color.YELLOW);
 
@sandeep1976. The reason you are seeing a delay is that S1/R1 and A/B signals do not occur in real time. They are plotted only after confirmation which is 10 bars later. So in your first example, even though the plot is on the bar opening at 10:10, it wasn't actually plotted until 11:00.
 
@sandeep1976 The indicator you shared repaints.
The snippets below are of the same signal within a 5 minute window.
CzUoz7u.png

28UjKsl.png

FFf6onU.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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