[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "synthetic" bar code



PureBytes Links

Trading Reference Links

> Does anyone care to share the basic code that allows indicators to
> create, for example, 5 min bars from 1 min bars .  I want to plot a
> 20 bar xma of 5 min bars on  a chart of 1 min bars without using
> Data2. 

For XMA, you only need the close.  The only trick is calculating 
the XMA.  The standard Xaverage is a Series function, which means 
it will get called on every bar -- not what you want.  You either 
need to use a Simple-function version of Xaverage, or just 
calculate the XMA inline.

For example:

vars: Factor(0), XMA(Close);
Factor = 2 / (XMAlen + 1);
if mod(Time, 5) = 0 then
		XMA = Factor * Close + (1 - Factor) * XMA[1];

One weakness of the mod() = 0 test is if one or more of the 5-
minute boundary bars are missing.  To get around that, you could 
use something like this:

if mod(Time, 5) < mod(Time[1], 5) or Time >= Time[1]+5 then begin
  if mod(Time, 5) = 0 then value1 = Close
                      else value1 = Close[1];
            XMA = Factor * value1 + (1 - Factor) * XMA[1];

The value1 stuff just grabs the previous close if bars are 
missing.  So e.g. if you have a 1min bar at 9:33 and then another 
at 9:37, the close of the 9:33 bar is the close of your 5min bar.  
The mod test fires on the 9:37 bar, so you have to grab the 
previous (9:33) close.  If you have a bar at 9:35, the mod test 
fires on that bar, so you want the current bar's close.

Gary