Central Pivot Range (CPR) Indicator for ThinkorSwim

Hihi, i am using CPR tos script but how can i used it for scans?

Condition: 5min closed is above CPR range?

The current code if I put 5mins vs the CPR, it has some error like secondary period not allowed: 5min.

can someone enlighten me? Sorry I am a newbie and not so familiar with TOS yet.
 
Last edited:
Hihi, i am using CPR tos script but how can i used it for scans?

Condition: 5min closed is above CPR range?

The current code if I put 5mins vs the CPR, it has some error like secondary period not allowed: 5min.

can someone enlighten me? Sorry I am a newbie and not so familiar with TOS yet.
There is no work-around to the limitation of no secondary aggregations can be used in the TOS Scan Hacker.
Asecondaryaggregation.png

You can read about it here:
https://tlc.tdameritrade.com.sg/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters
 
May I know whether have code for watchlist ,the price touch the CPR line indicate 1, else 0. Many thanks
Secondary aggregations cannot be used in watchlists. See the post above yours for more information.
 
Hey @BenTen is there a way to use this for futures. When I use on the 5 day 5 minute chart the CPR ranges are not accurate when comparing them to the trading view CPR values.
 
Hey @BenTen is there a way to use this for futures. When I use on the 5 day 5 minute chart the CPR ranges are not accurate when comparing them to the trading view CPR values.
Hi Slade,

The difference is based on one platform using the "settlement" price as the close price, and the other using "last" price.

For example, you'll see here https://www.cmegroup.com/markets/equities/nasdaq/e-mini-nasdaq-100.settlements.html# that today's (1/20/2022) high, low, settlement, and close are
high = 15,340.25
low = 14,646.75
last = 14,725.75
settlement = 14,841.00

TradingView calculates the central pivot as (high + low + settlement price) / 3.
(15,340.25 + 14,646.75 + 14,841.00) / 3 = $14,942
ThinkOrSwim calculates the central pivot as (high + low + close price) / 3
(15,340.25 + 14,646.75 + 14,725.75) / 3 = $14,904

There is a way to get thinkorswim to calculate the pivot the same way as trading view. You'll want to create a new input to let the user enter settlement price, then change the code to use the input value as part of the calculation.

I've implemented a basic version below.

Code:
# CPR with Settlement
# by bigboss
#
# Some platforms, like Trading View, calculate CPR and pivots for futures using "settlement" price.
# Thinkorswim uses the "last" price.
# Override the price used for close with the settlement price input. Values can be found on the
# CME group website.

input settlement_price = 0.00;
input period = AggregationPeriod.DAY;

def h = high(period=period)[1];
def l = low(period=period)[1];
def c = if settlement_price > 0 then settlement_price else close(period=period)[1];

plot cp = (h + l + c)/3;

def _bc = (h + l)/2;
def _tc = (cp - _bc) + cp;

plot tc = max(_bc,_tc);
plot bc = min(_bc,_tc);


cp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
tc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

cp.SetDefaultColor(Color.MAGENTA);
tc.SetDefaultColor(Color.VIOLET);
bc.SetDefaultColor(Color.VIOLET);
 
Hi, thank you all for building this script. It works perfectly for me. I made a scanner for it; below is the link if anyone is interested.

I added a variable named "narrow" to define how narrow you want the CPR to be, with 1 being the thinnest possible. Currently set to 3.

Also, make sure to run the scanner at the end of the day in order to get the final close value.

CPR Scanner link: http://tos.mx/vietPEB

CPR indicator link: http://tos.mx/5sAqhmO

1685741281629.png
 

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