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