Scan: Breakout of previous day high

sbtosrc

New member
VIP
Hi,

I'm writing a scan script to identify stocks from WL that brokeout previous day high, but the script doesn't execute showing message: "Secondary period not allowed: Day."

input price = close;

# Previous day's high
def previousHigh = high(period = AggregationPeriod.DAY)[1];

# Condition: Current price is above previous day's high
plot scan = price > previousHigh;


i tried changing period to DAILY or DAY but no luck
 
Solution
Hi,

I'm writing a scan script to identify stocks from WL that brokeout previous day high, but the script doesn't execute showing message: "Secondary period not allowed: Day."

input price = close;

# Previous day's high
def previousHigh = high(period = AggregationPeriod.DAY)[1];

# Condition: Current price is above previous day's high
plot scan = price > previousHigh;


i tried changing period to DAILY or DAY but no luck

this is a watchlist study

if data from 1 time period is to be compared to a different period ( 2 different days) , then 2nd aggregation isn't needed.

this reads the high and low from yesterday and compares those levels to the current price.
if price is > prev hi , then green
if price is < prev lo , then red...
Hi,

I'm writing a scan script to identify stocks from WL that brokeout previous day high, but the script doesn't execute showing message: "Secondary period not allowed: Day."

input price = close;

# Previous day's high
def previousHigh = high(period = AggregationPeriod.DAY)[1];

# Condition: Current price is above previous day's high
plot scan = price > previousHigh;


i tried changing period to DAILY or DAY but no luck

this is a watchlist study

if data from 1 time period is to be compared to a different period ( 2 different days) , then 2nd aggregation isn't needed.

this reads the high and low from yesterday and compares those levels to the current price.
if price is > prev hi , then green
if price is < prev lo , then red

Code:
# zprevdhilo
#higher_prev_day

#https://usethinkscript.com/threads/scan-breakout-of-previous-day-high.18071/
# column
def na = double.nan;
def bn = barnumber();
def big = 99999;

def d = getday();
def isprevday = (d + 1) == getlastday();

def prevdayhi = if bn == 1 then 0
 else if isprevday then max(prevdayhi[1], high)
 else prevdayhi[1];

def prevdaylo = if bn == 1 then big
 else if isprevday then min(prevdaylo[1], low)
 else prevdaylo[1];

plot z1 = if d != getlastday() then na
 else if high > prevdayhi then 1
 else if low < prevdaylo then -1
 else 0;

AssignBackgroundColor(if high > prevdayhi then color.green else if low < prevdaylo then color.red else color.gray);
#

watchlist time was 5 minutes, after hours off
 

Attachments

  • img1.JPG
    img1.JPG
    37.4 KB · Views: 72
Solution

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

this is a watchlist study

if data from 1 time period is to be compared to a different period ( 2 different days) , then 2nd aggregation isn't needed.

this reads the high and low from yesterday and compares those levels to the current price.
if price is > prev hi , then green
if price is < prev lo , then red

Code:
# zprevdhilo
#higher_prev_day

#https://usethinkscript.com/threads/scan-breakout-of-previous-day-high.18071/
# column
def na = double.nan;
def bn = barnumber();
def big = 99999;

def d = getday();
def isprevday = (d + 1) == getlastday();

def prevdayhi = if bn == 1 then 0
 else if isprevday then max(prevdayhi[1], high)
 else prevdayhi[1];

def prevdaylo = if bn == 1 then big
 else if isprevday then min(prevdaylo[1], low)
 else prevdaylo[1];

plot z1 = if d != getlastday() then na
 else if high > prevdayhi then 1
 else if low < prevdaylo then -1
 else 0;

AssignBackgroundColor(if high > prevdayhi then color.green else if low < prevdaylo then color.red else color.gray);
#

watchlist time was 5 minutes, after hours off
There might be a chance that the statement "def isprevday = (d + 1) == getlastday();" may not work as intended if it is a weekend or holiday.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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