# PersonsPivots (PPS) Indicator for ThinkorSwim

#### 2sureshk

##### Member
I am looking for help on PPS indicator strategy. I see this indicator is good in 4 hrs and 2 hrs timeframe. Please share if there an existing strategy or help with code if possible to write as backtest strategy.

Mobius made a replica of the PersonsPivots indicator.

Code:
``````# PPS replica
# Mobius

input n  = 2;
input n2 = 7;
input n3 = 5;
input n4 = 4;

def c = close;

plot data  = Average(Inertia(c, n), n2);
plot data2 = ExpAverage(Inertia(ohlc4, n3), n4);

#Stan this is a better statement for the arrows in the PPS:
plot ArrowUP = data crosses above data2 and close crosses above data2;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);

Plot ArrowDN = close crosses below data2 and data crosses below data2;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);``````

#### tomsk

##### Well-known member
VIP
Note that PPS is one of the few studies where the source code is protected and not viewable by the public. If ThinkorSwim unlocks that study so that we see how the algorithm is written, someone may possibly convert that to a strategy.

#### drdarshil16

##### New member
2019 Donor
Here is the code with alerts, although it uses PPS, but PPS original code is still not revealed. Has alerts

Code:
``````input ArrowsOn = yes;
input TracerLinesOn = no;
input PriceColorOn = Yes;

input ShowTodayOnly = no;
input ShowExtraDays = 0;
def Today =
if !ShowTodayOnly then 1 else
if GetDay() + ShowExtraDays >= GetLastDay() && GetYear() == GetLastYear() then 1 else 0;
input ArrowSpace = .233;
def space = Average(high - low) * ArrowSpace;

#Input AlertsOn = no;
def SellIt = PPS().sellsignal;

plot ppsBuy = if !Today or !ArrowsOn then Double.NaN else BuyIt - space;

plot ppsSell = if !Today or !ArrowsOn then Double.NaN else SellIt + space;
ppsSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppsSell.SetDefaultColor(Color.WHITE);
ppsSell.SetLineWeight(3);

rec PriceAtBuy = if BarNumber() == 1 then close else if !IsNaN(BuyIt[0]) then open[0] else PriceAtBuy[1];
rec PriceAtSell = if BarNumber() == 1 then close else if !IsNaN(SellIt[0]) then open[0] else PriceAtSell[1];

rec trigger = if PriceAtBuy <> PriceAtBuy[1] then -1 else if PriceAtSell <> PriceAtSell[1] then 1 else trigger[1];
plot BuyPrice = if TracerLinesOn && trigger == -1 then PriceAtBuy else Double.NaN;
plot SellPrice = if TracerLinesOn && trigger == 1 then PriceAtSell else Double.NaN;
SellPrice.SetDefaultColor(Color.RED);
SellPrice.SetPaintingStrategy(PaintingStrategy.POINTS);

AssignPriceColor(if !PriceColorOn then Color.CURRENT else if trigger == 1 then Color.RED else Color.GREEN);``````

#### ssaeed73

##### Member
PPS Buy and Sell watchlist:

Code:
``````def buy = !IsNaN(PPS().”BuySignal”[1]);
def sell = !IsNaN(PPS().”SellSignal”[1]);

AddLabel(yes, if buy then "Buy Fired" else if  sell then "Sell Fired" else " ");
AssignBackgroundColor(if buy then color.green else if sell then color.red else color.black);``````

Last edited by a moderator:

#### boogieG

##### New member
@horserider I was also unsure about the PPS signal since the source code isnt available but I tried my hand at referencing the buy signal in "def ppsBuy = PPS().BuySignal is true within 3 bars;" as I've seen studies referenced this way in the past. There may be an issue as far as input length for the PPS now that I am looking at it a second time and thinking about how the study works. Would an IsNaN function have to be used for pps? I am not sure if it is a number output or not.

#### horserider

##### Well-known member
VIP
@boogieG Yes hidden code makes it difficult. I decided to play a bit and since the PPS is just 2 moving averages I believe you can closely approximate the PPS signals with just doing your own moving average crosses. Simple moving averages of 4 and 7. Put the crosses into your code and that may solve the PPS issue. Feel free to experiment with other types of moving averages if you think you can get a better match. Hmmm why hide what appears to be very simple code.

#### dougn

##### Member
2019 Donor
I have since acquired a column that seems to work fine. PPS may not be the holy grail but it sure can help alert you to potential reversals in any time frame.

Code:
``````###### PPS ###############################
def xDays = 1;
def ppsSell = PPS().SellSignal;
def sell = !IsNaN(ppsSell);

plot value =
if buy then 4
else if sell then 1
else 0;
value.assignValueColor(
if value == 4 then color.light_green
else if value == 1 then color.dark_red
else color.black);
assignBackgroundColor(
if value == 4 then color.light_green
else if value == 1 then color.dark_red
else color.black);
##########################################``````

#### Gimics

##### New member
I'm really (really) new to this stuff, but I think some of the above posts were asking for something like this (uses the PPS() buy and sell signals to create orders for a strategy).

Doesn't actually uncover what was coded for PPS, but uses the outputs.

Code:
``````plot buySignal = PPS().buysignal;
plot sellSignal = PPS().sellsignal;
plot slowAvg = PPS().slowavg;
plot fastAvg = PPS().fastavg;

AddOrder(OrderType.SELL_TO_CLOSE, sellSignal, tickColor = Color.GREEN, arrowColor = Color.GREEN, name = "PPS Sell");``````

#### I_make_no_cents

##### New member
As others have tried, I am trying to find something close to whatever formula weights the crossing SMA's to give the buy / sell signals with the PPS. If anyone has any input besides the composition of the averages, please do share. And for anyone that wants the PPS as a color coded column for a watchlist or in a scan, please see the code below. It really helps for confirmation on entry / exit. I've had it for a few years and most of the credit goes out to Pete Han and probably some other sources...I just remember finding some code, tweaking it and asking for some help. Its just to use as a column code, so you can adjust the timeframes in the "create custom code" window and save it as such. I don't think it is able to be adjusted to give exact prices at the time of the signal execution, just the close of the particular candle. If that is possible it would be a great addition. Enjoy.

Code:
``````#################################################
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtSell = if sell then close else closeAtSell[1];
rec state = if buy then 1 else if sell then -1 else state[1];
plot data = if state == 1 then closeAtBuy else closeAtSell;
data.AssignValueColor(if state == 1 then Color.BLACK else if state == -1 then Color.WHITE else Color.BLACK);
AssignBackGroundColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.CURRENT);
##################################################``````

If the mods can grab that pic an attach it to this post, I'd appreciate it.

#### stocksniper

##### Member
Does anyone have the PPS script in Multi TimeFrame, for example i would like to use the up and down arrows of a PPS of 1HR into a lower timeframe. If anyone has it can you please share it, or if anyone can make it I would greatly apprceated.

#### BenTen

Staff member
Staff
VIP
The source code for the PPS indicator is not available in ThinkorSwim, I had to use a replica by Mobius and turn it into an MTF indicator.

Code:
``````# PPS Replica_Mobius
# Added MTF by BenTen at UseThinkScript.com

input aggregationPeriod = AggregationPeriod.DAY;
def close = close(period = aggregationPeriod);
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);

def ohlc4 = (open + high + low + close) / 4;

input n  = 2;
input n2 = 7;
input n3 = 5;
input n4 = 4;

def c = close;

plot data  = Average(Inertia(c, n), n2);
plot data2 = ExpAverage(Inertia(ohlc4, n3), n4);

#Stan this is a better statement for the arrows in the PPS:
plot ArrowUP = data crosses above data2 and close crosses above data2;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);

Plot ArrowDN = close crosses below data2 and data crosses below data2;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);``````

#### Robertca0724

##### New member

that look in my thinkorswim mobile.
and can i use PPS in metatrader 4 (android)?
thank u very much for hour help

#### Robertca0724

##### New member
ok...ic...this forum i just talk about TOS and this forum is managed by develop TOS , not allowed discuss another platform. correct?
sorry for my understanding

#### MerryDay

Staff member
Staff
VIP
ok...ic...this forum i just talk about TOS and this forum is managed by develop TOS , not allowed discuss another platform. correct?
sorry for my understanding
Feel free to talk about other platforms.
You asked if thinkscript can be used on MT4. The answer is no. Every trading platform has its own proprietary language. They can not be interchanged. There is no 'universal' translator.

#### Robertca0724

##### New member
Feel free to talk about other platforms.
You asked if thinkscript can be used on MT4. The answer is no. Every trading platform has its own proprietary language. They can not be interchanged. There is no 'universal' translator.
ok...i get it now.

#### fearjet

##### New member
This was in an earlier reply on this thread and I'd like to use it. It looks like it works as a watchlist. I've saved the code as a study but it does not show up in the list when I try to customize my watch list? Can someone help me? Also, where in the code does this specify which time frames? Or am I just seeing a part of the puzzle? Thanks!!

from Dec 29, 2020 post above:

As others have tried, I am trying to find something close to whatever formula weights the crossing SMA's to give the buy / sell signals with the PPS. If anyone has any input besides the composition of the averages, please do share. And for anyone that wants the PPS as a color coded column for a watchlist or in a scan, please see the code below. It really helps for confirmation on entry / exit. I've had it for a few years and most of the credit goes out to Pete Han and probably some other sources...I just remember finding some code, tweaking it and asking for some help. Its just to use as a column code, so you can adjust the timeframes in the "create custom code" window and save it as such. I don't think it is able to be adjusted to give exact prices at the time of the signal execution, just the close of the particular candle. If that is possible it would be a great addition. Enjoy.

Code:
#################################################
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtSell = if sell then close else closeAtSell[1];
rec state = if buy then 1 else if sell then -1 else state[1];
plot data = if state == 1 then closeAtBuy else closeAtSell;
data.AssignValueColor(if state == 1 then Color.BLACK else if state == -1 then Color.WHITE else Color.BLACK);
AssignBackGroundColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.CURRENT);
##################################################

#### petergluis

##### Active member
The source code for the PPS indicator is not available in ThinkorSwim, I had to use a replica by Mobius and turn it into an MTF indicator.

Code:
``````# PPS Replica_Mobius
# Added MTF by BenTen at UseThinkScript.com

input aggregationPeriod = AggregationPeriod.DAY;
def close = close(period = aggregationPeriod);
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);

def ohlc4 = (open + high + low + close) / 4;

input n  = 2;
input n2 = 7;
input n3 = 5;
input n4 = 4;

def c = close;

plot data  = Average(Inertia(c, n), n2);
plot data2 = ExpAverage(Inertia(ohlc4, n3), n4);

#Stan this is a better statement for the arrows in the PPS:
plot ArrowUP = data crosses above data2 and close crosses above data2;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);

Plot ArrowDN = close crosses below data2 and data crosses below data2;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);``````
I remove AggregationPeriod.day so that you do not need to adjust Aggregation Period in lower timeframes. I also added line color changes to follow the trend changes.

Ruby:
``````# PPS Replica_Mobius
# Added MTF by BenTen at UseThinkScript.com
def ohlc4 = (open + high + low + close) / 4;
input n  = 2;
input n2 = 7;
input n3 = 5;
input n4 = 4;
def c = close;
plot data  = Average(Inertia(c, n), n2);
plot data2 = ExpAverage(Inertia(ohlc4, n3), n4);
data.AssignValueColor(if data > data[1] then Color.cyan else Color.RED);
data2.AssignValueColor(if data2 > data2[1] then Color.cyan else Color.RED);
#Stan this is a better statement for the arrows in the PPS:
plot ArrowUP = data crosses above data2 and close crosses above data2;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_UP);
Plot ArrowDN = close crosses below data2 and data crosses below data2;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);``````

Last edited:

#### I_make_no_cents

##### New member
This was in an earlier reply on this thread and I'd like to use it. It looks like it works as a watchlist. I've saved the code as a study but it does not show up in the list when I try to customize my watch list? Can someone help me? Also, where in the code does this specify which time frames? Or am I just seeing a part of the puzzle? Thanks!!

from Dec 29, 2020 post above:

As others have tried, I am trying to find something close to whatever formula weights the crossing SMA's to give the buy / sell signals with the PPS. If anyone has any input besides the composition of the averages, please do share. And for anyone that wants the PPS as a color coded column for a watchlist or in a scan, please see the code below. It really helps for confirmation on entry / exit. I've had it for a few years and most of the credit goes out to Pete Han and probably some other sources...I just remember finding some code, tweaking it and asking for some help. Its just to use as a column code, so you can adjust the timeframes in the "create custom code" window and save it as such. I don't think it is able to be adjusted to give exact prices at the time of the signal execution, just the close of the particular candle. If that is possible it would be a great addition. Enjoy.

Code:
#################################################
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtSell = if sell then close else closeAtSell[1];
rec state = if buy then 1 else if sell then -1 else state[1];
plot data = if state == 1 then closeAtBuy else closeAtSell;
data.AssignValueColor(if state == 1 then Color.BLACK else if state == -1 then Color.WHITE else Color.BLACK);
AssignBackGroundColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.CURRENT);
##################################################

This is a script I use on columns in my watchlist. You would need to customize the columns in your watchlist and use this code in one of the "custom" tabs. You can adjust the timeframe in each custom column as needed. For more info search the forum for "custom watchlist column"

If you choose to use it as a study you would be limited to the chart time period. You would also need to incorporate a label with color changes depending on if the current price was greater or lower than the pps signal.

#### FOTM_8888

##### Active member
VIP
Here is the code with alerts, although it uses PPS, but PPS original code is still not revealed. Has alerts

Code:
``````input ArrowsOn = yes;
input TracerLinesOn = no;
input PriceColorOn = Yes;

input ShowTodayOnly = no;
input ShowExtraDays = 0;
def Today =
if !ShowTodayOnly then 1 else
if GetDay() + ShowExtraDays >= GetLastDay() && GetYear() == GetLastYear() then 1 else 0;
input ArrowSpace = .233;
def space = Average(high - low) * ArrowSpace;

#Input AlertsOn = no;
def SellIt = PPS().sellsignal;

plot ppsBuy = if !Today or !ArrowsOn then Double.NaN else BuyIt - space;

plot ppsSell = if !Today or !ArrowsOn then Double.NaN else SellIt + space;
ppsSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppsSell.SetDefaultColor(Color.WHITE);
ppsSell.SetLineWeight(3);

rec PriceAtBuy = if BarNumber() == 1 then close else if !IsNaN(BuyIt[0]) then open[0] else PriceAtBuy[1];
rec PriceAtSell = if BarNumber() == 1 then close else if !IsNaN(SellIt[0]) then open[0] else PriceAtSell[1];

rec trigger = if PriceAtBuy <> PriceAtBuy[1] then -1 else if PriceAtSell <> PriceAtSell[1] then 1 else trigger[1];
plot BuyPrice = if TracerLinesOn && trigger == -1 then PriceAtBuy else Double.NaN;
plot SellPrice = if TracerLinesOn && trigger == 1 then PriceAtSell else Double.NaN;
SellPrice.SetDefaultColor(Color.RED);
SellPrice.SetPaintingStrategy(PaintingStrategy.POINTS);

AssignPriceColor(if !PriceColorOn then Color.CURRENT else if trigger == 1 then Color.RED else Color.GREEN);``````
hello it is scan for this great system? thanks in advance

## 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
• 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?