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

[amibroker] Re: Separate MA for normal and after hours trading


  • Date: Fri, 26 Feb 2010 06:07:43 -0000
  • From: "Barry" <razzbarry@xxxxxxxxxxxx>
  • Subject: [amibroker] Re: Separate MA for normal and after hours trading

PureBytes Links

Trading Reference Links

Thanks for the details.  The MA will be the hardest.  I don't know if the number of bars to omit is determinable. I looked at my database and I have the time stamp based on start of time interval.  If it is based on tick then I am not sure what would happen if there were no ticks in a bar.  Then some tickers don't have 24 hour data.  I just looked a AGU and DIA and both have missing bars in off hours.  

I guess the cleanest way would be to use a DLL and I will give that a go. I am not sure what I will do when there is no ticks in a bar. The volume would be 0. And if you build the arrays based on time of day then the MA calculation would be easy. Or so I think.  I will find out.

Barry  

--- In amibroker@xxxxxxxxxxxxxxx, Keith McCombs <kmccombs@xxx> wrote:
>
> Barry --
> You were perfectly clear the first time.
> Code for BEMAD and BEMAN, EMAs for day and night respectively:
> 
> |// Barry's day and night EMAs
> BPD = 50; // period of 50 bars for daytime
> BKD = 2/(1+BPD);
> BEMAD[0] = *Close*[0]; // best guess for start
> 
> BPN = 70; // period of 70 bars for nighttime
> BKN = 2/(1+BPD);
> BEMAN[0] = *Close*[0];
> 
> ||TM = TimeNum();
> *for*(i=1; i<*BarCount*; i++){
> *if*(TM[i]>=93000 *AND* TM[i]<=161500){
>        BEMAD[i] = BEMAD[i-1]*(1-BKD) + *Close*[i]*BKD;
>        BEMAN[i] = BEMAN[i-1];
>     }*else*{
>        BEMAN[i] = BEMAN[i-1]*(1-BKN) + *Close*[i]*BKN;
>        BEMAD[i] = BEMAD[i-1];
>     }
> }
> ||
> |
> The MA is a little more difficult, but simplified a little if you can 
> calculate precise number of bars to look back for the value to subtract 
> (which bar is C[i-p]?).
> MA[i] = MA[i-1] + C[i]/p - C[i-p]/p;
> And for MA, you might also need to use SetBarsRequired().
> -- Keith
> 
> On 2/25/2010 17:31, Barry wrote:
> >
> > Maybe I did not explain this well enough. I define day as
> > daytime = TimeNum() >= 093000 AND TimeNum() <= 161500;
> > Then I want to do an MA on only day time bars or not-day time bars. 
> > This will produce voids in the arrays. For instance there will be 27 
> > 15 minute day time bars and 69 15 minute off hours bars. If I do a 
> > simple MA(V, 50) it will average the last 50 bars regardless of 
> > whether they are day or night time bars. The data I average will span 
> > day and night volume numbers giving an inaccurate MA. I would have to 
> > use a loop and use the value of the last 50 day only or night only 
> > bars. I can't figure out how to do that.
> >
> > The code would be a lot easier in a DLL since I could have two arrays 
> > and store the correct data contiguously in one of two arrays. But I 
> > don't know how that would match up with AFL arrays or even if would 
> > have to. I have not written a DLL but I know MS C++ foundation classes.
> >
> > Anyway, if it is a simple matter in AFL it escapes me how to manage 
> > the arrays. Maybe I am making it harder than it needs to be.
> >
> > Thanks,
> > Barry
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>, 
> > Keith McCombs <kmccombs@> wrote:
> > >
> > > Barry --
> > > Calculating EMAs and MAs should be possible, and of only intermediate
> > > difficulty, using AFL. EMAs will be a bit easier than MAs. The reason
> > > being that calculating an EMA requires only 2 pieces of data, previous
> > > bar's EMA and this bar's data. Of course, you will have to construct
> > > your own EMA because you will need to stop calculating each EMA at the
> > > end of its time period and then continue when its time period begins 
> > again.
> > >
> > > As for MAs, they really require only 3 pieces of data, previous bars 
> > MA,
> > > this bars data, and data of one bar, P bars ago (in the correct time
> > > period), where P is MA period.
> > >
> > > One problem you may run into, especially with off hours data, is 
> > what to
> > > do if volume is zero. Is a bar created in this case? If not, what are
> > > you going to do about it?
> > >
> > > BTW, AB&IB seems to create zero volume bars when backfills are 
> > complete,
> > > though 180days are problematic. Some other data providers, PItrading
> > > for example, just leave zero volume bars out.
> > >
> > > -- Keith
> > >
> > >
> > >
> > > On 2/25/2010 12:06, Barry wrote:
> > > >
> > > > I am trying to create two moving averages, one for normal trading
> > > > hours volume and the other for the off hours volume. When futures are
> > > > trading during the day the volume is much higher than off hours. 
> > Using
> > > > an MA of say 50 bars gives an incorrect look at the volume until 50
> > > > bars into the new time period. However, if one were using hour or 15
> > > > minute charts the MA could span days. It would be clearer or more
> > > > accurate if one could only use the applicable volume when calculating
> > > > the MA for normal hours vs off hours trading.
> > > >
> > > > Has this been done in AFL? Can it be done in AFL? Is there an AFL
> > > > function that can separate the day and night session data? Can it be
> > > > done in the context of AFL or would one have to use a DLL to build
> > > > separate arrays that only contain values from the two time periods?
> > > >
> > > > I have tried a number of methods in AFL but none work correctly.
> > > > Managing the arrays in AFL and trying to ignore spans of bars is
> > > > blowing my mind.
> > > >
> > > > Thanks,
> > > > Barry
> > > >
> > > >
> > >
> >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/