Percent Change within time period

I need some help creating a scan or study that can determine percentage change within a period. Specifically, I want a study/scan that can determine if a stock has had a 100% increase within 8 weeks/40 bars, including the percentage increase from low to high within that period. I have been looking throughout the site and can't seem to find code that will work with those parameters.
 
Solution
Try this, it can be used as both a scan and study. Let me know how it goes.
zBhQnsk.png
5SofUxP.png

Code:
input Percent = 100;
input Days = 40;
input Weeks = 8;
def iAgg =
    getAggregationPeriod()
;
def iOffset =
         if iAgg == aggregationPeriod.WEEK then Weeks
    else if iAgg == aggregationPeriod.Day then Days
    else 0
;
def bRange =
    isNaN(close[-iOffset])
;
def bEdge =
    bRange and !isNaN(close[-(iOffset - 1)]) 
;
def dBase =
    if !bRange then Double.NaN
    else if bEdge then low
    else dBase[1]
;
def dTop =
    dBase + (dBase * (Percent / 100)); 
;
def bBreach =
    if bRange and high > dTop then Yes else bBreach[1]
;
def dCloud =
    dBase + 0
;
AddCloud(
    dCloud,dTop,color.cyan
);
assignpriceColor(...
Currently at that level of increase only, or also include instances where that level of increase occurred within the time period but has since subsided?
 

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

Try this, it can be used as both a scan and study. Let me know how it goes.

Code:
input Percent = 100;
input Days = 40;
input Weeks = 8;
def iAgg =
    getAggregationPeriod()
;
def iOffset =
         if iAgg == aggregationPeriod.WEEK then Weeks
    else if iAgg == aggregationPeriod.Day then Days
    else 0
;
def bRange =
    isNaN(close[-iOffset])
;
def bEdge =
    bRange and !isNaN(close[-(iOffset - 1)]) 
;
def dBase =
    if !bRange then Double.NaN
    else if bEdge then low
    else dBase[1]
;
def dTop =
    dBase + (dBase * (Percent / 100)); 
;
def bBreach =
    if bRange and high > dTop then Yes else bBreach[1]
;
def dCloud =
    dBase + 0
;
AddCloud(
    dCloud,dTop,color.cyan
);
assignpriceColor(
    if bBreach then color.cyan
    else color.current
);
Plot Scan = bBreach and BarNumber() > iOffset and bRange;
Scan.hide();
 

Attachments

  • zBhQnsk.png
    zBhQnsk.png
    7.3 KB · Views: 201
Last edited:
Solution
Try this, it can be used as both a scan and study. Let me know how it goes.
Hi Josh, quick update on the scan. From my observations, the scan works quite effectively, but a lot of the time it only picks up the move after it has happened. I was going to ask for some assistance in the timeframe and picking it up. I'll attach a picture of what I mean, but basically is it possible to change where the box is defined, from low to high within the 40 bars?
image.png
 
This should move it down so that it starts at the lowest low within the range of bars.
Code:
input Percent = 100;
input Days = 40;
input Weeks = 8;
def iAgg =
    getAggregationPeriod()
;
def iOffset =
         if iAgg == aggregationPeriod.WEEK then Weeks
    else if iAgg == aggregationPeriod.Day then Days
    else 0
;
def bRange =
    isNaN(close[-iOffset])
;
def bEdge =
    bRange and !isNaN(close[-(iOffset - 1)])
;
def rTrackLow =
    if bEdge then Low
    else if bRange then Min(low,rTrackLow[1])
    else Double.NaN
;
def dSeekLow =
    if bEdge then GetValue(rTrackLow,-(iOffSet -1))
    else if bRange then dSeekLow[1]
    else Double.NaN;
;
def dBase =
    if !bRange then Double.NaN
    else if bEdge then dSeekLow
    else dBase[1]
;
def dTop =
    dBase + (dBase * (Percent / 100));
;
def bBreach =
    if bRange and high > dTop then Yes else bBreach[1]
;
def dCloud =
    dBase + 0
;
AddCloud(
    dCloud,dTop,color.cyan
);
assignpriceColor(
    if bBreach then color.cyan
    else color.current
);
Plot Scan = bBreach and BarNumber() > iOffset and bRange;
Scan.hide();
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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