PureBytes Links
Trading Reference Links
|
Adrian,
> I was wondering if someone could help me. I'm trying to work out a way
> to count how many times a periods price range crosses the average of X
> periods. So for example if over the last 10 bars we have a
> movement with a low of 100 and a high of 120. The average will be 110.
> How many bars in the last 10 bars have traded at the average price of
> 110. I tried using COUNTIF function but it did not execute as I needed.
How about this (untested):
{function RangeCrossAvg}
inputs: price(NumericSeries), length(NumericSimple);
vars: ma(0), pcount(0), j(0);
ma = average(price, length);
pcount = 0;
for j = 0 to length begin
if H[j] >= ma and L[j] <= ma then pcount = pcount + 1;
end;
RangeCrossAvg = pcount;
-Alex
|