How To Scan On Past Dates

When I copy and paste the first script above, the thinkScript Editor rejects it because it has the word 'scan' in it twice. Please add in what's needed for a look back to the following Momentum Curl script, as an example for me to use:

def lowestLow = Lowest(low, 4);
def highestHigh = Highest(high, 4);
def rangea = highestHigh - lowestLow;

def kRaw =
if rangea != 0
then 100 * (close - lowestLow) / rangea
else 0;

def kSlow = WildersAverage(kRaw, 10);
def dLine = WildersAverage(kSlow, 10);

plot scan =
dLine > dLine[1] and
dLine[1] <= dLine[2];
Try this:
Code:
input lookbackBars = 7;

def c = close;

def liquidityOk =
    c > 20 and
    Average(volume, 50) > 1000000;

def ema10 = ExpAverage(c, 10);
def ema21 = ExpAverage(c, 21);

def trendOk =
    c > ema10 and
    c > ema21 and
    ema10 > ema21 and
    ema10 > ema10[3] and
    ema21 > ema21[3];

def h63 = Highest(high, 63);
def l63 = Lowest(low, 63);
def l20 = Lowest(low, 20);

def range63 = h63 - l63;
def rangePos63 = if range63 != 0 then (c - l63) / range63 else 0;
def pctOff20Low = if l20 != 0 then (c / l20) - 1 else 0;
def pctBelow63High = if h63 != 0 then (h63 - c) / h63 else 0;

def locationOk =
    pctOff20Low > 0.10 and
    pctBelow63High > 0.06 and
    pctBelow63High < 0.20 and
    rangePos63 > 0.45 and
    rangePos63 < 0.78;

def repairSetup =
    liquidityOk and
    trendOk and
    locationOk;

def lowestLow = Lowest(low, 4);
def highestHigh = Highest(high, 4);
def rangeA = highestHigh - lowestLow;

def kRaw =
    if rangeA != 0
    then 100 * (c - lowestLow) / rangeA
    else 0;

def kSlow = WildersAverage(kRaw, 10);
def dLine = WildersAverage(kSlow, 10);

def turnUpNow =
    dLine > dLine[1] and
    dLine[1] <= dLine[2];

def recentTurnUp =
    Highest(if turnUpNow then 1 else 0, lookbackBars) > 0;

plot scan =
    repairSetup and
    recentTurnUp;

if too many reduce lookback - too few increase lookback
 
Try this:
Code:
input lookbackBars = 7;

def c = close;

def liquidityOk =
    c > 20 and
    Average(volume, 50) > 1000000;

def ema10 = ExpAverage(c, 10);
def ema21 = ExpAverage(c, 21);

def trendOk =
    c > ema10 and
    c > ema21 and
    ema10 > ema21 and
    ema10 > ema10[3] and
    ema21 > ema21[3];

def h63 = Highest(high, 63);
def l63 = Lowest(low, 63);
def l20 = Lowest(low, 20);

def range63 = h63 - l63;
def rangePos63 = if range63 != 0 then (c - l63) / range63 else 0;
def pctOff20Low = if l20 != 0 then (c / l20) - 1 else 0;
def pctBelow63High = if h63 != 0 then (h63 - c) / h63 else 0;

def locationOk =
    pctOff20Low > 0.10 and
    pctBelow63High > 0.06 and
    pctBelow63High < 0.20 and
    rangePos63 > 0.45 and
    rangePos63 < 0.78;

def repairSetup =
    liquidityOk and
    trendOk and
    locationOk;

def lowestLow = Lowest(low, 4);
def highestHigh = Highest(high, 4);
def rangeA = highestHigh - lowestLow;

def kRaw =
    if rangeA != 0
    then 100 * (c - lowestLow) / rangeA
    else 0;

def kSlow = WildersAverage(kRaw, 10);
def dLine = WildersAverage(kSlow, 10);

def turnUpNow =
    dLine > dLine[1] and
    dLine[1] <= dLine[2];

def recentTurnUp =
    Highest(if turnUpNow then 1 else 0, lookbackBars) > 0;

plot scan =
    repairSetup and
    recentTurnUp;

if too many reduce lookback - too few increase lookback
Using the above that you posted a few minutes ago resulted in "No matching symbols' when I ran it with lookback set at 1. I ran it on All ETF's, All Stocks & All Symbols with all three showing 0 resulting symbols even though I pasted the exact setup above.

Any suggestions?
 
Using the above that you posted a few minutes ago resulted in "No matching symbols' when I ran it with lookback set at 1. I ran it on All ETF's, All Stocks & All Symbols with all three showing 0 resulting symbols even though I pasted the exact setup above.

Any suggestions?
run it on 5 or 7 there may not be any that fit the bill on just 1 day look back
 
Last edited:
Putting in higher numbers gives a few results. What I'd really like is a script I can add to each of the existing scans I'm using to allow me to lookback a week, a month and 3 months so I can evaluate the scanners using StockCharts.
 
Putting in higher numbers gives a few results. What I'd really like is a script I can add to each of the existing scans I'm using to allow me to lookback a week, a month and 3 months so I can evaluate the scanners using StockCharts.
gotcha... Yes, but the key constraint is this, You cannot make one universal top-box wrapper that magically applies lookback to whatever is inside Intersect. So, you will have to do the "def setup =" and plug in the scanner logic code into the look back prompt from above. what you are wanting would be cool but...
 
Putting in higher numbers gives a few results. What I'd really like is a script I can add to each of the existing scans I'm using to allow me to lookback a week, a month and 3 months so I can evaluate the scanners using StockCharts.

The simplest copy-paste placeholders, use these:​

Placeholder A: simple lookback​

Code:
input lookbackBars = 5;

def setup =
    0;  # replace with event logic

plot scan =
    Highest(if setup then 1 else 0, lookbackBars) > 0;

Placeholder B: still-valid lookback​

Code:
input lookbackBars = 5;

def event =
    0;  # replace with trigger logic

def stillValidNow =
    0;  # replace with current-hold logic

def recentEvent =
    Highest(if event then 1 else 0, lookbackBars) > 0;

plot scan =
    stillValidNow and
    recentEvent;

Placeholder C: structure now + recent trigger​

Code:
input lookbackBars = 5;

def structureNow =
    0;  # replace with structural conditions

def triggerNow =
    0;  # replace with event trigger

def recentTrigger =
    Highest(if triggerNow then 1 else 0, lookbackBars) > 0;

plot scan =
    structureNow and
    recentTrigger;

Placeholder D: exactly N bars ago​

Code:
input barsAgo = 3;

def event =
    0;  # replace with event logic

plot scan =
    if barsAgo >= 0
    then event[barsAgo]
    else 0;
 
I'm still running into the problem that having the word "Scan" a second time in the script causes thinkScript to reject the second instance of it. For example: "Identifier Already Used..." shows up at the bottom of the Filter screen and "Already assigned..." does too.

Is there something I can do to the script, that a dummy like me can do, to make the additional lookback wording work?
 

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