Need help with net change during a set period

Aaron

New member
WOULD SOMEONE PLEASE HELP ME WITH THE CODE TO RETURN THE HIGH AND LOW, NET CHANGE, OF A CERTAIN BAR THAT FALLS WITH IN A SET PERIOD.

EXAMPLE,
I WANT THE DIFFERENCE BETWEEN THE HIGH AND THE LOW OF EACH BAR BUT ONLY IF THAT BAR HAS A HIGH>LOW AND THAT BAR IS WITHIN A CERTAIN TIME FRAME. SAY THAT TIME FRAME IS THE LAST 5 BARS I WANT THE NET CHANGE OF THOSE BARS.

I REALIZE THIS CODE IS NOT CORRECT BUT I MADE AND ATTEMPT TO DO THIS AND I HAVE HIT A BRICK WALL. A LITTLE HELP WOULD BE MUCH APPRECIATED.

PERIOD = BARSAGO(5);
DEF HH = HIGH(period = RANGE);
DEF LL = LOW(period = RANGE);
CONDITION = HIGH>LOW;

XXX = CONDITION AND PERIOD;
AVG_XXX = AVG(XXX);

ADDLABEL(YES, "CHG:" + (AVG_XXX), COLOR.YELLOW);
 
hi aaron. i'm not sure what you are asking. i would suggest to forget about the code for now and try to write out a clear set of rules/conditions that the study will follow.
then look at 10 bars on a chart, and read the rules and see if it makes sense.

high > low, will always be true, so i'm not sure what you mean.

example 1
find the biggest gap over past 5 bars
..look at last 5 bars
..find the highest high
..find the lowest low
..calc the gap, highest high - lowest low
..calc an average of the gap

this will be a small number, compared to the stock price, so should be put in a lower study.
 

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

Thank you for the reply......I'm trying to collect some data on symbols that I have traded to try and figure out a pattern. This is the only way I could come up with to collect it, and if you know of a better way please don't hold out on me......I am trying to figure out the easiest way to find the true range of bear bars and the true range of bull bars from 8:00AM to 8.25AM . From the true range I want to calculate the average percent change for bull bars and a separate average percent change for the bear bars over that time period.

Looking at the size and number of bars in a certain direction is the best Indicator I have found to date. What would be your advice for me to go about this?
 
The approach that comes to my mind is as follows.

Ruby:
input numberOfBars = 100;

def bullBar = close > open;
def bullRange = if bullBar then TrueRange(blah blah blah) else 0;

def bearBar = open > close;
def bearRange = if bearBar then TrueRange(blah blah blah) else 0;

def bullCount = Sum(bullBar, numberOfBars);
def bullATR = Sum(bullRange, numberOfBars) / bullCount;

def bearCount = Sum(bearBar, numberOfBars);
def bearATR = Sum(bearRange, numberOfBars) / bearCount;

def biggestBull = Highest(bullRange, numberOfBars);
# ...etc.
 
Last edited:
The approach that comes to my mind is as follows.

Ruby:
input numberOfBars = 100;

def bullBar = close > open;
def bullRange = if bullBar then TrueRange(blah blah blah) else 0;

def bearBar = open > close;
def bearRange = if bearBar then TrueRange(blah blah blah) else 0;

def bullCount = Sum(bullBar, numberOfBars);
def bullATR = Sum(bullRange, numberOfBars) / bullCount;

def bearCount = Sum(bearBar, numberOfBars);
def bearATR = Sum(bearRange, numberOfBars) / bearCount;

def biggestBull = Highest(bullRange, numberOfBars);
# ...etc.
I gave up on that code for a while and for whatever reason it came to me last night, I finally finished it....You gave me a good starting point, thanks again!
 
I gave up on that code for a while and for whatever reason it came to me last night, I finally finished it....You gave me a good starting point, thanks again!
Hi - I am new to investing too. We're doing this for a class in school. So, I was so frustrated I started looking at the individual ticks and I've come up with a pattern after looking at hundreds of ticks that seems to prove out, I think for every candle. For example if you look at a specific candle it has a open, high, low, and close. (O) (H) (L) (C) When I looked at the specifics for each, I found out a pattern that can determine what the next candle is going to be before it shows up. For example if the (O) = x and the the (H), (L), and (C) = the same value then the next candle is going to be down. Also, if the (O) = x and the (H) = x, then both the (L) and the (C) will be < than (O). Opposite of this is when the stock is going up. If the (O) = x and the (H) > x, but the (L) = to the (O) x, then the (C) will be > (O) and the next candle is going up. I have more of these sequences written down and in each case when the (C) is equal to or less than the (O) the next candle will be down. My problem is that I am not a very good code writer but love to look at the detailed analysis. I think if you knew how to write the code and I could feed you more of these parameters maybe we could create some kind of key that will project the next tick and subsequent ticks by just the one previous tick, so that after two ticks we could see that a stock is going up and then we'd know what to do.

Thanks
Sincerely,
homeplate
 
Hi - I am new to investing too. We're doing this for a class in school. So, I was so frustrated I started looking at the individual ticks and I've come up with a pattern after looking at hundreds of ticks that seems to prove out, I think for every candle. For example if you look at a specific candle it has a open, high, low, and close. (O) (H) (L) (C) When I looked at the specifics for each, I found out a pattern that can determine what the next candle is going to be before it shows up. For example if the (O) = x and the the (H), (L), and (C) = the same value then the next candle is going to be down. Also, if the (O) = x and the (H) = x, then both the (L) and the (C) will be < than (O). Opposite of this is when the stock is going up. If the (O) = x and the (H) > x, but the (L) = to the (O) x, then the (C) will be > (O) and the next candle is going up. I have more of these sequences written down and in each case when the (C) is equal to or less than the (O) the next candle will be down. My problem is that I am not a very good code writer but love to look at the detailed analysis. I think if you knew how to write the code and I could feed you more of these parameters maybe we could create some kind of key that will project the next tick and subsequent ticks by just the one previous tick, so that after two ticks we could see that a stock is going up and then we'd know what to do.

Thanks
Sincerely,
homeplate
 
Hi - I am new to investing too. We're doing this for a class in school. So, I was so frustrated I started looking at the individual ticks and I've come up with a pattern after looking at hundreds of ticks that seems to prove out, I think for every candle. For example if you look at a specific candle it has a open, high, low, and close. (O) (H) (L) (C) When I looked at the specifics for each, I found out a pattern that can determine what the next candle is going to be before it shows up. For example if the (O) = x and the the (H), (L), and (C) = the same value then the next candle is going to be down. Also, if the (O) = x and the (H) = x, then both the (L) and the (C) will be < than (O). Opposite of this is when the stock is going up. If the (O) = x and the (H) > x, but the (L) = to the (O) x, then the (C) will be > (O) and the next candle is going up. I have more of these sequences written down and in each case when the (C) is equal to or less than the (O) the next candle will be down. My problem is that I am not a very good code writer but love to look at the detailed analysis. I think if you knew how to write the code and I could feed you more of these parameters maybe we could create some kind of key that will project the next tick and subsequent ticks by just the one previous tick, so that after two ticks we could see that a stock is going up and then we'd know what to do.

Thanks
Sincerely,
homeplate
Send me an [email protected]
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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