PureBytes Links
Trading Reference Links
|
Gary & Jimmy,
Many thanks for the reply. Gary's code is what I used, but put it in a
function. I modified the standard XAverage function like this and using
it as follows:
XAverageMulti (function)
-------------
input:
Price(NumericSeries), Length(NumericSimple),
BI(NumericSimple), TFMult(NumericSimple);
var:
Factor(0);
If(Length + 1 <> 0) then begin
if CurrentBar <= 1 then begin
Factor = 2 / (Length + 1);
XAverageMulti = Price;
end
else begin
if(Mod(BarNumber, BI*TFMult) = 0) then
XAverageMulti = Factor * Price + (1 - Factor) * XAverageMulti[1]
else
XAverageMulti = XAverageMulti[1];
end;
End;
This enables us to calculate XAverage of any interval
multiplier(TFMult). So, with a 3 minute chart we can get ema of 3, 6, 9
etc. minutes.
In the custom ema indicator, I call it like so
bi = BarInterval;
if mod(BarNumber, bi*TFMult) = 0 then
begin
ema = XAverageMulti(Price, Length, bi, TFMult);
Plot1(ema, "ema");
end;
In the indicator, "if mod(BarNumber, bi*TFMult) = 0 then" is only needed
to avoid plotting the value every 1 minute bar, instead of plotting
every 13th bar, as intended. In a strategy, if we are using a 1 minute
bar interval, XAverageMulti(Close, 34, 1, 13) would keep reporting the
same ema 13 times and then changeover to the new ema value, which would
then again be used 13 times.
Perfect!! Goodbye 13 minute chart, I guess. Woohoo!! KISS quest continues.
Abhijit
PS : While Thunderbird was running the spell check on this email, it
suggested I replace Woohoo with Boohoo. I wonder why the second one
deserves a place in the dictionary, but not the first one. Is is because
the world predominantly a sad place?
(untested, since I don't have my TS here, but should be close)
inputs: EMAlen(34);
vars: alpha(2/(1+EMAlen)), EMA(Close);
if mod(BarNumber, 13) = 0 then
EMA = alpha * Close + (1-alpha) * EMA;
alpha gets initialized to the proper value for an EMAlen-length
xaverage. EMA gets initialized to the value of Close on the
first bar, to give it a reasonable starting value.
Then every 13 bars, you just calculate the new EMA value using
the close of that 1min bar.
This may not exactly match the EMA on a 13min chart, because it
may be offset a bit. E.g. the 13min chart might have bars ending
at 10:00, 10:13, 10:26, etc, while this code might be
recalculating on the bars ending at 10:03, 10:16, 10:29, etc.
But the results should be close enough for your purposes.
Gary
|