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

[amibroker] Re: Duplicating Symbols


  • Date: Fri, 15 Jan 2010 20:43:55 -0000
  • From: "Mike" <sfclimbers@xxxxxxxxx>
  • Subject: [amibroker] Re: Duplicating Symbols

PureBytes Links

Trading Reference Links

David,

Keep in mind that if you use a local datasource, your PremiumData updates will not be reflected going forward. You will have to switch back to Metastock mode to receive the updates, as per their website:  "How can I increase the scanning speed of AmiBroker?" http://www.premiumdata.net/support/amibroker.php

Actually, I'm a bit surprised, I would expect that any new symbols created would be going into the local database kept by AmiBroker (for things such as composites) even when in Metastock format.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" <dbw451@xxx> wrote:
>
> I figured out how to get the symbol duplicating code to work.  Both the AFL code that Mike posted and the javascript that I later posted work.  The issue is database settings.  PremiumData is setup using the MetaStock plug-in and for some reason setting quotes through ActiveX does not work when the datasource is the MetaStock plugin.  If I set the database source to local, then setting quotes through ActiveX works.
> 
> Since the AFL code for duplicating symbols that Mike posted earlier in this thread is much shorter than the equivalent javascript code, there is no sense in me posting the javascript code.
> 
> Regards,
> 
> David
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" <dbw451@> wrote:
> >
> > I've been unsuccessful in filling a duplicate symbol with quotes from a
> > source symbol.  I could not make it work in AFL, so I reluctantly
> > switched to javascript and I still cannot get quote data into a new
> > symbol.  I guess I'm too close to my code because I cannot see what is
> > wrong.  Can anyone see why the code below will not update a new symbol
> > with quote data?  The new symbol is created fine, but the quotes are not
> > added.   (Note: the code below has been reduced to only write the Close
> > array to the duplicate symbol).
> > Thanks,
> > David
> > 
> > // // AmiBroker javascript OLE code to copy close data from a symbol to
> > a duplicate symbol //
> > EnableScript("jscript");
> > Buy = Sell = 0;
> > ScanActive = "FALSE";if ( Status( "action" ) == actionScan )  ScanActive
> > = "TRUE";
> > abTicker = Name(); abYear = Year();abMonth = Month();abDay = Day(); <%
> > function GetArray( abName ){   return VBArray( AFL( abName )
> > ).toArray();}
> > jsScanActive = AFL("ScanActive");
> > if (jsScanActive == "TRUE"){ jsTicker = AFL.Var("abTicker"); jsYear =
> > GetArray("abYear"); jsMonth = GetArray("abMonth"); jsDay =
> > GetArray("abDay"); jsClose = GetArray("Close");
> >      AB = new ActiveXObject( "Broker.Application" );     oStocks =
> > AB.Stocks;     oSymbol = oStocks.Item( jsTicker );
> >      for ( m = 2; m <= 3; m++ )     {         TickerNew = jsTicker + "_"
> > + m;         oSymbolNew = oStocks.Add( TickerNew );
> >         for ( i = 0; i < jsDay.length; i++ )         {    oDate = new
> > Date( jsYear[i] + "-" + jsMonth[i] + "-" + jsDay[i] );            oQuote
> > = oSymbolNew.Quotations.Add( oDate.getVarDate() );            
> > oQuote.Close = jsClose[i];        }   }
> >    AB.RefreshAll();  AB.SaveDatabase(); }%>
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" <dbw451@> wrote:
> > >
> > > Excellent Mike! Great suggestions.  However the results of your
> > modifications is similar to the results I was getting before.  The code
> > produces duplicate symbols with no quote data.  Something is still not
> > quite right with copying the quote data from the source symbol to the
> > new duplicate symbol.  I had previously surmised that the problem
> > probably lies with the Quotations.Add() routine not being passed a
> > proper date value. Most of the examples I could find for
> > Quotations.Add() are in jscript and the date parameter is formated as a
> > VT_DATE type (usually through the jscript date routine getVarDate())  or
> > as a string of format YYYY-MM-DD.
> > >
> > > I'm making an assumption that Quotations.Add() is not adding quote
> > data records because my chart shows the message "To plot any chart at
> > least 3 data bars are needed, but there are only 0 bars..." for each of
> > the new duplicate symbols.  I wanted to keep the code in AFL, but maybe
> > there's a reason there are no examples of Quotations.Add() in AFL and
> > the only way to get this to work is to convert to jscript.
> > >
> > > Regards,
> > >
> > > David
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" sfclimbers@ wrote:
> > > >
> > > > Try using DateTime instead. Also, the property is OpenInt, not
> > > > OpenInterest. Finally, rather than entering all the tickers
> > manually,
> > > > just run a Scan over a watchlist of desired tickers.
> > > > e.g. using a simplified version of your original post:
> > > > //
> > > > // AmiBroker OLE code to Duplicate a list of Symbols
> > > > //
> > > >
> > > > Buy = Sell = 0;
> > > >
> > > > if ( Status( "action" ) == actionScan )
> > > > {
> > > >      Ticker = Name();
> > > >      Dates = DateTime();
> > > >      AB = CreateObject( "Broker.Application" );
> > > >      oStocks = AB.Stocks;
> > > >      oSymbol = oStocks.Item( Ticker );
> > > >
> > > >      for ( m = 2; m <= 12; m++ )
> > > >      {
> > > >          TickerNew = Ticker + "_" + m;
> > > >          oSymbolNew = oStocks.Add( TickerNew );
> > > >
> > > >          oSymbolNew.FullName = oSymbol.FullName;
> > > >          oSymbolNew.Currency = oSymbol.Currency;
> > > >          oSymbolNew.Continuous = oSymbol.Continuous;
> > > >          oSymbolNew.MarketID = oSymbol.MarketID;
> > > >          oSymbolNew.GroupID = oSymbol.GroupID;
> > > >          oSymbolNew.IndustryID = oSymbol.IndustryID;
> > > >          oSymbolNew.DataLocalMode = oSymbol.DataLocalMode;
> > > >          oSymbolNew.RoundLotSize = oSymbol.RoundLotSize;
> > > >          oSymbolNew.MarginDeposit = oSymbol.MarginDeposit;
> > > >          oSymbolNew.TickSize = oSymbol.TickSize;
> > > >          oSymbolNew.PointValue = oSymbol.PointValue;
> > > >
> > > >          for ( i = 0; i < BarCount; i++ )
> > > >          {
> > > >              oQuotations = oSymbolNew.Quotations;
> > > >              oQuote = oQuotations.Add( NumToStr( dates[i],
> > formatDateTime
> > > > ) );
> > > >              oQuote.Open = O[i];
> > > >              oQuote.High = H[i];
> > > >              oQuote.Low = L[i];
> > > >              oQuote.Close = C[i];
> > > >              oQuote.Volume = V[i];
> > > >              oQuote.OpenInt = OI[i];
> > > >          }
> > > >      }
> > > >
> > > >      AB.RefreshAll();
> > > >      AB.SaveDatabase();
> > > > }
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" <dbw451@> wrote:
> > > > >
> > > > > Using OLE objects in AFL, what is the Date parameter format passed
> > to
> > > > the Quotations.Add() routine?  I've tried DateNum values, DateTime
> > > > values, and strings of Year + "-" + Month + "-" + Day.  I've been
> > > > unsuccessful in adding a quote to a new Symbol created with
> > > > Stocks.Add().
> > > > >
> > > > > Here's the relevant code (where oSymbolNew is a Stock object
> > created
> > > > earlier in the code with AB.Stocks.Add()):
> > > > >
> > > > >  qDay = Day();
> > > > >  qMonth = Month();
> > > > >  qYear = Year();
> > > > >  oQuotations = oSymbolNew.Quotations;
> > > > >
> > > > >  for(i=0; i<BarCount; i++)
> > > > >  {
> > > > >  qDate = "" + qYear[i] + "-" + qMonth[i] + "-" + qDay[i];
> > > > >  oQuote = oQuotations.Add( qDate );
> > > > >  oQuote.Close = C[i];
> > > > >  }
> > > > >
> > > > >
> > > > > Thanks,
> > > > >
> > > > > David
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" dbw451@ wrote:
> > > > > > I've attempted to code functionality to duplicate symbols using
> > the
> > > > AmiBroker OLE interface.  In my test code below, 2 symbols ($A0 and
> > $CA)
> > > > are attempted to be duplicated into symbols $A0_2, $A0_3, $CA_2, and
> > > > $CA_3.  The duplication process entails:
> > > > > >
> > > > > > 1. adding a new symbol
> > > > > > 2. setting the new symbol information using the source symbol
> > > > information
> > > > > > 3. adding new symbol quotes and assigning source symbol quote
> > > > values.
> > > > > >
> > > > > > My test code creates a new symbol ($A0_2) and assigns the
> > FullName
> > > > and Currency, but does not assign any other symbol information.  The
> > > > code also does not create the quotes for the new symbol.  The
> > > > SaveDatabase() routine is reached and executed.  The code then
> > generates
> > > > an "unhandled application error" probably caused by
> > RestorePriceArrays()
> > > > to a new symbol that has no quotes.
> > > > > >
> > > > > > Can anyone tell me what's wrong with the following code?
> > > > > >
> > > > > > //
> > > > > > // AmiBroker OLE code to Duplicate a list of Symbols
> > > > > > //
> > > > > > DuplicateTickers = ParamTrigger("Duplicate Tickers", "Click here
> > to
> > > > Duplicate Tickers");
> > > > > > TickerList = ParamStr("Tickers to Duplicate","$AO,$CA");
> > > > > > MaxTickerNum = Param("Max Ticker Number",3,2,12,1);
> > > > > >
> > > > > > if(DuplicateTickers)
> > > > > > {
> > > > > >
> > > > > >  AB = CreateObject("Broker.Application");
> > > > > >  oStocks = AB.Stocks;
> > > > > >  for (m=2; m<=MaxTickerNum; m++) // Loop through each duplicate
> > > > > >  {
> > > > > >   for(n=0; (Ticker=StrExtract( TickerList, n))!=""; n++) // Loop
> > > > through each symbol
> > > > > >   {
> > > > > >    oSymbol = oStocks.Item( Ticker );
> > > > > >
> > > > > >    TickerNew = Ticker + "_" + m;
> > > > > >    oSymbolNew = oStocks.Add( TickerNew );
> > > > > >
> > > > > >    oSymbolNew.FullName = oSymbol.FullName;
> > > > > >    oSymbolNew.Currency = oSymbol.Currency;
> > > > > >    oSymbolNew.Continuous = oSymbol.Continuous;
> > > > > >    oSymbolNew.MarketID = oSymbol.MarketID;
> > > > > >    oSymbolNew.GroupID = oSymbol.GroupID;
> > > > > >    oSymbolNew.IndustryID = oSymbol.IndustryID;
> > > > > >    oSymbolNew.DataLocalMode = oSymbol.DataLocalMode;
> > > > > >    oSymbolNew.RoundLotSize = oSymbol.RoundLotSize;
> > > > > >    oSymbolNew.MarginDeposit = oSymbol.MarginDeposit;
> > > > > >    oSymbolNew.TickSize = oSymbol.TickSize;
> > > > > >    oSymbolNew.PointValue = oSymbol.PointValue;
> > > > > >
> > > > > >    SetForeign( Ticker );
> > > > > >    qDate = DateNum();
> > > > > >    for(i=0; i<BarCount; i++)
> > > > > >    {
> > > > > >     oQuotations = oSymbolNew.Quotations;
> > > > > >     oQuote = oQuotations.Add( qDate[i] );
> > > > > >     oQuote.Open =  O[i];
> > > > > >     oQuote.High =  H[i];
> > > > > >     oQuote.Low =   L[i];
> > > > > >     oQuote.Close = C[i];
> > > > > >     oQuote.Volume = V[i];
> > > > > >     oQuote.OpenInterest = OI[i];
> > > > > >    }
> > > > > >
> > > > > >    AB.RefreshAll();
> > > > > >    AB.SaveDatabase();
> > > > > >    RestorePriceArrays();
> > > > > >   }
> > > > > >  }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > David
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "dbwyatt_1999" <dbw451@>
> > wrote:
> > > > > > >
> > > > > > > I've got a system that consists of 12 models.  For each model,
> > > > I've defined a watchlist that has unique symbol names that are only
> > used
> > > > by a single model.  The unique symbol names are duplicates of a
> > source
> > > > symbol with incremental numbers attached (e.g. ES, ES_2, ES_3, ...,
> > > > ES_12).  I create the duplicate symbols by starting with an ASCII
> > file
> > > > which I import, rename, import again, rename, import again, etc. 
> > Then I
> > > > have to go into Symbol information for each symbol and manually
> > enter
> > > > the contract specifications (lot size, margin, tick size, point
> > value).
> > > > > > >
> > > > > > > I now have a new requirement for 55 additional instruments and
> > > > have obtained historical futures data from PremiumData.  The 55
> > > > instruments were very easy to load and PremiumData has predefined
> > the
> > > > contract specifications.  Now I need to somehow duplicate the 55
> > > > instruments 11 times into 660 total symbols.  I have not found a
> > native
> > > > way in AB to duplicate (or rename) symbols.  I can export the data
> > using
> > > > AFL, but import files don't include the symbol information.
> > > > > > >
> > > > > > > Duplicating a symbol looks like it can be done using the
> > Amibroker
> > > > activeX object.  Before I embark on a new programming task, I
> > thought
> > > > I'd ask if anyone has written a script to duplicate an AB symbol:
> > > > > > >
> > > > > > > 1. creates a new symbol.
> > > > > > > 2. copies the quote data from a source symbol to the new
> > symbol.
> > > > > > > 3. copies the symbol information from the source symbol to the
> > new
> > > > symbol.
> > > > > > >
> > > > > > > Ultimately, I would like to loop through a watchlist 11 times;
> > > > creating and updating duplicate symbol quotes and information.  Any
> > > > directions or suggestions would be great.
> > > > > > >
> > > > > > > Thanks,
> > > > > > >
> > > > > > > David
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>




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

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