Capture PreMarket Open and Close Price For ThinkOrSwim

Max71

New member
Hello,

I would like to capture Open price at Pre market open time i.e. 0700 EST and close price at Pre market close time i.e. 0920. How do I do that?

I tried this but does not work. What am I doing wrong here? Is there better way to do this?

def PM_OpenTime = if SecondsFromTime (0702) == 0 and SecondsTillTime(0702) == 0 then 1 else 0 ;
def PM_CloseTime = if SecondsFromTime (0925) == 0 and SecondsTillTime(0925) == 0 then 1 else 0 ;


AddLabel(yes, "PM_OP=" +PM_OpenPrice );
AddLabel(yes, "PM_CP=" + PM_ClosePrice);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

input Start_Time = 0400;
input End_Time = 0930;

def PM_OpenPrice = if SecondsTillTime(Start_Time) == 0 then open else PM_OpenPrice[1] ;
def PM_ClosePrice = if SecondsTillTime(End_Time) == 0 then open else PM_ClosePrice[1];

AddLabel(yes, "PM_OP=" +PM_OpenPrice, color.white);
AddLabel(yes, "PM_CP=" + PM_ClosePrice, color.white);
 
Here is code that captures premarket or postmarket High, depending on when you run it. To find the low, just copy this code and change high to low.

Code:
input Globex_Open = 1600;
input Globex_Close = 0930;

def globexOpen = if(secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>=0, 1, 0);
def globexReset = if globexOpen and !globexOpen[1] then 1 else 0;

rec globexHigh = compoundValue(1, if((high > globexHigh[2] and globexOpen) or globexReset, high,globexHigh[2]),high);


AddLabel(1, "$" + globexHigh, if globexHigh < 0 then color.RED else color.GREEN);
 
Thanks for your prompt reply.

I am using stock-hacker to scan the bar in premarket that there is no bar higher than previous high or vice versa.

for the compoundValue, is it returned in the form of array?

How do I convert the compoundValue into say, highest value among the premarket time?

Code:
input Globex_Open = 1600;
input Globex_Close = 0930;

def globexOpen = if(secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>=0, 1, 0);
def globexReset = if globexOpen and !globexOpen[1] then 1 else 0;

rec globexHigh = compoundValue(1, if((high > globexHigh[2] and globexOpen) or globexReset, high,globexHigh[2]),high);

plot scan = globexHigh < high
 
That's exactly what this does. You just need to make sure you set your aggregation to 1m and include Extended Hours. The above will only tell you what the premarket or post-market (if after regular trading hours) high was. If you're wanting something allows you to scan for a stock above, say 10% in premarket or post market, you'd use this:

Code:
#Wizard text: The
#Wizard input: price
#Wizard text: has moved
#Wizard input: operator
#Wizard input: percent_change
#Wizard text: %  in Premarket trading

input closing_time = 0930;
input open_time = 0400;
input price = Open;
input operator = {default "greater than"};
input percent_change = +10.00;


def time_until_close = SecondsTillTime(open_Time);
def time_until_open = SecondsTillTime(closing_time);
def closing_bell = time_until_close == 0;
rec closing_price = CompoundValue(1, if closing_bell then price else closing_price[1], price);
def after_closing_bell = time_until_close <= 0;
def before_opening_bell = time_until_open  >= 0  ;
def Premarket_percent_change = 100 * (price / closing_price - 1);
def meet_scan_criteria;

switch (operator) {
case "greater than":
    meet_scan_criteria = Premarket_percent_change >= percent_change;

}

plot scan = (after_closing_bell or before_opening_bell) AND meet_scan_criteria;
 
Thanks for your prompt reply.

I am using stock-hacker to scan the bar in premarket that there is no bar higher than previous high or vice versa.

for the compoundValue, is it returned in the form of array?

How do I convert the compoundValue into say, highest value among the premarket time?

Code:
input Globex_Open = 1600;
input Globex_Close = 0930;

def globexOpen = if(secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>=0, 1, 0);
def globexReset = if globexOpen and !globexOpen[1] then 1 else 0;

rec globexHigh = compoundValue(1, if((high > globexHigh[2] and globexOpen) or globexReset, high,globexHigh[2]),high);

plot scan = globexHigh < high


To answer your question, yes. From what I understand, CompoundValue loops through whatever time period you have set doing exactly what you tell it to do. If it hits the time specified in the "globex_open" and "globex_close", it either begins to look for what you're telling it to look for or stop looking. I just started using this language a few days ago, things are starting to do exactly what I tell them. This was one of the originals codes I put together -- using snippets from people on here -- but so far, this community has been a goldmine.
 
Thank for the replies.

But this only can find whether in premarket the stock gap up or not.

My scanner requirements are:
1. get the previous day high and low
2. and need to make sure there is the candle in premarket there is no candle higher/low exceed the previous day high and low.

But I not sure how to convert this into TOS. % return is unable to know whether the candle has exceeded and drop back to the range.
 
Thank for the replies.

But this only can find whether in premarket the stock gap up or not.

My scanner requirements are:
1. get the previous day high and low
2. and need to make sure there is the candle in premarket there is no candle higher/low exceed the previous day high and low.

But I not sure how to convert this into TOS. % return is unable to know whether the candle has exceeded and drop back to the range.
Hi Harry - I decided to finally go through the learning center as some things were still not making complete sense to me. Now that I finally understand things to a much higher degree, I can help you with this, but before I do, I just want to clarify your question.

You want a scanner to find the high and low of the previous day and ONLY show results of stocks that have not yet exceeded high or dropped passed the low? Or are you mainly concerned with the ones that have not yet exceeded the highs of the previous day?

Edit: I also need to know if you want post market from the previous day to act as part of the previous day high or if that should act as what you'd consider exceeding the high/low.
 
Last edited:
This is a shot in the dark, but I will ask anyway: I have a friend that gave me this strategy but it is in Easylanguage and he has no idea how to write it in Thinkscript. It seems to be a fairly simply strategy, but I have no experience with this sort of stuff. I would really appreciate any help.

input: length1(20),length2(3); //StopL(500),Proft(1000);

if close<close[200] and close>close[length1] and close<close[length2] and close>open then buy next bar at market;

if close>close[200] and close<close[length1] and close>close[length2] and close<open then sellshort next bar at market;

if barssinceentry>10 then Begin
sell next bar at market;
buytocover next bar at market;
end;

//SetStopLoss(StopL);
//SetProfitTarget(Proft);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
212 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