Here’s another reader request. The three day rolling pivot range. The pivots are calculated using 24 hour data (vice normal hours) which appears to be a limitation of ThinkScript’s high() and low() functions. If anyone knows a workaround, I’d love to hear it.
The formulas for the high and low pivot range are as follows:
The Pivot= (3day High + 3day Low + Close)/3
The Midpoint= (3day High + 3 day Low)/2
Pivot Range= Absolute Value (Pivot – Midpoint)
Pivot High= Pivot + Range
Pivot Low= Pivot – Range
# THREEDAYPIVOTRANGE
# (c) 2009 http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 22 Feb 2009
input timeFrame = {default DAY};
input showOnlyToday = no;
def day = getDay();
def lastDay = getLastDay();
def isToday = if(day >= lastDay, 1, 0);
def shouldPlot = if(showOnlyToday and isToday, 1, if(!showOnlyToday, 1, 0));
def HA = high(period = timeFrame)[1];
def HB = high(period = timeFrame)[2];
def HC = high(period = timeFrame)[3];
def LA = low(period = timeFrame)[1];
def LB = low(period = timeFrame)[2];
def LC = low(period = timeFrame)[3];
def C = close(period = timeFrame)[1];
def H3 = Max(Max(HA, HB), HC);
def L3 = Min(Min(LA, LB), LC);
def calc_PP = (H3 + L3 + C) / 3;
def calc_MP = (H3 + L3) / 2;
def calc_PR = AbsValue(calc_PP - calc_mp);
def calc_PH = Calc_PP + calc_PR;
def calc_PL = Calc_PP - calc_PR;
plot PH =if (shouldPlot , calc_PH, double.nan);
plot PL = if (shouldPlot , calc_PL, double.nan);
PH.setStyle(curve.POINTS);
PL.setStyle(curve.POINTS);
PH.SetDefaultColor(color.cyan);
PL.SetDefaultColor(color.yellow);
PH.SetStyle(Curve.POINTS);
PL.SetStyle(Curve.POINTS);





I have a workaround for only using market hours data. This would only work for a chart with the last 3 days and today on it, though. I’m pulling this code out of my head in thin air, so it may need debugging, but the gist is there:
def marketopen=0930;
def marketclose=1600;
def isopen=if secondsaftertime(marketopen)>=0 and secondsuntiltime(marketclose)>=0 then 1 else 0;
def markethourshigh=if isopen then high else 0;
def markethourslow=if isopen then low else 1000000;
#Then do your calcs as normal, but on your markethours versions instead:
def H3 = highestall(markethourshigh);
def L3 = lowestall(markethourslow);