Author Topic: Add to composite asx200 stocks  (Read 10834 times)


  • Newbie
  • *
  • Posts: 4
    • View Profile
Add to composite asx200 stocks
« on: February 07, 2011, 06:06:53 pm »
Hi how's it going?

I thought I was doing something that would be quite simple but not to be.

I use e-signal RT data, amibroker and windows 7.

I want to make my own index composite of ASX (S&P) 200 stocks in amibroker, then a intraday advance-decline line and intraday cumulative tick chart for these ASX200 stocks.

I can't get past the first one! I'm trying to use AddToComposite to make a composite index from the 200 stocks that make up the ASX(S&P200) in a watchlist.  I'm just testing it witha  few stocks first.  I run the following AFL in scan mode using the watchlist I created.

AFL Code:

AddToComposite(InWatchList(0)*Var,"~Watch1Comp","X ");

It seems to work and I get a composite for the stocks in the watchlist but I get the following error (because I want to run this on 5 min intervals this error will become very annoying):

Error 32.
Syntax error, probably missing semicolon at the end of the previous line

This is where I'm getting the information from on AddToComposite

If anyone could help me in achieving this it would be great, knowing this will most likely help your trading as well.

I want to create:

- composite index from ASX (S&P) 200 stocks
- intraday advance decline line asx200
- intraday cumulative tick chart asx200




  • Administrator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Add to composite asx200 stocks
« Reply #1 on: February 08, 2011, 05:39:09 pm »

Your code looks fine. Are you deleting the composite before running the scan? If not I would try that and see if it works because mixing EOD with Intraday could be the problem.


  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Add to composite asx200 stocks
« Reply #2 on: February 08, 2011, 07:13:30 pm »

yeah you are right it was the EOD with Intraday causing the problem or simply an incorrect price chart.

Here is the codes:

Creating a Composite Index from a group of stocks:
AddToComposite(L, "Index" ,"L");
AddToComposite(O, "Index" ,"O");
AddToComposite(H, "Index" ,"H");
AddToComposite(C, "Index" ,"C");
AddToComposite(V, "Index" ,"V");

Creating a composite for Advance-Decline line for a group of stocks:
AddToComposite(IIf(Close - Ref(Close, -1) > 0, 1, 0), "~Adv", "X" );
AddToComposite(IIf(Ref(Close, -1) - Close > 0, 1, 0), "~Dec", "X" );

Custom chart:
A=(Foreign("~Adv","C") - Foreign("~Dec","C"));
Plot(A,"Close",ParamColor("Color", colorRed ), styleLine | ParamStyle("Style") | GetPriceStyle() );

Creating a composite for Advance-Decline Volume for a group of stocks:
AddToComposite(IIf(Volume - Ref(Volume, -1) > 0, Volume, 0), "~AdvVol", "X" );
AddToComposite(IIf(Ref(Volume, -1) - Volume > 0, Volume, 0), "~DecVol", "X" );

Custom chart:
A=(Foreign("~AdvVol","C") - Foreign("~DecVol","C"));
Plot(A,"Close",ParamColor("Color", colorBlue ), styleLine | ParamStyle("Style") | GetPriceStyle() );

I hope this helps someone in the future.

Now all I have to do is figure out how to make a tick chart (the same as the NASDAQ $TICK or $TICKQ indictors).

This is the general formula for the tick indicator: if (last tick) > (last tick[previous]) then tickx = tickx + 1 else tickx = tickx - 1

I just need to get that code into amibroker.

The problem with the advance-decline line is it is dependent on time.  It references back a certain time period.  What I need is to just get the previous closing price on the previous tick. I don't want it to be time dependent, I just want to know if the current tick is an uptick or a downtick.

Uptick - last closing price higher than previous closing (traded) price
Downtick - last closing price lower than previously closing (traded) price
Level tick - no change

I found this in another forum, it explains how to do it, but I just don't have experience to do it:

You can create a tick preprocessor by collecting Ticks, just check whether the previous tick is equal to the current one, if not store it in a static tick buffer. I convert the tick prices to strings and store/read them in a string variable using StaticVarSetText(). When you extract the tick array from the string buffer you copy it to a normal array variable so you can apply the usual indicators to it, collect tick statistics, upticks/downticks, etc..

This way can create your own scrolling tick chart (indicator) without using any timeframes. It will work in any RT database, so you can display ticks without having to maintain a huge tick database. I use tick-charts with my 1-minute database with 1-second refresh, it works fine up to a few hundred ticks and that is all I need to improve entry/exit points. You can make up a custom x-axis to indicate bar-bounderies.

Here is some of the code but I'm not sure how to apply it:

Reset = Param("Reset Static Variables",0,0,1,1);

if( IsEmpty(StaticVarGet("IsInitialized")) OR Reset) // An Optional Reset is done with a Param() item
//... add your own variables here ...
StaticVarSet("UpTicks", 0);
StaticVarSet("IsInitialized",1); // This is set once for every AB run and is never reset

//... add your own variables here ...
Downticks = StaticVarGet("DownTicks");
Upticks = StaticVarGet("UpTicks");

ChartID = NumToStr(GetChartID(),1.0,False);
Reset = Param("Reset Static variables",0,0,1,1);
StaticScope = Param("Scope (0:Local,1:Global) for
if( StaticScope ) Scope = ""; else Scope = ChartID;
if( IsEmpty( StaticVarGet("TickCounter"+Scope)) OR Reset)
TickCount = StaticVarGet("TickCounter"+Scope);

Thank you,