Plot pivot levels based on RTH only


Category:
0
0

Hello,

I am trying to build a script to plot RTH data on RTH and ETH charts.

For instance, I would like to plot RTH-only pivot point (high + low + close) / 3 on an ETH chart of /ES

 

I have tried to use some of your code, buy my results are inconsistent and they also plot on every bar rather than one horizontal bar across the day.

 

Here is the code I have tried:

<pre>

def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();
def extendedSessionHours = RegularTradingStart(GetYYYYMMDD()) >= GetTime();
def extendedSessionStart = regularSessionHours[1] and extendedSessionHours;
def regularSessionStart = extendedSessionHours[1] and regularSessionHours;
def extendedSessionHigh = CompoundValue(1, if extendedSessionStart then high else if extendedSessionHours then Max(high, extendedSessionHigh[1]) else extendedSessionHigh[1], 0);

def extendedSessionLow = CompoundValue(1, if extendedSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1], 0);

def regularSessionHigh = CompoundValue(1, if regularSessionStart then high else if regularSessionHours then Max(high, regularSessionHigh[1]) else regularSessionHigh[1], 0);

def regularSessionLow = CompoundValue(1, if regularSessionStart then low else if regularSessionHours then Min(low, regularSessionLow[1]) else regularSessionLow[1], 0);
def regularSessionClose = CompoundValue(1, if regularSessionStart then close else if regularSessionHours then Min(close, regularSessionClose[1]) else regularSessionClose[1], 0);

plot ydayHigh = HighestAll(if IsNan(regularsessionhigh[-1]) then regularsessionhigh else double.nan) ;

plot PP = (regularSessionHigh[1] + RegularSessionLow[1] + close[1]) / 3;

</pre>

 

Thank you for your help.

Marked as spam
Posted by (Questions: 2, Answers: 3)
Asked on April 13, 2020 5:49 pm
222 views
0
Private answer

How does your request differ from  the standard pivot levels chart study included with Thinkorswim? The built in version already computes pivot levels from the Daily time frame, which for futures only includes regular trading hours.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 13, 2020 6:58 pm
0
This is not true. TOS pivot points change based on extended hours being toggled on/off. Take /ES for example: Off: pp=2780 On: pp= 2766~
( at April 13, 2020 7:13 pm)
0
I should add that I am trying to calculate these pivots based on US Equities RTH hours. So user-defined start and stop times would be ideal.
( at April 14, 2020 6:00 am)
0
Private answer

Thanks for providing those clarifications in the comment section. So I see this requires that we have a clear start time and end time as a user input that can be adjusted through edit studies window. The inputs for start and end time will need to be adjusted to match the timezone you have selected on the chart. In addition to this the end time will need to be adjusted for the time FRAME you select for the chart. Comments included with that user input explain this and provide examples for the 5 min and 15 min time frames.

FYI: Your attempted use of the function named RegularTradingStart() doesn't work for this.

With those time frames we can get the highest high, lowest low and target close for each day. Then we carry those static values forward into the next day. From there we can perform the simple match to compute the daily pivot based on that specific span of time you selected through user inputs.

Here is the code for that. Quite complex and I feel a bit of a twinge giving this away for free. Hope my paying clients are not upset that I would give away something this complex for free in the Q&A forum.

input startTime = 930;
# end time input must be adjusted for time frame {5 min = 1555, 15 min = 1545 etc..}
input endTime = 1545;
def afterStartTime = SecondsFromTime(startTime) >= 0;
def beforeEndTime = SecondsTillTime(endTime) >= 0;
def targetTimeSpan = afterStartTime and beforeEndTime;
def begin = targetTimeSpan and !targetTimeSpan[1];
rec priceH = if begin then high else if high > priceH[1] then high else priceH[1];
rec priceL = if begin then low else if low < priceL[1] then low else priceL[1];
def end = targetTimeSpan and !targetTimeSpan[-1];
rec trackHigh = if end then priceH else trackHigh[1];
rec trackLow = if end then priceL else trackLow[1];
rec trackClose = if end then close else trackClose[1];
plot pp = (trackHigh + trackLow + trackClose) / 3;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 14, 2020 7:57 am