plot premarket high , low and close for 3 minute aggregation

shakib3585

Active member
VIP
Greetings all,

I am trying to plot the premarket high , low and close for 3 minute aggregation period. I came up with the following plot but am a bit unsure if I did the closing price for the 3 minute premarket correctly. Please advice if the following code is right for pre -market high, low and closing plot for 3 minute aggregation.

Thank you very much



Code:
#Pre market high, low and close for 3 minute aggregation

input startTime = 400;
input endTime = 929;
def timeUntilClose = SecondsTillTime(endTime);

def timeUntilOpen = SecondsTillTime(startTime);
def targetPeriod = timeUntilClose > 0;
rec targetPeriodHigh = if targetPeriod and !targetPeriod[1] then high(period = aggregationPeriod.THREE_MIN) else if targetPeriod and high(period = aggregationPeriod.THREE_MIN) > targetPeriodHigh[1] then high(period = aggregationPeriod.THREE_MIN) else targetPeriodHigh[1];
rec targetPeriodLow = if targetPeriod and !targetPeriod[1] then low(period = aggregationPeriod.THREE_MIN) else if targetPeriod and low(period = aggregationPeriod.THREE_MIN) < targetPeriodLow[1] and low(period = aggregationPeriod.THREE_MIN) > 0 then low(period = aggregationPeriod.THREE_MIN) else targetPeriodLow[1];
rec targetPeriodclose =  if targetPeriod and !targetPeriod[1] then close(period = aggregationPeriod.THREE_MIN) else targetPeriodclose[1];

plot pmHigh = targetPeriodHigh;
plot pmLow = targetPeriodLow;
plot pmclose = targetPeriodclose;
 
Last edited:
Solution
Greetings all,

I am trying to plot the premarket high , low and close for 3 minute aggregation period. I came up with the following plot but am a bit unsure if I did the closing price for the 3 minute premarket correctly. Please advice if the following code is right for pre -market high, low and closing plot for 3 minute aggregation.

Thank you very much



Code:
#Pre market high, low and close for 3 minute aggregation

input startTime = 400;
input endTime = 929;
def timeUntilClose = SecondsTillTime(endTime);

def timeUntilOpen = SecondsTillTime(startTime);
def targetPeriod = timeUntilClose > 0;
rec targetPeriodHigh = if targetPeriod and !targetPeriod[1] then high(period = aggregationPeriod.THREE_MIN) else if targetPeriod and...
Greetings all,

I am trying to plot the premarket high , low and close for 3 minute aggregation period. I came up with the following plot but am a bit unsure if I did the closing price for the 3 minute premarket correctly. Please advice if the following code is right for pre -market high, low and closing plot for 3 minute aggregation.

Thank you very much



Code:
#Pre market high, low and close for 3 minute aggregation

input startTime = 400;
input endTime = 929;
def timeUntilClose = SecondsTillTime(endTime);

def timeUntilOpen = SecondsTillTime(startTime);
def targetPeriod = timeUntilClose > 0;
rec targetPeriodHigh = if targetPeriod and !targetPeriod[1] then high(period = aggregationPeriod.THREE_MIN) else if targetPeriod and high(period = aggregationPeriod.THREE_MIN) > targetPeriodHigh[1] then high(period = aggregationPeriod.THREE_MIN) else targetPeriodHigh[1];
rec targetPeriodLow = if targetPeriod and !targetPeriod[1] then low(period = aggregationPeriod.THREE_MIN) else if targetPeriod and low(period = aggregationPeriod.THREE_MIN) < targetPeriodLow[1] and low(period = aggregationPeriod.THREE_MIN) > 0 then low(period = aggregationPeriod.THREE_MIN) else targetPeriodLow[1];
rec targetPeriodclose =  if targetPeriod and !targetPeriod[1] then close(period = aggregationPeriod.THREE_MIN) else targetPeriodclose[1];

plot pmHigh = targetPeriodHigh;
plot pmLow = targetPeriodLow;
plot pmclose = targetPeriodclose;

if you want to find the single highest high , over a 5.5 hour period, there is no reason to specify 2nd aggregation.
just use high.
mentioning '3 minutes' is irrelevent. the high is the high. it doesn't matter what time period of data you look at.

for your end time, use 930.
then use < 930 to check the period.
by using 929 and < , you are excluding 930, so it would be skipped at 1 minute.

you didn't use the start time, so any data from midnight to 4am is also included.

use fromtime with the start time, not till.


Code:
# plot pre hi lo close, levels, after the pre period.
def na = double.nan;
def start = 400;
def end = 930;
def newday = (getday() <> getday()[1]);
def period =  ( SecondsFromTime(start) >= 0 and Secondstilltime(end) > 0 );

def hi = if newday then 0
else if !period then hi[1]
else if high > hi[1] then high
else hi[1];

def lo = if newday then 0
else if !period then lo[1]
else if low < lo[1] then low
else lo[1];

def cls = if newday then 0
else if !period then cls[1]
else close;

# plot horz lines, after the period
plot zhi = if !period and hi > 0 then hi else na;
plot zlo = if !period and lo > 0 then lo else na;
plot zcls = if !period and cls > 0 then cls else na;
#
 
Last edited:
Solution
if you want to find the single highest high , over a 5.5 hour period, there is no reason to specify 2nd aggregation.
just use high.
mentioning '3 minutes' is irrelevent. the high is the high. it doesn't matter what time period of data you look at.

for your end time, use 930.
then use < 930 to check the period.
by using 929 and < , you are excluding 930, so it would be skipped at 1 minute.

you didn't use the start time, so any data from midnight to 4am is also included.

use fromtime with the start time, not till.


Code:
# plot pre hi lo close, levels, after the pre period.
def na = double.nan;
def start = 400;
def end = 930;
def newday = (getday <> getday[1]);
def period =  ( SecondsFromTime(start) >= 0 and Secondstilltime(end) > 0 );

def hi = if newday then 0
else if !period then hi[1]
else if high > hi[1] then high
else hi[1];

def lo = if newday then 0
else if !period then lo[1]
else if low < lo[1] then low
else lo[1];

def cls = if newday then 0
else if !period then cls[1]
else close;

# plot horz lines, after the period
plot zhi = if !period and hi > 0 then hi else na;
plot zlo = if !period and lo > 0 then lo else na;
plot zcls = if !period and cls > 0 then cls else na;
#
thank you @halcyonguy
 

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