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;
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);
 

dougn

Member
2019 Donor
May be quite late but I do happen to have PPS/PMC built into a study that also can be used as a scan. I tried to install it as a watchlist column but lack the skill to eliminate "Nan's" ...
Code:
input xDays = 1;
def ppsBuy = PPS().BuySignal;
def ppsSell = PPS().SellSignal;
def buy = !IsNaN(ppsBuy);
def sell = !IsNaN(ppsSell);
def pmcDiff = PMC().Diff;
def pmcMA = PMC().DiffMA;
def lightBlue = pmcDiff > 0 and pmcDiff > pmcMA;
def darkBlue = pmcDiff > 0 and pmcDiff < pmcMA; def red = pmcDiff < 0 and pmcDiff < pmcMA; def magenta = pmcDiff < 0 and pmcDiff > pmcMA;
def confirmDaysBullish = (Sum(lightBlue, xDays) + Sum(magenta, xDays)) >= xDays;
def confirmDaysBearish = (Sum(red, xDays) + Sum(darkBlue, xDays)) >= xDays;
def confirmedBuy = buy and confirmDaysBullish;
def confirmedSell = sell and confirmDaysBearish;
def buyWithReversal = magenta[1] and lightBlue and Highest(buy, xDays) > 0;
def sellWithReversal = lightBlue[1] and red and Highest(sell, xDays) > 0;
# use this to scan for PPS buy signals that follow bullish PMC
plot scan = confirmedBuy;
# use this to scan for PPS sell signals that follow bearish PMC
#plot scan = confirmedSell;
# use this to scan for bullish PMC reversals that follow a PPS buy
#plot scan = buyWithReversal;
# use this to scan for bearish PMC reversals that follow a PPS sell
#plot scan = sellWithReversal;
 

ssaeed73

Member
Hi everyone, new to ThinkorSwim and to this site. Hoping someone can lend me a hand with this problem.

I am trying to get the PPS Buy and Sell signals in a column in my watchlist and have been able to do so using the code below. The issue is that I run this on the 5 min chart and the signal triggers on and off as the condition for Buy and Sell is being formed. What I would like to do is to only get the notification once the Buy or Sell signal is confirmed on one 5 min candle and that the alert stay on for at least the next five minutes before it goes away. Is that possible? Thanks in advance!

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

AddLabel(buy, "Buy Fired", color.black);
AddLabel(sell, "Sell Fired", color.black);
AddLabel(!buy and !sell, " ", color.black);

AssignBackgroundColor(if buy then color.white else if sell then color.white else color.black);
 

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.
 

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 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);
##########################################
 

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.
 

tradebyday

Active member
@Joules360 There is no auto-trading in TOS.. setting the code up as a strategy will just allow you to see backtesting results and will plot the buy/sell orders as they already have been plotted in the code above
 

Kiriland

New member
Hello Guys,

I am hoping to get some help is building an watchlist "indicator".

Is based on PPS study.

I used a code I found in the forum that is great, but i need some improvement. Now the indicator is showing only then event happens. PPS is triggered (Buy/ Sell). What i need is to get an indicator that is sensitive not only to a single event, but to count how many bars ago did happen. Example on 5 min chart if a buy/sell signal was triggered 15m ago I want in my added field in the watchlist to appear "buy -3" is 20 min "buy -4" same with the same. I assume this will be a loop code then this is all I have. I am adding as well the code I already have. It will be great is the color changes as well in the event is a buys is a regular green, if it happened a few bars ago dark green with text inside on the number of bars and same for sell signal

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

AddLabel(buy, "Buy Fired", color.black);
AddLabel(sell, "Sell Fired", color.black);
AddLabel(!buy and !sell, " ", color.black);

AssignBackgroundColor(if buy then color.DaRK_GREEN else if sell then color.dark_reD else color.black);

Thank you so much for the help. Regards Kiril
 

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.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");
 

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 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.
 

BenTen

Administrative
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);
 

Similar threads

Top