PDA

View Full Version : Referencing the index when scanning individual stocks


adrian77
21st November 2007, 10:17 PM
I am trying to reference the ASX200 index to form part of my entry and exit rules for trading an indivual stock...but I can't seem to get the Metastock explorer to do this correctly - it breaks down when the stock that I am scanning does not trade every day, so i am getting signals when there should not be signals.

Am I doing something incorrect in the code below? I would like to enter only when my entry condition is true AND the ASX200 is above its 200 day moving average...

ASXTrend:=If(Security("C:\Trading Data\Stocks\ASX\Indices\XJO",C)>Mov(Security("C:\Trading Data\Stocks\ASX\Indices\XJO",C),200,E),1,-1);

EntryTrigger:=
Cross(MOV(C,10,S),MOV(C,30,S))=1 AND
C>Mov(C,200,S) AND
ASXTrend=1;

I have also just plotted the ASXTrend on a range of individual stock charts and it doesn't seem to line up the dates correctly when a stock has days where there is no trading.

Any help with this problem would be much appreciated!!

Jose
21st November 2007, 11:20 PM
Try this:


Idx:=Security("C:\Trading Data\Stocks\ASX\Indices\XJO",C);
ASXTrend:=Idx>Mov(Idx,200,E);

EntryTrigger:=
Cross(Mov(C,10,S),Mov(C,30,S))=1
AND C>Mov(C,200,S)
AND ASXTrend;


jose '-)

adrian77
22nd November 2007, 03:24 AM
Jose,

Thanks for the prompt reply...I pasted your code into an indicator:

Idx:=Security("C:\Trading Data\Stocks\ASX\Indices\XJO",C);
ASXTrend:=Idx>Mov(Idx,200,E);
ASXTrend

But it does not seem to give exactly the same results when I plot it on two different securities...I have attached two pictures - a stock (bottom of each picture) with the above indicator (middle of each picture) and the ASX200(top of each picture)...The two charts show the same timeframes but the indicator plots slightly different results.

I have noticed that this problem is worse the further back in time you look, and also the more non-trading days a stock has...Is there something else that could be causing this?

Thanks

Adrian

adrian77
22nd November 2007, 03:59 AM
Jose - I just spent some more time digging into this and think i found the problem (But not sure on the solution.

To investigate the problem I created an indicator which is the 200 day simple moving average of the index based on your suggested code:

Idx:=Security("C:\Trading Data\Stocks\ASX\Indices\XJO",C);
ASXMA:=Mov(Idx,200,S);
ASXMA

I then plotted this indicator on several different individual stock charts and noticed the you get different results for any given day...for example, on ASX stock code AAR for 21/11/07 the indicator gives 6251.83 but on the same date for code AAQ you get 6234.13.

The reason for the difference is that when you call a different security into these stock charts, it only calls in the values on the dates in which your securities actually trades. Indicator above therefore gives slightly different results for any stock which has been suspended for any period of time or doesn't trade for a day.

Am I missing something obvious to eliminate this error, because as it stands this is useless for back testing because I want to look at the value of the XJO index compared to the 200 day average of XJO for the last 200 days, not the last 200 bars of the stock.

Do you have any ideas on how to get around this problem?

Adrian

Jose
22nd November 2007, 10:17 PM
Adrian, I don't have a ready-made solution for this problem, but it seems to me that one solution would be to create a simple moving average based on calendar days (see basic calendar code found at MetaStockTools.com (http://www.metastocktools.com/#metastock)) - this way missing data on the securities would no longer be an issue.


jose '-)

adrian77
22nd November 2007, 11:28 PM
Thanks Jose - I will give that a go

Adrian