Rolling Pivot Range Indicator for ThinkorSwim

D

Danthaman

New member
Can anyone convert the Pinescript of TradingView to TOS below. Thanks.

Here is the actual 3 day rolling pivot range indicator as detailed in Mark Fisher's book The Logical Trader.
Code:
study(title="Rolling Pivot Indicator", shorttitle="RPR", overlay = true)
width = input(3, minval=1)
xHigh  = security(tickerid,"D", high[1])
xHigh2  = security(tickerid,"D", high[2])
xHigh3  = security(tickerid,"D", high[3])
xLow   = security(tickerid,"D", low[1])
xLow2   = security(tickerid,"D", low[2])
xLow3   = security(tickerid,"D", low[3])
xClose = security(tickerid,"D", close[1])

mh = if xHigh >= xHigh2 and xHigh>=xHigh3
    xHigh
else
    if xHigh2 >= xHigh and xHigh2>=xHigh3
        xHigh2
    else
        xHigh3
 
ml = if xLow <= xLow2 and xLow<=xLow3
    xLow
else
    if xLow2 <= xLow and xLow2<=xLow3
        xLow2
    else
        xLow3


cpp1 = (xClose + mh +ml)/3
cpp2 = (mh + ml)/2
diff = cpp1 -cpp2

PH = (cpp1 + diff)
PL = (cpp1 - diff)

plot(PH, color=yellow, title="PH", style = line, linewidth = width)
plot(PL, color=black, title="PL", style = line, linewidth = width)

positive = low>PL ? green : na
negative = high<PL ? red : na
bgcolor(positive, transp=75, offset=0)
bgcolor(negative, transp=75, offset=0)

//pos = low<PH and low>=PL ? olive : na
//neg = high<PL and high>=PH ? maroon : na
//bgcolor(pos, transp=75, offset=0)
//bgcolor(neg, transp=75, offset=0)
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
I was looking at this indicator a few days ago, decided to convert it for our Warehouse members. Since you asked, I'll just share it here with everyone.

Code:
# True Rolling Pivot Range Indicator
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/AAzaP2Rn-True-Rolling-Pivot-Range-Indicator/

input aggregationPeriod = AggregationPeriod.DAY;
def d_high = high(period = aggregationPeriod);
def d_low = low(period = aggregationPeriod);
def d_close = close(period = aggregationPeriod);

def xHigh = d_high[1];
def xHigh2 = d_high[2];
def xHigh3 = d_high[3];
def xLow = d_low[1];
def xLow2 = d_low[2];
def xLow3 = d_low[3];
def xClose = d_close[1];

def mh = if xHigh >= xHigh2 and xHigh>=xHigh3 then

    xHigh
else
    if xHigh2 >= xHigh and xHigh2>=xHigh3 then

        xHigh2
    else
        xHigh3;

def ml = if xLow <= xLow2 and xLow<=xLow3 then

    xLow
else
    if xLow2 <= xLow and xLow2<=xLow3 then

        xLow2
    else
        xLow3;


def cpp1 = (xClose + mh + ml) / 3;
def cpp2 = (mh + ml) / 2;
def diff = cpp1 - cpp2;

def PH = (cpp1 + diff);
def PL = (cpp1 - diff);

plot line_h = PH;
plot line_l = PL;

line_h.SetDefaultColor(GetColor(1));
line_l.SetDefaultColor(GetColor(0));
 
Last edited:
D

Danthaman

New member
BenTen,

I created the script and put aggregation period at 3 days. it is extending the range over 3 days of trading not taking the rolling pivots from the last three days. the plot is well below the price action for AAPL but in trading view, AAPL is trading in the pivot range and well above in TOS.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Danthaman There was an error in the code. I just fixed it. Try again. Keep in mind that the TradingView version uses the "Day" setting. And that's also the default for the ToS version. If you decided to change to "3 Days", it will not look the same as the one on TradingView.
 

Top