Referencing past daily bars

CharlieK

New member
With this script, I get results that will show an 8% or smaller range of the last 5 daily bars. If I wanted it to show the last 5 bars, not counting the current bar, how would you do it?

**********************************************************
#Shows consolidation range last 5 bars

def HH= Highest(high, 5);
def LL = Lowest(low, 5);
def Consolidate = (HH-LL)/LL*100;

Plot signal = if Consolidate <8.00 then 1 else 0;
***********************************************************
 
Solution
With this script, I get results that will show an 8% or smaller range of the last 5 daily bars. If I wanted it to show the last 5 bars, not counting the current bar, how would you do it?

**********************************************************
#Shows consolidation range last 5 bars

def HH= Highest(high, 5);
def LL = Lowest(low, 5);
def Consolidate = (HH-LL)/LL*100;

Plot signal = if Consolidate <8.00 then 1 else 0;
***********************************************************
HH[1] && LL[1] would be the respective conditions, for the bar prior to the current one.

For your scan, you can try this:
Code:
plot signal = if Consolidate[1] <8.00 then 1 else 0.

or this:
Code:
def signal = if Consolidate <8.00 then 1 else 0;
plot...
With this script, I get results that will show an 8% or smaller range of the last 5 daily bars. If I wanted it to show the last 5 bars, not counting the current bar, how would you do it?

**********************************************************
#Shows consolidation range last 5 bars

def HH= Highest(high, 5);
def LL = Lowest(low, 5);
def Consolidate = (HH-LL)/LL*100;

Plot signal = if Consolidate <8.00 then 1 else 0;
***********************************************************
HH[1] && LL[1] would be the respective conditions, for the bar prior to the current one.

For your scan, you can try this:
Code:
plot signal = if Consolidate[1] <8.00 then 1 else 0.

or this:
Code:
def signal = if Consolidate <8.00 then 1 else 0;
plot scan = signal[1];

I use this technique often to pull up setups for back-testing scenarios.
 
Solution
EDIT

tradecombine has the simplest way. just define another variable that looks at an offset of Consolidate.

def consol1 = Consolidate[1];

.............

if i didn't need the values from the current formulas in any other formulas,
def HH= Highest(high, 5);
def LL = Lowest(low, 5);

i would change them, by adding an offset to high and low.
def HH= Highest( high[1] , 5 );
def LL = Lowest( low[1] , 5 );
 
Last edited:
I'm not sure why, but I couldn't get tradecombine's example to work. I did finally get it working with halcyonguy's. A screenshot below.

I have used the [1] to reference the past, but I was having troubles with where exactly to put it to make it work.

HiLo5New.jpg
 
I'm not sure why, but I couldn't get tradecombine's example to work. I did finally get it working with halcyonguy's. A screenshot below.

I have used the [1] to reference the past, but I was having troubles with where exactly to put it to make it work.

HiLo5New.jpg


Did you get an error?
Edit: Both ways worked right away for me:

QjZ1SmH.png


XyvY5gn.png
 
Did you get an error?
Edit: Both ways worked right away for me:

QjZ1SmH.png


XyvY5gn.png
No, I didn't get any errors. It was showing me stocks that were way over 8.00. Not too sure where exactly it was getting the numbers from, but it certainly wasn't the highs and lows of the last 5, or of the 5 before, or any combination that I could find.

I was also having another problem last night though... I'm using that scan, to scan a watchlist.... which is populated by scanning another watchlist... which scans yet another watchlist. When I first opened the watchlist, the names I expected to be there.. were there. A couple of minutes later, suddenly other names would pop into that watchlist, that were so far from not only the criteria I was scanning for, but they were also stocks, that were not in the list being scanned. They were in the 1st watchlist, but didn't pass the criteria to move to the next. Hopefully some of that makes sense.

It was almost like it was reverting to a previous scan... that didn't exist? Leaving it alone for 20 minutes, sometimes they would automatically leave the list... sometimes they would not. Multiple restarts and 'garbage cleaning', it was still doing it. I deleted a bunch of other old scans that I don't use anymore, and it appeared to be working again.... I think. Hopefully have some time to stare at it today!

The problem I was having with the script, may have been related to the scan problem... Would be easier to say it was, if I knew exactly what the problem was, that I was having!
 
The problem I was having with the script, may have been related to the scan problem... Would be easier to say it was, if I knew exactly what the problem was, that I was having!
Not sure if this answers your question.
Scans only update every 3-4 minutes.
When EDITING scans, best practices dictate that scans being EDITED be saved with a NEW scan name.

There are short-term issues with EDITING scans. When a scan is edited and you hit scan, it will provide the correct results. But because the scan is not immediately updated on the TDA servers and it will shortly revert to an old version. The new version isn't lost, it just takes awhile for the TDA servers to update EDITED scans.

The workaround is when editing a scan, save it with a new name. Thus, nothing for it to revert to.
 
Last edited:

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