PersonsPivots (PPS) Indicator for ThinkorSwim

2sureshk

Member
VIP
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);
 
Note
It is not possible to exactly replicate the ToS PPS. The ToS PPS is one of the few studies where the source code is protected and not viewable by the public.

Because the ToS PPS code is not made public, it is not possible to customize the ToS PPS.
 
Last edited by a moderator:

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

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;
AddLabel(PriceColorOn, "SH PriceColorOn");

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;
#AddChartLabel(AlertsOn, "SH AlertsOn");
def BuyIt = PPS().buysignal;
def SellIt = PPS().sellsignal;

plot ppsBuy = if !Today or !ArrowsOn then Double.NaN else BuyIt - space;
ppsBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ppsBuy.SetDefaultColor(Color.WHITE);
ppsBuy.SetLineWeight(3);
Alert(ppsBuy, “PPS Buy Signal”, Alert.BAR, Sound.Ring);

plot ppsSell = if !Today or !ArrowsOn then Double.NaN else SellIt + space;
ppsSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppsSell.SetDefaultColor(Color.WHITE);
ppsSell.SetLineWeight(3);
Alert(ppsSell, “PPS Sell Signal”, Alert.BAR, Sound.Ring);


AddLabel(ArrowsOn, "WhiteArrows=SH", Color.WHITE);

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;
BuyPrice.SetDefaultColor(Color.GREEN);
BuyPrice.SetPaintingStrategy(PaintingStrategy.POINTS);
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);
 
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:
@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.
 
@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.
 
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 ppsBuy = PPS().BuySignal;
def buy = !IsNaN(ppsBuy);
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);
##########################################
 
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.BUY_TO_OPEN, buySignal, tickColor = Color.DARK_ORANGE, arrowColor = Color.DARK_ORANGE, name = "PPS Buy");
AddOrder(OrderType.SELL_TO_CLOSE, sellSignal, tickColor = Color.GREEN, arrowColor = Color.GREEN, name = "PPS Sell");
 
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 buy = !IsNaN(PPS().”buySignal”);
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtBuy = if buy then close else closeAtBuy[1];
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);
##################################################

epSaboj.jpg


If the mods can grab that pic an attach it to this post, I'd appreciate it.
 
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.
 
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);
 
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 buy = !IsNaN(PPS().”buySignal”);
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtBuy = if buy then close else closeAtBuy[1];
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);
##################################################

epSaboj.jpg
 
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:
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 buy = !IsNaN(PPS().”buySignal”);
def sell = !IsNaN(PPS().”SellSignal”);
rec closeAtBuy = if buy then close else closeAtBuy[1];
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);
##################################################

epSaboj.jpg
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.
 
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;
AddLabel(PriceColorOn, "SH PriceColorOn");

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;
#AddChartLabel(AlertsOn, "SH AlertsOn");
def BuyIt = PPS().buysignal;
def SellIt = PPS().sellsignal;

plot ppsBuy = if !Today or !ArrowsOn then Double.NaN else BuyIt - space;
ppsBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ppsBuy.SetDefaultColor(Color.WHITE);
ppsBuy.SetLineWeight(3);
Alert(ppsBuy, “PPS Buy Signal”, Alert.BAR, Sound.Ring);

plot ppsSell = if !Today or !ArrowsOn then Double.NaN else SellIt + space;
ppsSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppsSell.SetDefaultColor(Color.WHITE);
ppsSell.SetLineWeight(3);
Alert(ppsSell, “PPS Sell Signal”, Alert.BAR, Sound.Ring);


AddLabel(ArrowsOn, "WhiteArrows=SH", Color.WHITE);

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;
BuyPrice.SetDefaultColor(Color.GREEN);
BuyPrice.SetPaintingStrategy(PaintingStrategy.POINTS);
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
 
Hello,
I know this is an old thread but thought I would try my question.
The code in the beginning with pps with alerts draws lines when it triggers a signal but the lines are at the open of the trigger bar instead of the close of the trigger bar. It could also be from the open of the next bar but drawing from the open of the trigger bar is misleading. Can someone help modify this code to draw the line accurately? Thanks
 
Hello,
I know this is an old thread but thought I would try my question.
The code in the beginning with pps with alerts draws lines when it triggers a signal but the lines are at the open of the trigger bar instead of the close of the trigger bar. It could also be from the open of the next bar but drawing from the open of the trigger bar is misleading. Can someone help modify this code to draw the line accurately? Thanks

See if this helps

Screenshot-2022-12-23-130505.png
Ruby:
input ArrowsOn = yes;
input TracerLinesOn = no;
input PriceColorOn = Yes;
AddLabel(PriceColorOn, "SH PriceColorOn");

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;
#AddChartLabel(AlertsOn, "SH AlertsOn");
def BuyIt = PPS().buysignal;
def SellIt = PPS().sellsignal;

plot ppsBuy = if !Today or !ArrowsOn then Double.NaN else BuyIt - space;
ppsBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ppsBuy.SetDefaultColor(Color.WHITE);
ppsBuy.SetLineWeight(3);
Alert(ppsBuy, “PPS Buy Signal”, Alert.BAR, Sound.Ring);

plot ppsSell = if !Today or !ArrowsOn then Double.NaN else SellIt + space;
ppsSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppsSell.SetDefaultColor(Color.WHITE);
ppsSell.SetLineWeight(3);
Alert(ppsSell, “PPS Sell Signal”, Alert.BAR, Sound.Ring);


AddLabel(ArrowsOn, "WhiteArrows=SH", Color.WHITE);

rec PriceAtBuy = if BarNumber() == 1 then close else if !IsNaN(BuyIt[0]) then close[0] else PriceAtBuy[1];
rec PriceAtSell = if BarNumber() == 1 then close else if !IsNaN(SellIt[0]) then close[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;
BuyPrice.SetDefaultColor(Color.white);
BuyPrice.SetPaintingStrategy(PaintingStrategy.POINTS);
plot SellPrice = if TracerLinesOn && trigger == 1 then PriceAtSell else Double.NaN;
SellPrice.SetDefaultColor(Color.yellow);
SellPrice.SetPaintingStrategy(PaintingStrategy.POINTS);

AssignPriceColor(if !PriceColorOn then Color.CURRENT else if trigger == 1 then Color.RED else Color.GREEN);
 
See if this helps
Hi Sleepy, first thanks for posting the script for this indicator. I have been trying to use PPS indicator for some time now, but do not quite have a good enough trading system based on it.
This set-up here looks different. Is there a link to how to interpret this indicator or could you share a bit more on how I might use it in a trading strategy?

OK, I figured it out. The bar color matches the arrow direction and remains that color until the next arrow is printed. The dashed lines mark the entry point.

Boy, I sure wish I could pair this with some sort of confirmatory price action or confluence(s). Would be a great strategy. I've tried to link it to Person's PMC indicator but frankly it's just me deciding which direction to go. If arrow gives a buy signal then I look at PMC to see if that bar is positive or not. This does not mean above 0. In the PMC, pink and light blue are positive so I'd enter trade. For a sell signal, red and dark blue on the PMC for entry
The thing is, I could have easily gone a different way and said that PMC needs to be above 0 for a but and below for a sell.
I've tried to watch the videos on youtube regarding PMC but they do not really make much sense. I may be way off here anyway since I am trying to trade forex with an indicator that is comparing price to the S&P.
 
Last edited:
Hello everyone, not sure if this thread is still monitored, but it appears that the TOS native PPS does not produce the same signals at the same time as the Mobius replica version of PPS. I have attached an image showing the native TOS (big arrows) and the Mobius replica PPS (small arrows) my question is, shouldn't they align exactly? Has anyone else noticed this and is there something in the replica version that needs to be adjusted to align? If so, does anyone know what that might be? Thanks in advance.
 

Attachments

  • IMG-20230910-WA0008.jpg
    IMG-20230910-WA0008.jpg
    116.3 KB · Views: 115

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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