Basic within-bar statistics

Posted By: GPEngine

Basic within-bar statistics - 07/11/14 04:06

I understand that BarPeriod sets the sampling rate of the price curve, and run will be executed exactly once for each fully formed bar.

FR1:
In run(), allow access to the individual ticks comprising the bar. For example, if BarPeriod is 60, populate an array of TICKs with one element for each minute that comprises the bar. The reason is to allow custom within-bar statistics.

Short of that,
FR2:
You already compute some basic within-bar statistics for me. For example,
priceHigh() is essentially the max(highs) of all ticks comprising the bar
priceLow() is min(Low)
price is average(something) (By the way, this is underspecified. what is averaged, the O, H, L, or C of each tick?)
MedPrice() is median(something)
TypPrice() is (High + Low + Close)/3
WCLPrice() is also underspecified

These are all operating on within-Bar values. I propose the following additions.
within-bar stddev
variance
percentile or at least 1st and 3rd quantile
bool highFirst, returns true if the highest high came before the lowest low in the bar. else false
var highDelayWithinBar returns proportion of time within the bar that passed before the highest high was reached. i.e. 0.0 if open == high, 1.0 if close == high.
lowDelayWithinBar
and anything else you can think of
Posted By: jcl

Re: Basic within-bar statistics - 07/11/14 06:18

You can do that already: when you set TICKS, g->asset->pTicks[i] is a pointer to a list of TICK pointers within bar i. You can then use this list for computing the moments and other statistics within the bar. Use the Moment function, not the StdDev function.

In live trading though, ticks are not stored in an array, so you'd need to update the statistics in a TMF in real time.
Posted By: GPEngine

Re: Basic within-bar statistics - 07/11/14 14:02

Oh, neat.

Do you have a code example of updating the statistics in a TMF in real time?
Posted By: jcl

Re: Basic within-bar statistics - 07/11/14 14:37

No, this task did not come up so far. priceClose() in a TMF is the last price tick; whenever it changes, store its sum, the sum of its squares, and increase a counter. From these 3 values you can then calculate the mean, variance, stddev and so on.
Posted By: GPEngine

Re: Basic within-bar statistics - 07/11/14 14:46

in price() what is averaged? The Close of each tick?
same question for MedPrice() and WCLPrice()
Posted By: jcl

Re: Basic within-bar statistics - 07/11/14 14:52

Indicators don't use ticks. I don't know what WCLPrice() does - you'd need to look into its source. All docs that I got are in the manual, so I have no more info than you about the TA-Lib indicators.

price() is the average of (H+L)/2 of all ticks. It's not identical to the average of the Close.

© 2024 lite-C Forums