Capture high/low up until a candle

jtbiz

New member
Plus
Hi! On a 1min intraday chart, looking for a way to capture high of day (hod) and low of day(lod) from 9.30 till a candle that meets a certain criteria (let's call it trigger candle). A new hod or lod could be created after the trigger candle which I want to ignore.

Thanks!
.
 
Solution
Without the specifics of your trigger candle criteria, this will be rather more abstract than it otherwise might be.

Let's start with explicitly defining your condition in terms of one (true) or zero (false):
Code:
def trigger = if some_condition() then 1 else 0;
Moving on to a typical way to find a high of the day:
Code:
def start_time = 0930;
def high_of_day = if secondsTillTime(start_time) >= 0
    and secondsTillTime(start_time)[1] < 0
        then high
    else if high > high_of_day[1]
        then high
    else high_of_day[1];
This basically checks to see whether it is 9:30 and if so, then the high of the day is the HIGH for that bar. If it is after 9:30, then we look to see whether the current bar HIGH is higher than the...
Without the specifics of your trigger candle criteria, this will be rather more abstract than it otherwise might be.

Let's start with explicitly defining your condition in terms of one (true) or zero (false):
Code:
def trigger = if some_condition() then 1 else 0;
Moving on to a typical way to find a high of the day:
Code:
def start_time = 0930;
def high_of_day = if secondsTillTime(start_time) >= 0
    and secondsTillTime(start_time)[1] < 0
        then high
    else if high > high_of_day[1]
        then high
    else high_of_day[1];
This basically checks to see whether it is 9:30 and if so, then the high of the day is the HIGH for that bar. If it is after 9:30, then we look to see whether the current bar HIGH is higher than the last value we had for the high_of_day and if it is, we replace the stored value with the current high. If it isn't higher, we bring the last value for high_of_day forward with us.

Where things get complicated is tracking whether your trigger condition has been met or not. We do that with another variable like this:
Code:
def trigger_fired = if secondsTillTime(start_time) >= 0
    and secondsTillTime(start_time)[1] < 0
        then 0
    else if trigger == 1 and trigger_fired[1] != 1
        then 1
    else trigger_fired[1];
Here, we set the trigger_fired variable to 0 (false) at 930. The next condition says: if the trigger is 1 (true) AND the trigger has not been fired yet, then fire the trigger, but even if the trigger is true (1) but the trigger has been fired, don't change me.

Now, we have a set of tests to determine whether or not to keep looking for a new high, or just keep our old one. So let's revisit the high_of_day definition from above and mess it about a bit.
Code:
def high_of_day = if secondsTillTime(start_time) >= 0 
    and secondsTillTime(start_time)[1] < 0 
        then high 
    else if high > high_of_day[1] AND trigger_fired == 0 
        then high 
    else high_of_day[1];
by adding the condition on the second part of the test (after the time test) we only change the stored high_of_day if the trigger has NOT been fired (trigger_fired is false(0)).

Of course, none of this code may work in ToS. I've just been typing in the browser to illustrate one possible approach to your question. If it works, huzzah! if not, come on back and we'll see if we can get it working for you.

-mashume
 
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
289 Online
Create Post

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