Body High Low Series
Author: hlh
Creation Date: 2/9/2011 10:51 AM
profile picture

hlh

#1
To find the length of the body I use
CODE:
Please log in to see this code.

but how can I create a series of the higher (max) of Open or Close,
and a series of the lower (min) of Open or Close.

I believe I could loop thru all bars using Math.Min and .Max and then write the values into a DataSeries but I wonder if there is a more elegant way directly creating a series like DataSeries.Max( Open, Close), similar to DataSeries.Abs( Open - Close) which does exist?
profile picture

Cone

#2
Those either/or conditions have to be programmed - one way or another. You can make an elegant function that you use over and over, but it has to loop through the bars.

CODE:
Please log in to see this code.
profile picture

hlh

#3
Thank you for your reply.

What I have is
CODE:
Please log in to see this code.

I do not know whether or not I need this DataSeries X = Close - Close; or not?

Also if a shorthand if as you used it would be faster than Math.Max?

And what is better: Generate DataSeries ShadowUpper as I did after the bar loop using the new BodyHigh Series or already inside the bar loop with ShadowUpper = High[bar] - BodyHigh[bar]?
profile picture

Cone

#4
QUOTE:
I do not know whether or not I need this DataSeries X = Close - Close; or not?
It's okay to do it once, but not twice - the second time doesn't create a separate series. Use new DataSeries like in my example. The added bonus is the ability to provide a series Description in the constructor.

QUOTE:
Also if a shorthand if as you used it would be faster than Math.Max?
It probably doesn't matter in a practical sense, but feel free to do some benchmark tests!

QUOTE:
And what is better:
Though it's not a formal indicator, I gave you a solution that you can use over and over in the same script for 2 generic DataSeries. You're writing in-line, hard code. Which is better?

Also your BodyMidpoint is the same as AveragePrice.Series(Bars);

profile picture

hlh

#5
By 'what is better' I meant if one has to run a bar loop anyway, would it make more sense to calculate additional series already in the loop, or after the loop has finished like in my example for the ShadowUpper which uses the difference between the High and BodyHigh, the latter which was constructed in the bar loop before.

I ask this because I assume that by building a series with e.g. DataSeries ShadowUpper = High - BodyHigh WL internally would also loop thru all the bars?
If so, each building of a DataSeries would over and over again loop thru all the bars, while if (all) included in the coded bar loop with XYSeries[bar] = ... would only require one run over all bars?

I think this might be important when using large number of bars (e.g. intraday minute) over long periods of time (many years) and/or huge number of extra created DataSeries?


Btw, the AveragePrice and AveragePriceC is not explained correctly in the Programming Guide as it is compared there to High and Low instead of Open and Close.
profile picture

Cone

#6
It's correct here: DataSeries > Series Operators and here. What is incorrect?
profile picture

Eugene

#7
QUOTE:
If so, each building of a DataSeries would over and over again loop thru all the bars, while if (all) included in the coded bar loop with XYSeries[bar] = ... would only require one run over all bars?

Not quite. Once a series is built, it's placed into Bars.Cache and retrieved from there (if exists).
profile picture

hlh

#8
@Cone

My BodyMidpoint was calculated from, well, as it says the body = Abs( Open - Close ), not High - Low which is the range, not the body. So it is not as you said 'Also your BodyMidpoint is the same as AveragePrice.Series(Bars);'

Based on your comment I checked your AveragePrice description. My mistake was to say it is incorrect while it is correct. The average price is, as far as I know, defined by the midpoint of H - L and correct in WL.

@Eugene

I see, being in the Bars.Cache would make reading its values faster. But I guess it still would loop again and again thru all its values on each DataSeries operation/calculation?

Don't want to theorize and my code is not finished to check for practical impact, but I need to loop over 2000 symbols of minute data, a total of 50GB of ASCII data. So I guess best will be to have it coded using the DataSeries operations first, and if I run into timing troubles to code each of them within one single "manual bar loop".

At least that's what I assume. I am a trader, not a programmer.
profile picture

Eugene

#9
But the result of "each DataSeries operation/calculation" (modification) is also placed into the Bars.Cache, as a new series, speeding things up. ;)
profile picture

Cone

#10
My mistake to equate Average.Series to your Body Midpoint... tired eyes to blame! :)

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).