PureBytes Links
Trading Reference Links
|
One problem you have there is that you can't use "if" with arrays.
Even for a programmer, array mathematics can take a little getting
used to. Despite what it might sound like, the Ref function isn't
referencing a particular value of an array, but rather returning
another array offset in time (bars) by the reference offset. The
statement "if (Ref(...))" should give an error.
So what you want is VolumeOK to always be False during the first 30
bars of a day, then after that during the same day to be True only if
the sum of the first 30 bars' volume is greater than the average daily
volume of the last 30 days time 0.25?
Should that average daily volume include the current day, even though
it's not complete yet? Assuming not (else it would drag the average
down unless adjusted back to a per-day value), then VolumeOK will be
constant for the rest of the day, since neither OpeningVolume nor the
30-day volume average will change during the rest of the day.
With minute bars, I'm not sure of the easiest way to do daily average
calculations, but assuming for the sake of demonstration that there
are a fixed number of minute bars per day, which I'll call MINPERDAY
(but you'd need to use the actual figure in the code), then I think
you could do something like this:
dn = DateNum();
StartDay = dn != Ref (dn,-1);
VolAvg30 = ValueWhen(StartDay, Sum(Ref(V,-1),30*MINPERDAY)/30);
bss = BarsSince(StartDay);
v30 = Sum(V,30);
OpenVol = IIf(bss==29, v30, IIf(bss>29, Ref(v30,29-bss), 0));
VolOk = OpenVol > VolAvg30*0.25;
Note that I haven't checked any of this, and wouldn't be at all
surprised if it has problems, but it at least conveys the idea. There
may be a better way to get a 30-day average using minute bars, you
might need to check if BarsSince returns zero or one on the StartDay
bar (ie. whether BarsSince starts at zero for the StartDay bar or
one), and there might be a bit of fiddling with exact figures to get
it right (eg. should it be bss==30 or 29, bss>29 or bss>30, and the
usual out-by-one issues that typically occur in this sort of programming).
Hope this helps.
Regards,
GP
--- In amibroker@xxxxxxxxxxxxxxx, "hrokling" <henning@xxx> wrote:
>
> Thanks for that, GP. I should explain that I'm trying to build my
> first system here :)
>
> Using 1-minute bars, I'm trying to calculate the volume for the first
> 30 minutes. Using the DateNum function as a starting point, this is
> what it looks like so far:
>
> dn = DateNum();
> StartDay = dn != Ref (dn, -1);
>
> if (Ref (StartDay, 0))
> OpeningVolume = 0;
> else
> ;
>
> if (Ref (StartDay, -29))
> OpeningVolume = Sum (V,29);
> else
> ;
>
> VolumeOK = IIf (OpeningVolume > (AvgVol30Days * 0.25)), 1, 0);
>
> This use of if-else looks very crude to me, but I'm not familiar
> enough with AFL to make something elegant (and haven't really
> programmed for 10-15 years - a bit rusty). But I want to set the
> OpeningVolume to 0 until I have the OpeningVolume (after 30 minutes),
> at which point I'm comparing it to the average daily volume. Will
> this work?
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@>
> wrote:
> >
> > You could first create a start-of-day signal array by checking for
> the
> > date not being equal to the date of the previous bar. That would be
> > something like this:
> >
> > dn = DateNum();
> > StartDay = dn != Ref(dn, -1);
> >
> > That should give a one at the first bar of each new day.
> >
> > Once you have that, you could sum the volume a few ways, depending
> on
> > exactly where you want the resulting numbers to be. Say you want
> them
> > just on the last bar of those periods, then you could use something
> like:
> >
> > volSum = IIf(Ref(StartDay,-25), Sum(V, 25), 0);
> >
> > That says when the first bar of the day was 25 bars ago, store the
> > value of the 25-bar sum of volume, otherwise store zero. So the
> volSum
> > array would end up full of zeroes except for the 25th bar of each
> day
> > which would have the sum of the previous 25 bars' volume.
> >
> > I don't have intra-day data so can't check this, but I think it
> should
> > work.
> >
> > Regards,
> > GP
>
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|