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

[amibroker] Re: Intra-Day Database Setup



PureBytes Links

Trading Reference Links

Pete,

I am in and out of the office at the moment so I can't give this full attention.

Please note also that how you do it depends on what it is that you want to do (note that TimeframeGetPrice can allow 'looking into the future' in some cases ... as per Tomaz's comments in the manual ... you have to consider the same points, in this regard, as mentioned in Tomasz's current reply to ChristianVost on MA crosses).

Leaving the application to you and just trying to understand TGP a bit more .........

I raised the issue of DatabaseSettings because you did so in the first place and also because it seems to me that timeframe functions need to reference the definition of a day, in some way...... specifically, for TGP(indaily) I assume that the function needs to 'know' the daysession settings.

Checking this with code:

- I used 1 min database
- I changed my DB settings to lastbar == 1559 to get precision for the discussion
- plot the following as an indicator
- in 24 hour view it is difficult to explain the plot
- in day session only view it returns high of previous day session as expected
- however this has nothing to do with BT/Opt modes which is where you want to use it ... I just used the plot for crosschecking AA engine outputs
- running as an exploration, either with Daily or 1min in the settings, gives the same answer as the day session plot i.e. TimeframeGetPrice() seems to automatically reference the daysession.

I am not sure what how the other timeframe functions handle session definitions ... your tests seem to indicate it varies.
Without looking into it, quite likely this is necessary, or at the least useful or both .... Tomasz can do this for us sometimes :-)

Note that I think it is possible to replicate TGP for ourselves, if we want to.
Since bruceR has vouched for Tomasz's programming ability this may not be required and we can just use the builtin function ;-)

Sometimes I write my own version so that I get a better understanding or so that I get control over a certain point of the operation (I think we are better to take control ourselves rather than leave it all to Tomasz and maybe not fully understand, say, why/when we are looking forward ... or perhaps sometimes we want to look forward if we know what we are doing).


PH = TimeFrameGetPrice( "H", inDaily, -1 );//looksback to previous 'day'

//PH = TimeFrameGetPrice( "H", inDaily, -1,expandPoint );
Plot(PH,"PrevHigh",1,1);

Filter = 1;

AddColumn(PH,"PreviousHigh",1.2);


As to how to use it?

There are probably 2-3 ways to do what you want ... it is all up to you.
Notice that if we change to 'expandpoint' version of the function we get an array with all null values and only one PH at the end of every session ... perhaps we could sum 10 of these if we want MA for 10 periods..............

..........this would be similar to (using psuedo code):

1)PH = iif (end of day session, HHV for prev days worth of bars,0);
2)then Sum(PH, number of bars need to make x days);//assumes padded data
3)divide sum(PH) by required daily periods to get required average

Anyway, as I said, there is no point in me doing that until I know exactly what you what and you can't make the journey by yourself (I might not make it back to this topic anyway).


BTW you didn't let us know if Ed's code did the job for you so we don't know where we are up to?


--- In amibroker@xxxxxxxxxxxxxxx, "Pete" <dryheat3@xxx> wrote:
>
> Thanks for suggesting the TimeFrameGetPrice function. I had not tried
> that in any of my code yet. Looks like is does have a lot of potential
> uses.
> My first question would be how you can calculate a daily moving average
> using this function.
> Example:
> TimeFrameGetPrice(MA(C,10), inDaily, 0);
> 
> It is one thing to go and retrieve the desired price element, but then
> to start doing things like moving averages or even more complex things
> like stochastics? I'm afraid we would be right back to using the
> compress/expand statements.
> 
> Gong back to the setup for a moment. I'm embarrased to admit it but up
> until now I have not tried setting the intraday menu to 'Show Day
> Session Only (RTH)". I think I'll give that a try and see if I can get
> it to calcualte a moving average without jumping through all of these
> time hoops.
> 
> thanks again for your input. I'll let you know if that last bit works
> out.
> 
>    Pete  :-)
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> >
> > Pete,
> >
> > Initially I was just thinking to eliminate the possibility that it is
> anything to do with DatabaseSettings. It looks like we have done that
> (it seems that we are agreed that the settings are not the issue and we
> can focus on the code)?
> >
> > Yes, let's see what others have to say.
> >
> > In the meantime ... to eliminate another step ... have you looked at
> TimeFrameGetPrice?
> > It is the one step reference to the DailyH etc, from within an
> intraday database. Tomasz said it is 2* faster than the equivalent
> nested compress/expnand statements.
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Pete" dryheat3@ wrote:
> > >
> > > Brian, thank you for the very thorough response and examples.
> > > I have included below a section of code which demonstrates the very
> different results computed using two different techniques.
> > >
> > > One uses TimeFrameSet() and TimeFrameRestore().
> > > The other uses TimeFrameCompress() and TimeFrameExpand().
> > >
> > > Now matter how I setup the database market hours the time frame
> set/restore method gives inaccurate results, as compared to values
> calculated manually in an excel spread sheet.
> > >
> > > The time frame compress/expand is the only method I've found which
> produces accurate results. However, when you have to call these
> functions dozens of times in a AFL code it drastically slows the
> processing time of backtests and optimizations.
> > >
> > > It is a multi-stage process. First determine values during market
> hours, then compress the result into daily time frame. Once in the daily
> time frame it is now possible to perform operations involving multiple
> days, like calculating moving averages. Once the values are calculated
> you must then expand the variable before it can be used in the intra-day
> time frame.
> > >
> > > This is the reason I am searching for a better solution. If I could
> nest all of my calculations within a single time frame set/restore
> statement I could drastically reduce processing time.
> > >
> > > If someone has a solution to this I would be very grateful to know
> it.
> > >
> > > Thanks.
> > >
> > >   Pete  :-)
> > >
> > >
> > > _Section_Begin("Time Frame Test");
> > > MrktOpn = TimeNum() == 093000;
> > > MrktCls = TimeNum() == 160000;
> > >
> > > TimeBar = TimeNum() >= 160000;
> > > TimeBar2 = TimeNum() < 160000;
> > > EOSTimeBar = TimeBar == 1 AND Ref(Timebar2,-1) == 1;
> > >
> > > //the only way I've found to calculate the true difference
> > > //between daily H and L which are only taken during market hours
> > > DlyHighest = HighestSince(MrktOpn , H);
> > > HighAtClose = ValueWhen(EOSTimeBar , Ref(DlyHighest,-1));
> > > DlyLowest = LowestSince(MrktOpn , L);
> > > LowAtClose = ValueWhen(EOSTimeBar , Ref(DlyLowest,-1));
> > > TRUE_DlyDiff = HighAtClose - LowAtClose ;
> > > //then it needs to be compressed before using it to calculate
> > > //a daily moving average of the difference between H and L
> > > tfc_DlyDiff = TimeFrameCompress(TRUE_DlyDiff, inDaily,
> compressLast);
> > > TRUE_DlyMA = MA(tfc_DlyDiff,10);
> > > //then it gets expanded for use in Ploting to other method of
> > > //display
> > > tfeDlyMA = TimeFrameExpand(TRUE_DlyMA,inDaily);
> > >
> > > //What I would prefer to use is the timeframeset, use it once
> > > //and perform various calcluations like the one above and have
> > > //it accurately produce results. If you check the values calculated
> > > //using the timeframeset section below against values manually
> > > //calculated in a spread sheet you will see they are including
> > > //data from outside of market trading hours.
> > > TimeFrameSet(inDaily);
> > > FALSE_DlyDiff = H-L;
> > > FALSE_DlyMA = MA(HighAtClose - LowAtClose, 10);
> > > /*
> > > it does not work no matter what you try here:
> > > FALSE_DlyMA = MA(H - L, 10);
> > > FALSE_DlyMA = MA(FALSE_DlyDiff, 10);
> > > */
> > > TimeFrameRestore(inDaily);
> > >
> > > //plot to compare false results to true.
> > > Plot(TimeFrameExpand(FALSE_DlyDiff,inDaily), "FALSE Daily Diff",
> colorBlue, styleDashed);
> > > Plot(TRUE_DlyDiff, "TRUE Daily Diff", colorBlack, styleDots);
> > >
> > > Plot(TimeFrameExpand(FALSE_DlyMA,inDaily), "FALSE Dly MA", colorRed,
> styleDashed);
> > > Plot(tfeDlyMA , "TRUE Dly MA", colorRed, styleLine);
> > > _Section_End();
> > >
> >
>




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

**** 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:
    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/