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

Re: [amibroker] Need some help with ATC and making continuous contract futures



PureBytes Links

Trading Reference Links

This post contains a few posts down the thread that did not make it onto the email list for some reason in the last couple of days.

Herman,

As a followup point of interest, I was able to get the execution time of my continuous contract (CC) AFL cut from 800ms down to 250ms per pass.  The method I used was to avoid writing the ATC ticker (or processing the whole array) except on a new bar.  In order to tell if it was a new bar on the main chart (since the CC AFL chart is running in 5 second timeframe), I had to have the main chart send information via static variables to the CC chart.  Things like the time of the start of the last bar, the timeframe mode and interval and an update on demand flag in case of a relevant parameter change.   

I then scanned the 5 second bars since the time the last main chart bar was started to determine if the criteria was met for the main chart to make a new bar.  Only then did I update the ATC ticker.

In the mean time, I sent the OHLCV info about the last bar to the main chart through static variables so it could keep the last bar updated in realtime.

I will post the AFL if anyone wants to see it --about 100 lines of AFL to make it work --not including a few lines in the main chart to pass the info back and forth.  Much more complex than my first attempt at the start of this thread.  The same method can be used to speed up other types of pre-processor filters.

So to answer my own question --yes, there is a faster way.  

Best regards,
Dennis

On Dec 19, 2007, at 12:01 PM, Dennis Brown wrote:

Thanks Herman,

For now, I will collect bars from the ES continuous contract as the closest thing I can get to a reference ticker.  In another 10 days I should have enough for a rough one month template (as long as I keep it up to date).  Not perfect, but all I got.  

Yes, this method of ticker generation by SetForeign() and ATC is very slow.  It is the ATC that is so slow, because it shuts off fast AFL and requires multiple file writes.  It has to do this to make sure that a whole ticker is written out.  It would actually be 4 times faster to read in the two contract tickers directly into the main chart with a 5 second timeframe and then work in other timeframes after that (200ms vs 800ms).  This is my preferred ultimate goal.  

However, The studies and date/time axis are locked to the 5 second timeframe, making this method useless for realtime discretionary trading.  

To make my ideal trading system fully operational would require 4 linked charts running in 4 different timeframe modes (Range, Volume, Time, and 5 second time).  It is quite painful and slow.

If AFL could work in the base timeframe (5 seconds) independent of the specified chart displayed timeframe, a whole lot of my problems would go away.  I would no longer have to make unnatural workarounds with one chart running in 5 second timeframe writing out tickers for another chart that runs in another timeframe.  

The greatest obstacles I have had with AB and AFL stem from different internal operating modes that are linked together at the UI level or even AFL level.  There are many things that I would like to do that require more flexibility in what can be specified from AFL.  I spend 90% of my time writing and debugging UI workarounds to get what I want --and I still end up with half successful slow kludges.  

I understand Tomasz's reasons for his choices that evolved over time, but some devolution could be put to good use by those of us who are gaining more skill with AFL and want to take advantage of our ideas in actual trading using AB.

Best regards,
Dennis

On Dec 18, 2007, at 5:47 PM, Herman wrote:

A DateTime reference ticker could be selected in AA settings as the reference for stuffing bars. This would allow a much more rigid way of performing TA. Right now all TA is based on the assumption that your have an ideal reference ticker (no holes). I don't have a single one that perfect in my DB and I doubt that anyone else has.

It would be preferential to be able to create a composite with a perfect and continuous datetime sequence. Perhaps this could be done with an additional flag for the ATC.

Note too that using the SetForeign() or Foreign() are extremely slow since they (I assume) call up all available data, and not only the Quick-AFL range.

good luck,
herman

For tips on developing Real-Time Auto-Trading systems visit:

Tuesday, December 18, 2007, 5:19:31 PM, you wrote:

>
Herman,

Thanks for the reply.  I thought about making a reference, but it would have to be updated every 5 seconds with a new bar and the whole thing written out again with ATC, and that would take too long even if I knew how to do it.  

The real solution would be to have a fake reference ticker in the local database that makes a new bar at every interval.  
This should be quite easy! --I just put that in there to make Tomasz cringe ;-)

Seriously though, a time reference ticker in the local database would be an ideal solution and it would not require any changes to AB or AFL to make it work --just a special ticker symbol.  SetBarsRequired() could guarantee you get as many bars as you need.

Did you put in a request for this? Oh, I see that you did in feature request #807  --I will vote for it ten times over.

Optionally, I guess that AB could recognize a special ticker name and instead of going to the database, just create the bars on the fly.
Another way would be to have a preference that would pad and align all data to an ideal reference --though I would rather it be something like a parameter in SetBarsRequired() that would turn this on and off.

Several possible ways to do this someday, but I only have a week before my current method fails.  I can live with holes as long as every bar that is in both contract tickers is in the array.  Is there a way to merge the two tickers in an indicator to cover all bars in both?

Best regards,
Dennis


On Dec 18, 2007, at 4:00 PM, Herman wrote:


I think you are looking for a continuous DateTime reference array; there is no such thing in AmiBroker. No matter how carefully you manage your data there will be holes. The need for such a reference array is outlined in a post on Data Holes in Real-Time Trading One way of constructing it is using the calculations outlined in the posts Time calculations and Date Calculations . The calculations are intensive and timeconsuming. The reference arrays calculated would have to be stored in Composite files created with the AddToComposite(). I found the calculations and use of composites too slow for us in real time trading with with 5 second data. I was using up to 500,000 bars. There were some discussions on this list on this topic however the best suggestion that surfaced was to do the calculations off line, and import the data with the import wizard. However this process doesn't help the real time trader.

Season's Greetings,
herman



For tips on developing Real-Time Auto-Trading systems visit:

Tuesday, December 18, 2007, 3:37:38 PM, you wrote:

> Hi all,

> I needed to have a months worth of ES (S&P 500 eMini) 5 second data  
> for my backtesting.  eSignal only provides 10 days of backfill though  
> for the 5 second data.  They have a continuous contract, but when it  
> rolls over it changes the oldest prices, so it would have to be  
> backfilled.  I have collected 200K bars of the December contracts  
> which just rolled to the March contracts.

> I wrote an AFL to produce a continuous contract for ES by combining  
> the two contracts into an ATC ticker (~ES).  Then I use this ticker  
> to run my real time indicator chart of ES.   I have only run into two  
> problems.  The first is it takes almost one second to run the AFL to  
> generate the real time contract ticker.  The second is I need to have  
> that chart ticker pointing to something that has all the 5 second  
> bars for 30 days back in order for the other two contracts to have a  
> place to store their quotes (using foreign).  I don't have such a  
> beast.  The closest I can come is to use the oldest contract ticker  
> which will work for a week until the contract expires.

> With all that background, here are my questions:

> Is there a faster and easier way to do this?

> I need all the bars in both the two contract tickers to merge them.   
> How do I get all the bars I need to make my 200K bar ATC ticker?

> Thanks for your help.  Here is my AFL.

> //////////////////////////////////////////////////////////////////////// 
> ///
> // Continious Contract on 5 sec database (by Dennis Brown 12/16/2007)
> //
> // This chart is used to generate Continious Contract data for  
> another chart.
> // This runs on a 5 second database to merge contract prices and volume.
> // Last quarters contract prices are adjusted down by the premium.
> // Volumes are just added.
> // Merged data is saved to "~ES" ATC ticker every pass.
> // Edit the Tick size: .25, and Point value: 50 for the ~ES ticker
> // Other chart must use the ticker "~ES".
> //
> // set the realtime data also using static variables
> // "bidRT","askRT","lastRT"

> Version(5.0); //minimum version required
> SetChartOptions(2,chartShowDates);
> SetBarsRequired(1000000,1000000);
> tick = TickSize; if(tick==0){tick=.01;}
> flag=0;

> function StaticArraySet(VarName,array){AddToComposite 
> (array ,"~SA_"+VarName ,"X",atcFlagEnableInIndicator|atcFlagDefaults);}

> //ChartTicker = StaticVarGetText("ChartTicker"); //name from main chart

> //if(ChartTicker =="~ES"){
> ATCname="~ES"; OldContract="ES Z7"; NewContract="ES H8"; flag=1;
> //}
> if(flag)
> {
>         SetForeign(OldContract); //older ticker
>         O1=O; H1=H; L1=L; C1=C; V1=V;
>         Title=OldContract + " Through "+ NewContract;
>         SetForeign(NewContract); //newer ticker
>         diff = MA((H1+L1)/2,2160) - MA((H+L)/2,2160); //3 Hour average price  
> difference
>         Vxover = MA(V,17280) > MA(V1,17280); //24 hr ave volume crossover
>         for(i=BarCount-1; i>0 AND Vxover[i]==1; i--){V[i]+=V1[i];} //add  
> both volumes together
>         delta = round(diff[i]*(1/tick))/(1/tick); //move to closest tick
>         for(i=i; i>=0; i--)
>                 {O[i]=O1[i]-delta; H[i]=H1[i]-delta; L[i]=L1[i]-delta; C[i]=C1[i]- 
> delta; V[i]+=V1[i];} //offset old array bars

>         AddToComposite(O ,ATCname ,"O",atcFlagEnableInIndicator| 
> atcFlagDeleteValues);
>         AddToComposite(H ,ATCname ,"H",atcFlagEnableInIndicator);
>         AddToComposite(L ,ATCname ,"L",atcFlagEnableInIndicator);
>         AddToComposite(C ,ATCname ,"C",atcFlagEnableInIndicator);
>         AddToComposite(V ,ATCname ,"V",atcFlagEnableInIndicator);

>         StaticVarSet("bidRT",GetRTDataForeign("Bid",NewContract));
>         StaticVarSet("askRT",GetRTDataForeign("Ask",NewContract));
>         StaticVarSet("lastRT",GetRTDataForeign("Last",NewContract));
> }
> //Plot(C,"",IIf(Vxover,colorBlack,colorRed),styleBar);
> //Plot(V,"",colorLightGrey,styleHistogram|styleOwnScale);
> RequestTimedRefresh(2,0);


__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___