Determining which price occurred first within a single bar

TNTrader5159

Active member
How would one determine which occurred first in the current bar -- the high or the low? Can the time of each be called forth and compared?
 
Solution
How would one determine which occurred first in the current bar -- the high or the low? Can the time of each be called forth and compared?

events during a candle can't be saved, except high and low.
you would have to use a smaller time frame chart and compare bar numbers of the 2 events.
How would one determine which occurred first in the current bar -- the high or the low? Can the time of each be called forth and compared?

events during a candle can't be saved, except high and low.
you would have to use a smaller time frame chart and compare bar numbers of the 2 events.
 
Solution

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

As @halcyonguy pointed out, the ToS platform nor any other platform provides for "inter-candle" history.
The candle provides the open, close, high, low. It is not possible from that data to determine "when" they happened.

As @halcyonguy stated, you might be able to code an interpolation routine comparing the high and lows of the lower timeframes to create a guesstimate for which came first for the current aggregation on your chart.
I see. I will have to break the current bar into at least two bars to make mostly sure the high engulfs the 3 preceding bars BEFORE the low does to indicate a Short alert at the latter. Or the opposite for a Long alert when the high break occurs AFTER the low break.

Really my system is about TIME ratios not necessarily fixed bars that can only approximate that goal and thus yield fewer and less accurate trade detections. Ideally it would use 1-second intervals, but no market trades often enough throughout each session to make time a true representation. Events or volume are really what matter as with directional movement indicators. Are volume bars done in TS? I don't think so, but I'm not focusing there anyway. It's too complicated. I like simple.

So back to the more practical means to ends, breaking things down into 1-minute bars is the best way for TS to approximate the desired end result. For example, if one bar engulfs the preceding three bars, you have a 1/3 ratio or the minimum in my system. If two bars engulf six, the same ratio applies. The shortcut is to look at multiple timeframes at once to achieve the desired minimum ratio using a minimum number of variants without complicating things in using all the numerous possible ratio combinations for one fixed timeframe.

So first determine if one bar engulfs three, then which end engulfs them first (high for a short and low for a long) by breaking it down into a shorter base timeframe, then determine how many bars it actually does engulf, and keep it calibrating as the market moves favorably to possibly achieve a tradeable ratio on a longer timeframe to project a longer favorable move that would plow through more impedance. This is the key to determining what is elusive to most traders as the proper exit point.

Measure the number of bars engulfed against the "Impedance Factor" that would stand in the way as prior primary and secondary peaks and valleys and congestion zones. The bigger wins. I have a way to calculate congestion zones for comparison to pattern strength or the "Thrust Factor" that I will show later. With any trade entered, your profit objective is already known in advance. Stops should not be necessary in most cases, and should an adverse move occasionally occur, you can usually turn this into profit that more than offsets the small loss by reversing the position. More on that later. Of course, an emergency/catastrophe stop would be entered automatically with EVERY TRADE placed, unless it's a non-leveraged investment like option purchases. More on that later also.

All that's left is account management rules and to exit all positions before any holiday or weekend. Most trades would conclude intraday anyway, as the objective is to trade as short-term as possible to capture more market "surface area." In these crazy times, you don't want to leave yourself exposed during any significant breaks in trading where even a stop would not protect you should there be a catastrophic event.
 
close of the previous candle?
No because the current candle/bar could open near there then go down first then back up and give what would in accord be a long signal when that might not be appropriate for conditions. I think cutting the timeframe into one-minute segments and comparing bar numbers of the high and low breaks is the only way to determine which would come first here.
 
I see. I will have to break the current bar into at least two bars to make mostly sure the high engulfs the 3 preceding bars BEFORE the low does to indicate a Short alert at the latter. Or the opposite for a Long alert when the high break occurs AFTER the low break.

Really my system is about TIME ratios not necessarily fixed bars that can only approximate that goal and thus yield fewer and less accurate trade detections. Ideally it would use 1-second intervals, but no market trades often enough throughout each session to make time a true representation. Events or volume are really what matter as with directional movement indicators. Are volume bars done in TS? I don't think so, but I'm not focusing there anyway. It's too complicated. I like simple.

So back to the more practical means to ends, breaking things down into 1-minute bars is the best way for TS to approximate the desired end result. For example, if one bar engulfs the preceding three bars, you have a 1/3 ratio or the minimum in my system. If two bars engulf six, the same ratio applies. The shortcut is to look at multiple timeframes at once to achieve the desired minimum ratio using a minimum number of variants without complicating things in using all the numerous possible ratio combinations for one fixed timeframe.

So first determine if one bar engulfs three, then which end engulfs them first (high for a short and low for a long) by breaking it down into a shorter base timeframe, then determine how many bars it actually does engulf, and keep it calibrating as the market moves favorably to possibly achieve a tradeable ratio on a longer timeframe to project a longer favorable move that would plow through more impedance. This is the key to determining what is elusive to most traders as the proper exit point.

Measure the number of bars engulfed against the "Impedance Factor" that would stand in the way as prior primary and secondary peaks and valleys and congestion zones. The bigger wins. I have a way to calculate congestion zones for comparison to pattern strength or the "Thrust Factor" that I will show later. With any trade entered, your profit objective is already known in advance. Stops should not be necessary in most cases, and should an adverse move occasionally occur, you can usually turn this into profit that more than offsets the small loss by reversing the position. More on that later. Of course, an emergency/catastrophe stop would be entered automatically with EVERY TRADE placed, unless it's a non-leveraged investment like option purchases. More on that later also.

All that's left is account management rules and to exit all positions before any holiday or weekend. Most trades would conclude intraday anyway, as the objective is to trade as short-term as possible to capture more market "surface area." In these crazy times, you don't want to leave yourself exposed during any significant breaks in trading where even a stop would not protect you should there be a catastrophic event.
Can you reference the current timeframe, eg if you're on a 10-minute bar chart, can you have some code return the value '10' so as to know how many bars to look at in comparing the bar numbers of the high and low breaks above/below the number of bars engulfed?
events during a candle can't be saved, except high and low.
you would have to use a smaller time frame chart and compare bar numbers of the 2 events.
 
Can you reference the current timeframe, eg if you're on a 10-minute bar chart, can you have some code return the value '10' so as to know how many bars to look at in comparing the bar numbers of the high and low breaks above/below the number of bars engulfed?

yes,
this reads the chart time and converts it to minutes. then compares the number to others, to determine which label text to display.

https://usethinkscript.com/threads/...icator-for-thinkorswim.1129/page-5#post-69106

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetAggregationPeriod
 
How would one determine which occurred first in the current bar -- the high or the low? Can the time of each be called forth and compared?

I was working on something and not sure it is what you wanted, but may help.

This is an overlay of a higher timeframe that you can choose. It plots a line at the high and low of that timeframe on a tlower timeframe chart (1m is most descriptive).

!) It displays bubbles with the times (default ET) on the lower timeframe chart bars when the highs/lows (often there are multiples) of the higher timeframe input.
2) It then displays whether the higher timeframe's first high or low occurred and places another bubble at the beginning of the higher timeframe's bars (seperated by verticallines) with "H" or "L".
3) Also, added is a bubble for engulfing bars, as you had mentioned them, over the high of those higher timeframe bars.

Good luck with your endeavor.

Capture.jpg
Ruby:
input agg = AggregationPeriod.TEN_MIN;

def rth   = Between(GetTime(), RegularTradingStart(GetYYYYMMDD()),
                               RegularTradingEnd(GetYYYYMMDD()));

plot hper = if !rth then Double.NaN else high(period = agg);
plot lper = if !rth then Double.NaN else  low(period = agg);
hper.SetPaintingStrategy(PaintingStrategy.DASHES);
lper.SetPaintingStrategy(PaintingStrategy.DASHES);
hper.SetLineWeight(2);
hper.SetDefaultColor(Color.GREEN);
lper.SetDefaultColor(Color.RED);
lper.SetLineWeight(2);


#Define Bars in minutes in Agg input
def bn      = BarNumber();
input begin = 0930;
input end   = 1600;
def bar     = if SecondsFromTime(begin) < 0 and SecondsTillTime(end) > 0
              then 0
              else if SecondsTillTime(begin) == 0 and
                      SecondsFromTime(begin) == 0
              then 0
               else bar[1] + 1;
def minutes  = GetValue(agg / 60000, 1);
AddLabel(1, minutes);

def barx_min = bar % ((minutes) / (GetAggregationPeriod() / 60000)) == 0;
def barxct   = if barx_min then 1 else barxct[1] + 1;

#Identify Highs/Lows of the Agg Input
def lastbubbleh = if high == hper then bn else lastbubbleh[1];
def lastbubblel = if low == lper then bn else lastbubblel[1];

#Vertical Lines seperate number of bars in Agg minutes
AddVerticalLine(rth and barx_min, "", Color.WHITE);

#Test to show Highs/Lows and Time Happened
input test = yes;
input timezone = {default "ET", "CT", "MT", "PT"};

def starthour  = (if timezone == timezone."ET"
                        then 9
                        else if timezone == timezone."CT"
                        then 8
                        else if timezone == timezone."MT"
                        then 7
                        else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes_ = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;

AddChartBubble(test and bn == lastbubbleh, high(period = agg),
               #high + "\n" + lastbubbleh + "\n" +
               hour + ":" + (if minutes_ < 10 then "0" else "") + minutes_, Color.CYAN);

AddChartBubble(test and bn == lastbubblel, low(period = agg),
               #low + "\n" + lastbubblel + "\n" +
               hour + ":" + (if minutes_ < 10 then "0" else "") + minutes_, Color.WHITE, no);

#High or Low First Identified - If multiples of Highs/Lows, the latest bar is determinative of When Happened. For example, if a Low(agg) first appears then a singlar High(agg) appears and then another Low(agg) appears, as coded, then High would be first.
AddChartBubble(barx_min[-1], if lastbubblel < lastbubbleh then low(period = agg) else high(period = agg), if lastbubblel < lastbubbleh then "L" else "H", if lastbubblel > lastbubbleh then Color.GREEN else Color.RED,
if lastbubblel > lastbubbleh then yes else no);

#Engulfing Candle

def engulfingBar = if hper > hper[1] and lper < lper[1]
                   then 1
                   else 0;
AddChartBubble(engulfingBar, high(period = agg) + .02, "Engulfing", Color.MAGENTA);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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