Finding the Bar and Open for comparing high and low

ksadras

New member
How do get a handle on a candle at a specific time like 9:30 am EST so that I can compare its open and low against the current bar?
Example:
def referanceBarLow = GetCandle(930).low
def referenceBarHigh = GetCandle(930).high

if low > referenceBarLow doSomething;
 
In your code you seemed to define the reference bar as the bar at 9:30. I did the same. I just did the low of the candle, but replace 'low' with high, open or close to get the other data points.
 
def referenceBarLow = if SecondsFromTime(0930)==0 then low else referenceBarLow[1];

What is referenceBarLow[1] though. Is it a candle object? If so should it not be referenceBarLow[1].low and then I can get the high value as referenceBarLow[1].high?

But it doesn't compile if I try to treat referanceBarLow[1] as a candle object.
 
Here is the problem statement: I want to compare the candles that come after the market open candle to see if the low value of that candle is lower than the market open candle and alert. How do I do this in thinkscript?
 
def referenceBarLow = if SecondsFromTime(0930)==0 then low else referenceBarLow[1];

What is referenceBarLow[1] though. Is it a candle object? If so should it not be referenceBarLow[1].low and then I can get the high value as referenceBarLow[1].high?

But it doesn't compile if I try to treat referanceBarLow[1] as a candle object.

referenceBarLow[1] is the value of referenceBarLow from the last bar. Setting referenceBarLow = referenceBarLow[1] allows you to store the value of the first bar low through the trading day. The code to your problem statement is below. I encourage you to use labels and chart bubbles to see what the code is doing. If you want the reference bar to be the first bar on the chart (instead of the 9:30 bar) then search this site for "firstbarofday".

Ruby:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsTillTime(0930)!=0 then low < referenceBarLow[1] else 0;
alert(lowerLowThanOpeningBar,"This Bar Has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);
addchartbubble(lowerLowThanOpeningBar, high, "ALERT");
 
referenceBarLow[1] is the value of referenceBarLow from the last bar. Setting referenceBarLow = referenceBarLow[1] allows you to store the value of the first bar low through the trading day. The code to your problem statement is below. I encourage you to use labels and chart bubbles to see what the code is doing. If you want the reference bar to be the first bar on the chart (instead of the 9:30 bar) then search this site for "firstbarofday".

Ruby:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsTillTime(0930)!=0 then low < referenceBarLow[1] else 0;
alert(lowerLowThanOpeningBar,"This Bar Has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);
addchartbubble(lowerLowThanOpeningBar, high, "ALERT");
Thanks a lot. I really appreciate it. The code, works like a charm. But this one adds a bubble and alerts every time it finds a lower bar than the referenceBarLow. How do I stop showing bubble once it is shown? Only one alert and one bubble between regulartradingstart(getyyyymmdd()) and regulartradingend(getyyyymmdd()). Thanks.
 
Last edited:
Ruby:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then low < referenceBarLow[1] else 0;

def conditionCount = if secondsTillTime(0930)==0 then 0 else if lowerLowThanOpeningBar then conditionCount[1]+1 else conditionCount[1];

alert(conditionCount == 1 && lowerLowThanOpeningBar,"This Bar Has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);

addchartbubble(conditionCount == 1 && lowerLowThanOpeningBar, high, "ALERT");
 
Ruby:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then low < referenceBarLow[1] else 0;

def conditionCount = if secondsTillTime(0930)==0 then 0 else if lowerLowThanOpeningBar then conditionCount[1]+1 else conditionCount[1];

alert(conditionCount == 1 && lowerLowThanOpeningBar,"This Bar Has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);

addchartbubble(conditionCount == 1 && lowerLowThanOpeningBar, high, "ALERT");
It works. Thank you so much. In my mind I was going crazy thinking I have to use fold and all. You made it very simple. I have modified your code to track both the first high and first low during the market open.
Code:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then low < referenceBarLow[1] else 0;

def lowConditionCount = if secondsTillTime(0930)==0 then 0 else if lowerLowThanOpeningBar then lowConditionCount[1]+1 else lowConditionCount[1];

alert(lowConditionCount == 1 && lowerLowThanOpeningBar,"This Bar has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);

addchartbubble(lowConditionCount == 1 && lowerLowThanOpeningBar, high, “L”, Color.RED);

def referenceBarHigh = if secondsTillTime(0930)==0 then high else referenceBarHigh[1];
def higherHighThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then high > referenceBarHigh[1] else 0;

def highConditionCount = if secondsTillTime(0930)==0 then 0 else if higherHighThanOpeningBar then highConditionCount[1]+1 else highConditionCount[1];

alert(highConditionCount == 1 && higherHighThanOpeningBar,"This Bar has Higher High Than Reference Bar", alert.BAR, sound.CHIMES);

addchartbubble(highConditionCount == 1 && higherHighThanOpeningBar, high, “H”, Color.GREEN);

But the trick is to only alert the first high or first low but not both. If you have any insight on how to do that, much appreciated. I will try as well.
 
You just have to add one more condition to the alert statements. Everything you need is there. Let me know what you come up with. :)
Here it is. Thanks again
Code:
def referenceBarLow = if secondsTillTime(0930)==0 then low else referenceBarLow[1];
def lowerLowThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then low < referenceBarLow[1] else 0;

def lowConditionCount = if secondsTillTime(0930)==0 then 0 else if lowerLowThanOpeningBar then lowConditionCount[1]+1 else lowConditionCount[1];



def referenceBarHigh = if secondsTillTime(0930)==0 then high else referenceBarHigh[1];
def higherHighThanOpeningBar = if secondsFromTime(0930) > 0 and secondsTillTime(1600) > 0 then high > referenceBarHigh[1] else 0;

def highConditionCount = if secondsTillTime(0930)==0 then 0 else if higherHighThanOpeningBar then highConditionCount[1]+1 else highConditionCount[1];

alert(lowConditionCount == 1 && highConditionCount == 0 && lowerLowThanOpeningBar,"This Bar has Lower Low Than Reference Bar", alert.BAR, sound.CHIMES);

alert(highConditionCount == 1 && lowConditionCount == 0 && higherHighThanOpeningBar,"This Bar has Higher High Than Reference Bar", alert.BAR, sound.CHIMES);


addchartbubble(highConditionCount == 1 && lowConditionCount == 0 && higherHighThanOpeningBar, high, “H”, Color.GREEN);
addchartbubble(lowConditionCount == 1 && highConditionCount == 0 && lowerLowThanOpeningBar, high, “L”, Color.RED);
 

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