Morning session range

toast

New member
Hello, I am very new to thinkscript. I want to create a script indicator that plot a horizontal line (price level line) automatically of the highest price between market open (9:30 est) and 10:05 est or any time range; check image below for example.


The box shows the range I want to check and the red arrow shows the highest price in that range.

I know it be possibly easier to just plot it manually, but I would like to use this as a trading strategy when looking for trades.
 
Solution
Hello, I am very new to thinkscript. I want to create a script indicator that plot a horizontal line (price level line) automatically of the highest price between market open (9:30 est) and 10:05 est or any time range; check image below for example.


The box shows the range I want to check and the red arrow shows the highest price in that range.

I know it be possibly easier to just plot it manually, but I would like to use this as a trading strategy when looking for trades.

Here is a modification of the aftermarket script to the timeframe that you requested.

Screenshot-2021-08-22-112609.jpg
Ruby:
input afterbegin = 0930;
input afterend   = 1005;
def aftermarket =  SecondsFromTime(afterbegin) >= 0 and SecondsTillTime(afterend) >=...
Hello, I am very new to thinkscript. I want to create a script indicator that plot a horizontal line (price level line) automatically of the highest price between market open (9:30 est) and 10:05 est or any time range; check image below for example.


The box shows the range I want to check and the red arrow shows the highest price in that range.

I know it be possibly easier to just plot it manually, but I would like to use this as a trading strategy when looking for trades.

Here is a modification of the aftermarket script to the timeframe that you requested.

Screenshot-2021-08-22-112609.jpg
Ruby:
input afterbegin = 0930;
input afterend   = 1005;
def aftermarket =  SecondsFromTime(afterbegin) >= 0 and SecondsTillTime(afterend) >= 0;
def bars   = 2000;

input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default BAR};
input onExpansion = no;
input profiles = 1000;

def period;

switch (timePerProfile) {
case BAR:
    period = BarNumber() - 1;
}


def count = CompoundValue(1, if aftermarket and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
def con = CompoundValue(1, onExpansion, no);

def hProfile = if aftermarket and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if aftermarket and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if aftermarket and plotsDomain then hProfile else Double.NaN;
def ProfileLow = if aftermarket and plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hrange.SetDefaultColor(Color.GREEN);
lrange.SetDefaultColor(Color.RED);
hrange.SetLineWeight(2);
lrange.SetLineWeight(2);

input bubblemover = 0;
def b  = bubblemover;
def b1 = b + 1;


input showbubbles = yes;
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b])  , hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b]) , lrange, AsText(lrange), Color.LIGHT_RED, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 
Solution
@SleepyZ any idea how to add the ability to show YESTERDAY's TimePrice Range plotted on today? What I'm exactly looking to do, is to plot yesterday's AFTERNOON SESSION (1230-1600) as HI LO lines on today's intraday chart.

See if this helps

Capture.jpg
Ruby:
#Previous Day High between 1230 and 1600 - Extended After Hours ---------------------
def phi    = if SecondsFromTime(1230) == 0 then high else if SecondsTillTime(1600) >= 0 then Max(high, phi[1]) else phi[1];
def phiext = if GetTime() >= RegularTradingEnd(GetYYYYMMDD()[1]) then phi else phiext[1];
plot xphi  = phiext;
xphi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Previous Days Low between 1230 and 1600 - Extended After Hours----------------------
def plo    = if SecondsFromTime(1230) == 0 then low else if SecondsTillTime(1600) >= 0 then Min(low, plo[1]) else plo[1];
def ploext = if GetTime() >= RegularTradingEnd(GetYYYYMMDD()[1]) then plo else ploext[1];
plot xplo  = ploext;
xplo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
See if this helps
Wonderful. And thank you. If you get a chance tonight, check it against $INTU. For some reason the high is higher than yesterday's high after midnight moving forward. No idea why. But it works on all other charts.

EDIT: Also $AEMD, the low is the low of the day, instead of the low of the afternoon session.
 
Wonderful. And thank you. If you get a chance tonight, check it against $INTU. For some reason the high is higher than yesterday's high after midnight moving forward. No idea why. But it works on all other charts.

EDIT: Also $AEMD, the low is the low of the day, instead of the low of the afternoon session.

Thank you for the followup information.

As a result, I have added a vertical line to test where 1230 will start, even if there is not a 1230 bar on the chart being viewed. Let me know if you see any other issues. Also, using phi[1]/plo[1] instead to phi/plo in the extended lines seems to work better.

#Previous Day High between 1230 and 1600 - Extended After Hours ---------------------

def phi = if secondstillTime(1230)[1]>=0 and SecondsFromTime(1230) >= 0 then high else if SecondsTillTime(1600) >= 0 then Max(high, phi[1]) else phi[1];

def phiext = if GetTime() >= RegularTradingEnd(GetYYYYMMDD()[1]) then phi[1] else phiext[1];

plot xphi = phiext;

xphi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



#Previous Days Low between 1230 and 1600 - Extended After Hours----------------------

def plo = if SecondstillTime(1230)[1] >= 0 and SecondsfromTime(1230) >= 0 then low else if SecondsTillTime(1600) >= 0 then Min(low, plo[1]) else plo[1];

def ploext = if GetTime() >= RegularTradingEnd(GetYYYYMMDD()[1]) then plo[1] else ploext[1];

plot xplo = ploext;

xplo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



#Vertical line added to ensure that approximately 1230 is captured even if that time is not shown on the chart

input debug = yes;

addverticalLine(debug and secondstillTime(1230)[1]>=0 and SecondsFromTime(1230) >= 0,"");
 
Last edited:
Thank you for the followup information.

As a result, I have added a vertical line to test where 1230 will start, even if there is not a 1230 bar on the chart being viewed. Let me know if you see any other issues. Also, using phi[1]/plo[1] instead to phi/plo in the extended lines seems to work better.
Yep I believe that did the trick! Nice catch.

So FYI, how to use the concept:
If a stock puts in an above ATR day (Day's Range>ATR) and the afternoon session (1230-1600) is less than 25% of that range, then it sets up the next day for an ATR breakout in either direction (up or down) and if price reverses, you stop out and take the opposite trade. Because of the max 25% range, it sets up the trade for an average of 4:1 reward to risk, and overall is profitable in the long run. Enjoy!
 
Question for you @SleepyZ, and again thank you so much for your expert help on this. How does one (do I) incorporate this into a scan whereby I'm looking for the following criteria:
1) Greater than average ATR traded already in the morning session (930-1230)
2) Afternoon session was/is less than 25% of the day's total range
I'm curious to be able to scan for that for both yesterday's matches, so I have that info handy in the morning for breakouts, and also for today so I can check them out later at night and watchlist the best setups.

This is what I have for my ATR scan already:
Code:
(High[0]-Low[0])>(1.3*Average(TrueRange(high,  close,  low),  14))
Which obviously finds stocks that put in a day's range over 30% above ATR. The question is how to convert this to paying attention to only the first half of the day.

And then how to scan for SECONDHALFOFDAY <= (0.25 * 1STHALFOFDAY)

Are you familiar with doing scans? I am, but only moderately.

Many thanks ahead of time for any advice you have.
 
Question for you @SleepyZ, and again thank you so much for your expert help on this. How does one (do I) incorporate this into a scan whereby I'm looking for the following criteria:
1) Greater than average ATR traded already in the morning session (930-1230)
2) Afternoon session was/is less than 25% of the day's total range
I'm curious to be able to scan for that for both yesterday's matches, so I have that info handy in the morning for breakouts, and also for today so I can check them out later at night and watchlist the best setups.

This is what I have for my ATR scan already:
Code:
(High[0]-Low[0])>(1.3*Average(TrueRange(high,  close,  low),  14))
Which obviously finds stocks that put in a day's range over 30% above ATR. The question is how to convert this to paying attention to only the first half of the day.

And then how to scan for SECONDHALFOFDAY <= (0.25 * 1STHALFOFDAY)

Are you familiar with doing scans? I am, but only moderately.

Many thanks ahead of time for any advice you have.

This has 2 Tests you outlined. There are 2 scripts to derive the data. Script AM finds the High/Low of the current day in the AM and allows the computation of `14 days AM TrueRanges, which are then able to be averaged. The Script PM finds the PM High/Low of the current day in the PM. The 2 tests are then computed as 1 or 0 (true/false). Both have to be 1/true for the plot SCAN to be TRUE.

I did not find many true instances of the Test 2, so most SCAN results were FALSE.

After you are satisfied with a SCAN from this information, then the easiest way is to NAME the Scan Study and then reference the study's name in the scanner.

Ruby:
script am {
    input day    = 0;
    input begin  = 0930;
    input end    = 1230;
    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;
#High between begin and end ---------------------
    def amhi    = if thisDay == day and SecondsTillTime(begin)[1] >= 0 and SecondsFromTime(begin) >= 0 then high else if thisDay == day and SecondsTillTime(end) > 0 then Max(high, amhi[1]) else amhi[1];
    plot hi     = amhi;

#Low between begin and end ----------------------
    def amlo    = if SecondsTillTime(begin)[1] >= 0 and SecondsFromTime(begin) >= 0 then low else if SecondsTillTime(end) > 0 then Min(low, amlo[1]) else amlo[1];
    plot lo     = amlo;

#Close at end -----------------------------------
    def amc    = if SecondsTillTime(end) > 0 then close else amc[1];
    plot cl    = amc;

}

script pm {
    input day    = 0;
    input begin  = 1230;
    input end    = 1600;
    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;
#High between begin and end ---------------------
    def phi    = if thisDay == day and SecondsTillTime(begin)[1] >= 0 and SecondsFromTime(begin) >= 0 then high else if thisDay == day and SecondsTillTime(end) > 0 then Max(high, phi[1]) else phi[1];
    plot pmhi     = phi;

#Low between begin and end ----------------------
    def plo    = if SecondsTillTime(begin)[1] >= 0 and SecondsFromTime(begin) >= 0 then low else if SecondsTillTime(end) > 0 then Min(low, plo[1]) else plo[1];
    plot pmlo     = plo;

}

#Average True Range over 14 AM periods================
def tr0 = TrueRange(am().hi, am().cl, am().lo);
def tr1 = TrueRange(am(1).hi, am(1).cl, am(1).lo);
def tr2 = TrueRange(am(2).hi, am(2).cl, am(2).lo);
def tr3 = TrueRange(am(3).hi, am(3).cl, am(3).lo);
def tr4 = TrueRange(am(4).hi, am(4).cl, am(4).lo);
def tr5 = TrueRange(am(5).hi, am(5).cl, am(5).lo);
def tr6 = TrueRange(am(6).hi, am(6).cl, am(6).lo);
def tr7 = TrueRange(am(7).hi, am(7).cl, am(7).lo);
def tr8 = TrueRange(am(8).hi, am(8).cl, am(8).lo);
def tr9 = TrueRange(am(9).hi, am(9).cl, am(9).lo);
def tr10 = TrueRange(am(10).hi, am(10).cl, am(10).lo);
def tr11 = TrueRange(am(11).hi, am(11).cl, am(11).lo);
def tr12 = TrueRange(am(12).hi, am(12).cl, am(12).lo);
def tr13 = TrueRange(am(13).hi, am(13).cl, am(13).lo);
def amatr = (tr0 + tr1 + tr2 + tr3 + tr4 + tr5 + tr6 + tr7 + tr8 + tr9 + tr10 + tr11 + tr12 + tr13) / 14;

#Scan -------------------------------------------
def test2  = if (pm().pmhi - pm().pmlo) < .25 * (am().hi - am().lo) then 1 else 0;
def test1  = if (am().hi - am().lo) > (1.3 * amatr) then 1 else 0;
plot scan  = if test1 == 1 and test2 == 1 then 1 else 0;

#Vertical line added to ensure that approximately 1230 is captured if that time is not shown on the chart
input debug = yes;

AddVerticalLine(debug and SecondsTillTime(0930)[1] >= 0 and SecondsFromTime(0930) >= 0, "");

AddLabel(debug, "AH: " + am().hi + " AC: " + am().cl + " AL: " + am().lo + " ATR: " + amatr, Color.WHITE);

addlabel(debug, "PH: " + " " + pm().pmhi + " PL:" + pm().pmlo + " PM Diff: " + (pm().pmhi - pm().pmlo) + " AM Diff: " + (.25 * (am().hi - am().lo)), if test2==1 then color.green else color.red);

AddLabel(debug, "SCAN: Test1: " + Test1 + " Test2: " + test2 + " == " + scan, if scan == 1 then Color.GREEN else Color.RED);
 

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