# Auto Pivot Points Support & Resistance Indicator for ThinkorSwim

Mobius Projection Pivots For ThinkOrSwim
This was a poster request. Mobius Project Pivots is the same script as found in the top post (and as shown in image2) with less plots.

Pivot points are used by traders in equity and commodity exchanges. They're calculated based on the high, low, and closing prices of previous trading sessions, and they're used to predict support and resistance levels in the current or upcoming session. These support and resistance levels can be used by traders to determine entry and exit points, both for stop-losses and profit taking. ~Investopedia

The code for the 1st image is directly below. The code for the JQ version is in the top post.

Ruby:
``````# V01.08.2012 Projection Pivots
# mobius
# 10.06.2016 Altered the fold expression relacing the index variable with -1

input n = 13;
input showLines = no;
input showValues = no;
input showBarNumbers = no;

def h = high;
def l = low;
def bar = barNumber();
def PH;
def PL;
def hh = fold i = 1 to n + 1
with p = 1
while p
do h > getValue(h, -i);
PH = if (bar > n and
h == highest(h, n) and
hh)
then h
else double.NaN;
def ll = fold j = 1 to n + 1
with q = 1
while q
do l < getValue(l, -j);
PL = if (bar > n and
l == lowest(l, n) and
ll)
then l
else double.NaN;
def PHBar = if !isNaN(PH)
then bar
else PHBar[1];
def PLBar = if !isNaN(PL)
then bar
else PLBar[1];
def PHL = if !isNaN(PH)
then PH
else PHL[1];
def priorPHBar = if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PLL = if !isNaN(PL)
then PL
else PLL[1];
def priorPLBar = if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);
def FirstRpoint = if HighPivots
then bar - PHBar
else 0;
def PriorRpoint = if HighPivots
then bar - PriorPHBar
else 0;
def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
/ (PHBar - PriorPHBar);
def FirstSpoint = if LowPivots
then bar - PLBar
else 0;
def PriorSpoint = if LowPivots
then bar - PriorPLBar
else 0;
def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
/ (PLBar - PriorPLBar);
def RExtend = if bar == highestall(PHBar)
then 1
else RExtend[1];
def SExtend = if bar == highestall(PLBar)
then 1
else SExtend[1];

plot pivotHigh = if HighPivots
then PH
else double.NaN;
pivotHigh.SetDefaultColor(GetColor(1));
pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.setHiding(!showValues);
plot pivotHighLine = if PHL > 0 and
HighPivots
then PHL
else double.NaN;
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.setHiding(!showLines);
plot RLine = pivotHigh;
RLine.enableApproximation();
RLine.SetDefaultColor(GetColor(7));
RLine.SetStyle(Curve.Short_DASH);
plot RExtension = if RExtend
then (bar - PHBar) * RSlope + PHL
else double.NaN;
RExtension.SetStyle(Curve.Short_DASH);
RExtension.SetDefaultColor(GetColor(7));
plot pivotLow = if LowPivots
then PL
else double.NaN;
pivotLow.setDefaultColor(GetColor(4));
pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.setHiding(!showValues);
plot pivotLowLine = if PLL > 0 and
LowPivots
then PLL
else double.NaN;
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.setHiding(!showLines);
plot SupportLine = pivotLow;
SupportLine.enableApproximation();
SupportLine.SetDefaultColor(GetColor(7));
SUpportLine.SetStyle(Curve.Short_DASH);
plot SupportExtension = if SExtend
then (bar - PLBar) * SSlope + PLL
else double.NaN;
SupportExtension.SetDefaultColor(GetColor(7));
SupportExtension.SetStyle(Curve.Short_DASH);
plot BN = bar;
BN.SetDefaultColor(GetColor(0));
BN.setHiding(!showBarNumbers);
BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot PivotDot = if !isNaN(pivotHigh)
then pivotHigh
else if !isNaN(pivotLow)
then pivotLow
else double.NaN;
pivotDot.SetDefaultColor(GetColor(7));
pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
pivotDot.SetLineWeight(3);
# End Code Projection Pivots``````
Hi Ben/Team, Where can I find the original Mobius algorithm for this? I want to develop a python script for this. Thank you!

Last edited:
Any more details on this? or is this a trendline study ?

Any more details on this? or is this a trendline study ?
Is your question how to use pivot point indicators?
Pivot points are used by traders in equity and commodity exchanges. They're calculated based on the high, low, and closing prices of previous trading sessions, and they're used to predict support and resistance levels in the current or upcoming session. These support and resistance levels can be used by traders to determine entry and exit points, both for stop-losses and profit taking. ~Investopedia

Thank you for creating. Works great on the 5m, but less so on the 1m. Is there a setting that i need to adjust - the N value is set at 13. Thanks!

Thank you for creating. Works great on the 5m, but less so on the 1m. Is there a setting that i need to adjust - the N value is set at 13. Thanks!
I would assume that you would need more data points to attempt to find something useful amongst all the noise on a one minute chart.

I created one minute charts in post#1 using n=21.
You would need to play with the inputs to find what supports your strategy.

Last edited:
Is it possible for the projection pivots to change quicker?

Is it possible for the projection pivots to change quicker?
The statement n= determine length. make the n= number smaller, would presumably make the "pivots to change quicker?"

I’m having a hard time to get this to work on mobile

Last edited by a moderator:
Pivot Study with Audible Alarms for Buy/Sell.... this is a mobious study, and definitely worth a try it also paints buy/sell wedges.

Code:
``````# Mobius
####EVANB ADDED CODE AT THE BOTTOM
# V01.08.2012

input n = 1;
input showLines = yes;
input showValues = Yes;
input showBarNumbers = no;

# 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;
}
def h = high;
def l = low;
def bar = barNumber();
def PH;
def PL;
def hh = fold i = 1 to n + 1
with p = 1
while p
do h > getValue(h, -i);
PH = if (bar > n and
h == highest(h, n) and
hh)
then h
else double.NaN;
def ll = fold j = 1 to n + 1
with q = 1
while q
do l < getValue(low, -j);
PL = if (bar > n and
l == lowest(l, n) and
ll)
then l
else double.NaN;
def PHBar = if !isNaN(PH)
then bar
else PHBar[1];
def PLBar = if !isNaN(PL)
then bar
else PLBar[1];
def PHL = if !isNaN(PH)
then PH
else PHL[1];
def priorPHBar = if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PriorPH = if PHL != PHL[1]
then PHL[1]
else PriorPH[1];
def PLL = if !isNaN(PL)
then PL
else PLL[1];
def PriorPLBar = if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def PriorPL = if PLL != PLL[1]
then PLL[1]
else PriorPL[1];
def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);
def FirstRpoint = if HighPivots
then bar - PHBar
else 0;
def PriorRpoint = if HighPivots
then bar - PriorPHBar
else 0;
def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
/ (PHBar - PriorPHBar);
def FirstSpoint = if LowPivots
then bar - PLBar
else 0;
def PriorSpoint = if LowPivots
then bar - PriorPLBar
else 0;
def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
/ (PLBar - PriorPLBar);
def RExtend = if bar == highestall(PHBar)
then 1
else RExtend[1];
def SExtend = if bar == highestall(PLBar)
then 1
else SExtend[1];
plot PriorPHLine = LinePlot(PriorRPoint, PriorPH, PriorPHBar);
PriorPHLine.SetStyle(Curve.Firm);
PriorPHLine.SetDefaultColor(Color.Red);
plot PivotHighLine = LinePlot(FirstRPoint, PH, PHBar);
PivotHighLine.SetStyle(Curve.Firm);
PivotHighLine.SetDefaultColor(Color.Red);
plot pivotHigh = if HighPivots
then PH
else double.NaN;
pivotHigh.SetDefaultColor(GetColor(1));
pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.setHiding(!showValues);
plot RLine = pivotHigh;
RLine.enableApproximation();
RLine.SetDefaultColor(GetColor(7));
RLine.SetStyle(Curve.Short_DASH);
plot RExtension = if RExtend
then (bar - PHBar) * RSlope + PHL
else double.NaN;
RExtension.SetStyle(Curve.Short_DASH);
RExtension.SetDefaultColor(GetColor(7));
plot PriorPLLine = LinePlot(PriorSPoint, PriorPL, PriorPLBar);
PriorPLLine.SetStyle(Curve.Firm);
PriorPLLine.SetDefaultColor(Color.Green);
plot PivotLowLine = LinePlot(FirstSPoint, PL, PLBar);
PivotLowLine.SetStyle(Curve.Firm);
PivotLowLine.SetDefaultColor(Color.Green);
plot pivotLow = if LowPivots
then PL
else double.NaN;
pivotLow.SetDefaultColor(GetColor(1));
pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotLow.setHiding(!showValues);
plot SupportLine = pivotLow;
SupportLine.enableApproximation();
SupportLine.SetDefaultColor(GetColor(7));
SUpportLine.SetStyle(Curve.Short_DASH);
plot SupportExtension = if SExtend
then (bar - PLBar) * SSlope + PLL
else double.NaN;
SupportExtension.SetDefaultColor(GetColor(7));
SupportExtension.SetStyle(Curve.Short_DASH);

### EvanB #######
plot buy = close[1] > pivotHighLine and high>high[1];

plot sell = close[1] < pivotlowline  and low < low[1];
sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
sell.SetDefaultColor(Color.pink);
plot bo = close>open and high>high[1] and close > rextension;
bo.setPaintingstrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
bo.SetDefaultColor(Color.green);
plot bd = close<open and low<low[1] and close < supportextension;
bd.setPaintingstrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
bd.SetDefaultColor(Color.pink);

what do the arrows mean? to buy and sell in the direction they are pointing or is it to mean they are oversold? also why are the top bars painted red and the bottom painted green?

what do the arrows mean? to buy and sell in the direction they are pointing or is it to mean they are oversold? also why are the top bars painted red and the bottom painted green?
The bottom is where price found support when combined with your other indicators this can be a good entry point.
The top is resistance, this is where the price previously stopped. Does not mean it will stop there again. But resistance is a popular target level for dippers

Mobius Projection Pivots For ThinkOrSwim
This was a poster request. Mobius Project Pivots is the same script as found in the top post (and as shown in image2) with less plots.

The code for the 1st image is directly below. The code for the JQ version is in the top post.

Ruby:
``````# V01.08.2012 Projection Pivots
# mobius
# 10.06.2016 Altered the fold expression relacing the index variable with -1

input n = 13;
input showLines = no;
input showValues = no;
input showBarNumbers = no;

def h = high;
def l = low;
def bar = barNumber();
def PH;
def PL;
def hh = fold i = 1 to n + 1
with p = 1
while p
do h > getValue(h, -i);
PH = if (bar > n and
h == highest(h, n) and
hh)
then h
else double.NaN;
def ll = fold j = 1 to n + 1
with q = 1
while q
do l < getValue(l, -j);
PL = if (bar > n and
l == lowest(l, n) and
ll)
then l
else double.NaN;
def PHBar = if !isNaN(PH)
then bar
else PHBar[1];
def PLBar = if !isNaN(PL)
then bar
else PLBar[1];
def PHL = if !isNaN(PH)
then PH
else PHL[1];
def priorPHBar = if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PLL = if !isNaN(PL)
then PL
else PLL[1];
def priorPLBar = if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);
def FirstRpoint = if HighPivots
then bar - PHBar
else 0;
def PriorRpoint = if HighPivots
then bar - PriorPHBar
else 0;
def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
/ (PHBar - PriorPHBar);
def FirstSpoint = if LowPivots
then bar - PLBar
else 0;
def PriorSpoint = if LowPivots
then bar - PriorPLBar
else 0;
def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
/ (PLBar - PriorPLBar);
def RExtend = if bar == highestall(PHBar)
then 1
else RExtend[1];
def SExtend = if bar == highestall(PLBar)
then 1
else SExtend[1];

plot pivotHigh = if HighPivots
then PH
else double.NaN;
pivotHigh.SetDefaultColor(GetColor(1));
pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.setHiding(!showValues);
plot pivotHighLine = if PHL > 0 and
HighPivots
then PHL
else double.NaN;
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.setHiding(!showLines);
plot RLine = pivotHigh;
RLine.enableApproximation();
RLine.SetDefaultColor(GetColor(7));
RLine.SetStyle(Curve.Short_DASH);
plot RExtension = if RExtend
then (bar - PHBar) * RSlope + PHL
else double.NaN;
RExtension.SetStyle(Curve.Short_DASH);
RExtension.SetDefaultColor(GetColor(7));
plot pivotLow = if LowPivots
then PL
else double.NaN;
pivotLow.setDefaultColor(GetColor(4));
pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.setHiding(!showValues);
plot pivotLowLine = if PLL > 0 and
LowPivots
then PLL
else double.NaN;
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.setHiding(!showLines);
plot SupportLine = pivotLow;
SupportLine.enableApproximation();
SupportLine.SetDefaultColor(GetColor(7));
SUpportLine.SetStyle(Curve.Short_DASH);
plot SupportExtension = if SExtend
then (bar - PLBar) * SSlope + PLL
else double.NaN;
SupportExtension.SetDefaultColor(GetColor(7));
SupportExtension.SetStyle(Curve.Short_DASH);
plot BN = bar;
BN.SetDefaultColor(GetColor(0));
BN.setHiding(!showBarNumbers);
BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot PivotDot = if !isNaN(pivotHigh)
then pivotHigh
else if !isNaN(pivotLow)
then pivotLow
else double.NaN;
pivotDot.SetDefaultColor(GetColor(7));
pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
pivotDot.SetLineWeight(3);
# End Code Projection Pivots``````
Sorry to ask, Why called the JQ version, is it Ben's post on page 1?!

Sorry to ask, Why called the JQ version, is it Ben's post on page 1?!
"#ProjectionPivots_v03_JQ"

Last edited:
Can we get this working on the cell phone?

Would someone be able to convert this for tos. It's pivot high and Pivot low marked with a dot. Thank you so much.

Last edited by a moderator:
mod note:
This study was moved here as it plots similarly to the other pivot points in this thread, except this has extended lines and pivot bubbles.
Would someone be able to convert this for tos. It's pivot high and Pivot low marked with a dot. Thank you so much.

inputs:
Price( High ) [DisplayName = "Price", ToolTip =
"Enter an EasyLanguage expression to use for pivot high determination."],
LeftStrength( 3 ) [DisplayName = "LeftStrength", ToolTip =
"Enter the number of bars to the left of the current bar to be analyzed to see if the price of those bars is less than the price of the current bar."],
RightStrength( 3 ) [DisplayName = "RightStrength", ToolTip =
"Enter the number of bars to the right of the current bar to be analyzed to see if the price of those bars is less than the price of the current bar."],
PlotOffsetTicks( 1 ) [DisplayName = "PlotOffsetTicks", ToolTip =
"Enter the number of price ticks to offset the plot from the pivot high."];

variables:
intrabarpersist double OnePriceTick( 0 ),
double PlotPriceValue( 0 );

once
begin
OnePriceTick = MinMove / PriceScale;
end;

if PivotHighVSBar( 1, Price, LeftStrength, RightStrength, RightStrength + 1 )
<> -1 then
begin
PlotPriceValue = High[RightStrength] + PlotOffsetTicks * OnePriceTick;
Plot1[RightStrength]( PlotPriceValue, !( "PivotHi" ) );
end
else
begin
NoPlot( 1 ); { remove the marker }
end;

Pivot low

inputs:
Price( Low ) [
DisplayName = "Price",
ToolTip = "Enter an EasyLanguage expression to use for pivot low determination."],

LeftStrength( 3 ) [
DisplayName = "LeftStrength",
ToolTip = "Enter the number of bars to the left of the current to be analyzed to see if the price of those bars is greater than the price of the current bar."],

RightStrength( 3 ) [
DisplayName = "RightStrength",
ToolTip = "Enter the number of bars to the right of the current to be analyzed to see if the price of those bars is greater than the price of the current bar."],

PlotOffsetTicks( 1 ) [
DisplayName = "PlotOffsetTicks",
ToolTip = "Enter the number of price ticks to offset the plot from the pivot low."];

variables:
intrabarpersist double OnePriceTick( 0 ),
double PlotPriceValue( 0 );

once
begin
OnePriceTick = MinMove / PriceScale;
end;

if PivotLowVSBar( 1, Price, LeftStrength, RightStrength, RightStrength + 1 )
<> -1 then
begin
PlotPriceValue = Low[RightStrength] - PlotOffsetTicks * OnePriceTick;
Plot1[RightStrength]( PlotPriceValue, !( "PivotLo" ) );
end
else
begin
NoPlot( 1 ); { remove the marker }
check this.

CSS:
``````declare upper;

input Length_Forward   = 9;
input Length_Backward  = 9;

#def _BN  = BarNumber();     # current barnumber
def na = Double.NaN;      # non-numeric values
def _H   = high;            # high price
def _L   = low;             # low price
def _C   = close;           # close price
def _O   = open;            # open price
#def _LL  = Lowestall(_L);   # lowest _L price
#def _HH  = highestall(_H);  # highest _H price

script FindPivots {
input dat = high; # default data or study being evaluated
input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
input PF  = 1;    # default pivot forward period
input PB  = 5;    # default pivot backward period

##############
def _nan;    # used for non-number returns
def _BN;     # the current barnumber
def _VStop;  # confirms that the lookforward period continues the pivot trend
def _V;      # the Value at the actual pivot point
def _VBar;   # the bar number at the pivot point
def _PV;     # the previous pivot Value
def _PVBar;  # the previous pivot bar number
def _VDiff;  # the difference in values between last two pivot points
def _VDist;  # the diffence in barnumbers between last two pivot points
def _VSlope; # the Slope calculated using value and distance changes
def _VPivot; # used for the pivot point connector line only
##############

_BN  = BarNumber();
_nan = Double.NaN;
_VStop =
fold a = 1 to PF + 1
with b = 1 while b
do if HL > 0 then
dat > GetValue(dat, -a) else
dat < GetValue(dat, -a) ;
if (HL > 0) {
_V = if _BN > PB and dat == Highest(dat, PB) and _VStop
then dat else _nan;
} else {
_V = if _BN > PB and dat == Lowest(dat, PB) and _VStop
then dat else _nan;
}
;
_VBar   = if !IsNaN(_V) then _BN else _VBar[1];
_PV     = if !IsNaN(_V) then GetValue(dat, _BN - _VBar[1]) else _PV[1];
_PVBar  = if   _VBar != _VBar[1]
then _PVBar[1] else _VBar;
_VDiff  = AbsValue(_V) - AbsValue(_PV);
_VDist  = _BN - _PVBar;
_VSlope = if _V > _PV  then 1 else
if _V < _PV  then -1 else 0;
if (HL > 0) {
_VPivot = _BN >= HighestAll(_PVBar);
} else {
_VPivot = _BN >= LowestAll(_PVBar);
}
;
plot result = if !IsNaN(_V) and _VStop then _V else _nan; #return the final _dat value at the most recent pivot point (same as V)
}

def ph =  findpivots(_H, 1, length_forward, length_backward)."result";
def pl =  findpivots(_L, -1, length_forward, length_backward)."result";

def ph_1 = if !isnan(ph) then ph else ph_1[1];
def pl_1 = if !isnan(pl) then pl else pl_1[1];

def hh = !isnan(ph) and ph > ph_1[1];
def ll = !isnan(pl) and pl < pl_1[1];

#--------------------------------------------------------------
def LastTF = CompoundValue(1, if isNaN(ph) then LastTF[1] else ph, ph);
def LastBF = CompoundValue(1, if isNan(pl) then LastBF[1] else pl, pl);
#--------------------------------------------------------------

plot HLine =  LastTF ; #,color=red,style=circles,linewidth=1,offset=-1)
plot LLine =  LastBF ; #,color=green,style=circles,linewidth=1,offset=-1)
HLine.SetPaintingStrategy(PaintingStrategy.POINTS);
HLine.SetDefaultColor(Color.DARK_GREEN);
LLine.SetPaintingStrategy(PaintingStrategy.POINTS);
LLine.SetDefaultColor(Color.DARK_RED);

Last edited by a moderator:
Looks great thank you so much

Thank you for sharing

Does anyone know how the S/R lines are able to be drawn on Mobile? I can't figure out why it works on this study, but not others.

87k+ Posts
420 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?