 # Need help with net change during a set period

#### Aaron

##### New member
VIP
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);

#### halcyonguy

##### Active member
VIP
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.

#### Aaron

##### New member
VIP
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?

#### Slippage

##### Active member
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:

#### Aaron

##### New member
VIP
Thank you for taking the time to send me that. Going to take another stab at it now. Ill let you know how it goes.

#### Aaron

##### New member
VIP
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!

#### homeplate2

##### Member
VIP
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

#### homeplate2

##### Member
VIP
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

#### Aaron

##### New member
VIP
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]