Repaints Double Top and Double Bottom For ThinkOrSwim

Repaints

MagicBlueBalls

New member
Could any chap in here make a "Double Top" version of Mobius Double Bottom? I have tried everything but no cigar.
 
Last edited by a moderator:
try this, i am not expert but hope this work.

Ruby:
# Double Top \ Bottom
# Mobius
# Mod Sam4Cok

input Percent_A_to_C = .1;
input nP = 13;
input ShowValues = yes;
input ShowLines = yes;

def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);
CondH1.SetHiding(!ShowLines);

plot PivotHigh = PivotH;
PivotHigh.SetDefaultColor(Color.WHITE);
PivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
PivotHigh.SetHiding(!ShowValues);

plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotHDot.SetLineWeight(3);

# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.Yellow);
Cond1.SetHiding(!ShowLines);

plot pivotLow = PivotL;
pivotLow.SetDefaultColor(Color.Yellow);
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!ShowValues);

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotLDot.SetLineWeight(3);

# End Code
 
Last edited by a moderator:
Hello I am trying to fix this thinkscript to update in real time. Not entirely sure if that requires repaint or not, but was wondering if anyone could provide some insight on what may be missing.

UPDATE: Found Sam4Cok edit. Trying to have the candle get labeled right after the match. Right now it takes the nP or x candles after the bubble candle for it to actually populate the bubble. So instead of testing x number of candles after... instead search a range before such as 5 candles and then compare with the 2 previous candles. If the 2 previous trigger the match then the active candle should immediately get labeled.

Credit to Mobius for the original script
Credit to Sam4Cok for mod


VJllFaE.jpg


Ruby:
# Double Top \ Bottom
# Mobius
# Mod Sam4Cok
# Edited By ShadFX
# Combo Double Top and Bubbles
# Date: 12/13/2022

input Percent_A_to_C = .1;
#input nP = 3;
input ShowValues = yes;
input ShowLines = yes;
input ShowLabel = yes;
input blink = no;

def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;
def offset = 3;
def range = 2;


def ll = fold jl = range to offset + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (
l == Lowest(l, range) and
ll)
then l
else Double.NaN;

def hh = fold j = range to offset + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (
h == Highest(h, range) and
hh)
then h
else Double.NaN;


###########################
#DOUBLE TOP

def PH1 = if !IsNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if Between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else Double.NaN);
CondH1.SetDefaultColor(Color.DARK_RED);
CondH1.SetHiding(!ShowLines);

plot PivotHigh = PivotH;
PivotHigh.SetDefaultColor(Color.DARK_RED);
#PivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
PivotHigh.SetHiding(!ShowValues);

plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.DARK_RED);
#PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotHDot.SetLineWeight(3);

# Double Bottom

def PL1 = if !IsNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if Between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else Double.NaN);
Cond1.SetDefaultColor(Color.DARK_GREEN);
Cond1.SetHiding(!ShowLines);

plot pivotLow = PivotL;
pivotLow.SetDefaultColor(Color.DARK_GREEN);
#pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!ShowValues);

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.DARK_GREEN);
#PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotLDot.SetLineWeight(3);

#AddChartBubble(bar and pivotLow, low, if pivotLow then "UP" else "", Color.UPTICK, no);
#AddChartBubble(bar and pivotHigh, high, if pivotHigh then "DOWN" else "", Color.DOWNTICK, yes);

#def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(bar);
def limit = !IsNaN(close) and IsNaN(close [-4] );
#AddChartBubble(bar and pivotLow and limit, low, if PivotL then "UP" else "", Color.UPTICK, no);
#AddChartBubble(bar and PivotHigh and limit, high, if PivotH then "DOWN" else "", Color.DOWNTICK, yes);

AddOrder(OrderType.BUY_AUTO,  PivotLow, name = "B", tickColor = Color.WHITE, arrowColor = Color.WHITE);
AddOrder(OrderType.SELL_AUTO, PivotHigh, name = "S" , tickcolor = Color.WHITE, arrowcolor = Color.WHITE);
 
Last edited:
From my understanding this is a pivot base indicator finds the average lowest range and average highest range?
 
It finds the lowest low or highest high in a range of candles that are similar to a double top/bottom pattern.

This is the main portion I am working with. Basically the bottom two mirror the top two just inverted for high vs low.

Ruby:
def ll = fold jl = range to offset + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (
l == Lowest(l, range) and
ll)
then l
else Double.NaN;

def hh = fold j = range to offset + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (
h == Highest(h, range) and
hh)
then h
else Double.NaN;
 
It finds the lowest low or highest high in a range of candles that are similar to a double top/bottom pattern.

This is the main portion I am working with. Basically the bottom two mirror the top two just inverted for high vs low.

Ruby:
def ll = fold jl = range to offset + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (
l == Lowest(l, range) and
ll)
then l
else Double.NaN;

def hh = fold j = range to offset + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (
h == Highest(h, range) and
hh)
then h
else Double.NaN;
does this repaint?
 
From my further testing it does look like it repaints.

Any ideas on why you think the AddLabel wouldn't update colors when PivotLow is true or PivotHigh is true?

Ruby:
AddLabel(ShowLabel, "test123", if pivotLow then color.BLUE else if pivotHigh then color.DARK_ORANGE else Color.WHITE);
 
Hello I am trying to fix this thinkscript to update in real time. Not entirely sure if that requires repaint or not, but was wondering if anyone could provide some insight on what may be missing.

UPDATE: Found Sam4Cok edit. Trying to have the candle get labeled right after the match. Right now it takes the nP or x candles after the bubble candle for it to actually populate the bubble. So instead of testing x number of candles after... instead search a range before such as 5 candles and then compare with the 2 previous candles. If the 2 previous trigger the match then the active candle should immediately get labeled.

Credit to Mobius for the original script
Credit to Sam4Cok for mod


VJllFaE.jpg


Ruby:
# Double Top \ Bottom
# Mobius
# Mod Sam4Cok
# Edited By ShadFX
# Combo Double Top and Bubbles
# Date: 12/13/2022

input Percent_A_to_C = .1;
#input nP = 3;
input ShowValues = yes;
input ShowLines = yes;
input ShowLabel = yes;
input blink = no;

def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;
def offset = 3;
def range = 2;


def ll = fold jl = range to offset + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (
l == Lowest(l, range) and
ll)
then l
else Double.NaN;

def hh = fold j = range to offset + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (
h == Highest(h, range) and
hh)
then h
else Double.NaN;


###########################
#DOUBLE TOP

def PH1 = if !IsNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if Between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else Double.NaN);
CondH1.SetDefaultColor(Color.DARK_RED);
CondH1.SetHiding(!ShowLines);

plot PivotHigh = PivotH;
PivotHigh.SetDefaultColor(Color.DARK_RED);
#PivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
PivotHigh.SetHiding(!ShowValues);

plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.DARK_RED);
#PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotHDot.SetLineWeight(3);

# Double Bottom

def PL1 = if !IsNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if Between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else Double.NaN);
Cond1.SetDefaultColor(Color.DARK_GREEN);
Cond1.SetHiding(!ShowLines);

plot pivotLow = PivotL;
pivotLow.SetDefaultColor(Color.DARK_GREEN);
#pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!ShowValues);

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.DARK_GREEN);
#PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotLDot.SetLineWeight(3);

#AddChartBubble(bar and pivotLow, low, if pivotLow then "UP" else "", Color.UPTICK, no);
#AddChartBubble(bar and pivotHigh, high, if pivotHigh then "DOWN" else "", Color.DOWNTICK, yes);

#def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(bar);
def limit = !IsNaN(close) and IsNaN(close [-4] );
#AddChartBubble(bar and pivotLow and limit, low, if PivotL then "UP" else "", Color.UPTICK, no);
#AddChartBubble(bar and PivotHigh and limit, high, if PivotH then "DOWN" else "", Color.DOWNTICK, yes);

AddOrder(OrderType.BUY_AUTO,  PivotLow, name = "B", tickColor = Color.WHITE, arrowColor = Color.WHITE);
AddOrder(OrderType.SELL_AUTO, PivotHigh, name = "S" , tickcolor = Color.WHITE, arrowcolor = Color.WHITE);
i see too many up& downs....almost for every 3-4 candles...and what are cond1 and condh1?
 
try this, i am not expert but hope this work.
@samer800 thanks for this script, I would like to have a horizontal line plot across the pivotlow with this but it only plots a dash...how can i get the line drawn? Thanks

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);
PivotLDot.SetLineWeight(3);
 
Since I only like turning points I revamped this a bit to give White Dots at high/low turning points as follows:

Code:
# Tops \ Bottoms
# Mobius
# Modified C.Ricks 12/22/22

input Percent_A_to_C = .1;
input nP = 13;


def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);


plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);


# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.White);


plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.White);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);

# End Code
 
Since I only like turning points I revamped this a bit to give White Dots at high/low turning points as follows:

# Tops \ Bottoms
# Mobius
# Modified C.Ricks 12/22/22

input Percent_A_to_C = .1;
input nP = 13;


def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);


plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);


# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.White);


plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.White);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);

# End Code
Hi,
Is it possible to change the dot to plot a horizontal line across?

Thanks
 
Since I only like turning points I revamped this a bit to give White Dots at high/low turning points as follows:

# Tops \ Bottoms
# Mobius
# Modified C.Ricks 12/22/22

input Percent_A_to_C = .1;
input nP = 13;


def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);


plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);


# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.White);


plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.White);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);

# End Code
How real time is this ?
 
How real time is this ?

This study uses a fold function, which in this case looks at future bars. You can see an example of this on line 39 where it says "GetValue(h, -j)". The "-j" refers to a negative bar index, which would be in the future. So even though it's real time it will not mark tops / bottoms until those future bars print.

Hopefully this helps.
 
Last edited by a moderator:
@samer800 thanks for this script, I would like to have a horizontal line plot across the pivotlow with this but it only plots a dash...how can i get the line drawn? Thanks

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.hoRIZONTAL);
PivotLDot.SetLineWeight(3);

@Mobius @8Nick8 @samer800


I have the same challenge. Wouldn't plot a horizontal line starting at pivots to right.. need your insight about this. Help?

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.horizontal);
PivotLDot.SetLineWeight(3);
 
try this, i am not expert but hope this work.

Ruby:
# Double Top \ Bottom
# Mobius
# Mod Sam4Cok

input Percent_A_to_C = .1;
input nP = 13;
input ShowValues = yes;
input ShowLines = yes;

def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);
CondH1.SetHiding(!ShowLines);

plot PivotHigh = PivotH;
PivotHigh.SetDefaultColor(Color.WHITE);
PivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
PivotHigh.SetHiding(!ShowValues);

plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotHDot.SetLineWeight(3);

# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.Yellow);
Cond1.SetHiding(!ShowLines);

plot pivotLow = PivotL;
pivotLow.SetDefaultColor(Color.Yellow);
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!ShowValues);

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotLDot.SetLineWeight(3);

# End Code
Thanks @samer800 for this code. This one looks perfect for DT/DB too.

https://www.tradingview.com/script/92tmeSms-Pro-Trading-Art-Double-Top-Bottom-with-alert/
 
try this, i am not expert but hope this work.

Ruby:
# Double Top \ Bottom
# Mobius
# Mod Sam4Cok

input Percent_A_to_C = .1;
input nP = 13;
input ShowValues = yes;
input ShowLines = yes;

def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);
CondH1.SetHiding(!ShowLines);

plot PivotHigh = PivotH;
PivotHigh.SetDefaultColor(Color.WHITE);
PivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
PivotHigh.SetHiding(!ShowValues);

plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotHDot.SetLineWeight(3);

# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.Yellow);
Cond1.SetHiding(!ShowLines);

plot pivotLow = PivotL;
pivotLow.SetDefaultColor(Color.Yellow);
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!ShowValues);

plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.Yellow);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotLDot.SetLineWeight(3);

# End Code
Hi Samer800, can you please provide scan for pivotHigh and PivotLow?
 
Slighlty modified version with bubbles:

Ruby:
# https://usethinkscript.com/threads/double-top-and-double-bottom-for-thinkorswim.11391/
# Tops \ Bottoms
# Mobius
# Modified C.Ricks 12/22/22

input Percent_A_to_C = .1;
input nP = 13;
input DisplayLabels = Yes;


def AC = Percent_A_to_C / 100;
def h = high;
def l = low;
def bar = BarNumber();
def Ps = 1 + AC;
def Ns = 1 - AC;

def hh = fold j = 1 to nP + 1
with q = 1
while q
do h > GetValue(h, -j);

def PivotH = if (bar > nP and
h == Highest(h, nP) and
hh)
then h
else Double.NaN;

def PH1 = if !isNaN(PivotH)
then h
else PH1[1];

def PH2 = if PH1 != PH1[1]
then PH1[1]
else PH2[1];

def CheckH1 = if between(PH2, PH1 * Ns, PH1 * Ps)
then 1
else 0;

plot CondH1 = HighestAll(if CheckH1
then PH2
else double.nan);
CondH1.SetDefaultColor(Color.WHITE);


plot PivotHDot = PivotH;
PivotHDot.SetDefaultColor(Color.WHITE);
PivotHDot.SetPaintingStrategy(PaintingStrategy.POINTS);


# Double Bottom

def ll = fold jl = 1 to nP + 1
with ql = 1
while ql
do l < GetValue(low, -jl);

def PivotL = if (bar > nP and
l == Lowest(l, nP) and
ll)
then l
else Double.NaN;

def PL1 = if !isNaN(PivotL)
then l
else PL1[1];

def PL2 = if PL1 != PL1[1]
then PL1[1]
else PL2[1];

def Check1 = if between(PL2, PL1 * Ns, PL1 * Ps)
then 1
else 0;

plot Cond1 = HighestAll(if Check1
then PL2
else double.nan);
Cond1.SetDefaultColor(Color.White);


plot PivotLDot = PivotL;
PivotLDot.SetDefaultColor(Color.White);
PivotLDot.SetPaintingStrategy(PaintingStrategy.POINTS);


AddChartBubble(DisplayLabels && PivotLDot, low, "Double bottom", Color.YELLOW, yes);
AddChartBubble(DisplayLabels && PivotHDot, high, "Double top", Color.WHITE, yes);


# End Code
 
I've this script but it shows double bottom like 1 hour late on 15 min. Is it possible to adjust so that double bottoms are displayed earlier? Actually, modified that np value which is by default 13, meaning it'll need 13 more candles closed to draw double bottom/top. Reducing that number will draw bottom/top earlier.

 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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