logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
DWMcGrack  
#1 Posted : Wednesday, September 14, 2022 4:03:55 AM(UTC)
DWMcGrack

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/30/2022(UTC)
Posts: 5

Was thanked: 1 time(s) in 1 post(s)

Hi Guys

I am running some system tests which include a realtive strength calc against two indices.

The difficulty I have is that many stocks predate one of the indices I am using and so no signals are generated at all for the period this indice did not exist. My manual review of stocks suggest there should be. The formula I am using is as follows;

IGClose:=Security("C:\Trading Data\Stocks\ASX\Indices\XENK",C); {this is an Industry Group Index} XAOClose:=Security("C:\Trading Data\Stocks\ASX\Indices\XAO",C);. {this is the main index}...............

RCSXAO:=C/XAOClose; {this is my RCS calc on the main index} RCSIG:=C/IGClose; {this is my RCS calc on the Industry Group Index}......................

AND RCSXAO>Ref(HHV(RCSXAO,13),-1) AND  RCSIG>Ref(HHV(RCSIG,13),-1)

For the period that both indices have data, this works. However, for the period where there is no data for one index, no signals are generated.

I have tried using an if statement for RCSIG:= suggesting if C/IGClose = 0 to plot RCSXAO instead, (assuming that the C/IGClose will register as false given there is not data for the IGClose). Formula as follows:

RCSIG:= If(C/IGClose=0,C/XAOClose,C/IGClose);

I have also tried to plot in a date from which to calculate the RCSIG with the aim being that it only calculates the RCSIG after it has three months data for the IGClose. For any period prior it uses the XAOClose to calculate the RCS. Formula as folows:

RCSIG:= If((Month()>6 and Year()=2000) or Year()>2000, (C/IGClose),(C/XAOClose));

Unfortunately none of these work.

Clearly I am missing something and would appareciate any suggestions at why this may not be working.

Many Thanks

MS Support  
#2 Posted : Wednesday, September 14, 2022 3:04:17 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,957

Thanks: 91 times
Was thanked: 155 time(s) in 150 post(s)
Originally Posted by: DWMcGrack Go to Quoted Post

Hi Guys

I am running some system tests which include a realtive strength calc against two indices.

The difficulty I have is that many stocks predate one of the indices I am using and so no signals are generated at all for the period this indice did not exist. My manual review of stocks suggest there should be. The formula I am using is as follows;

IGClose:=Security("C:\Trading Data\Stocks\ASX\Indices\XENK",C); {this is an Industry Group Index} XAOClose:=Security("C:\Trading Data\Stocks\ASX\Indices\XAO",C);. {this is the main index}...............

RCSXAO:=C/XAOClose; {this is my RCS calc on the main index} RCSIG:=C/IGClose; {this is my RCS calc on the Industry Group Index}......................

AND RCSXAO>Ref(HHV(RCSXAO,13),-1) AND  RCSIG>Ref(HHV(RCSIG,13),-1)

For the period that both indices have data, this works. However, for the period where there is no data for one index, no signals are generated.

I have tried using an if statement for RCSIG:= suggesting if C/IGClose = 0 to plot RCSXAO instead, (assuming that the C/IGClose will register as false given there is not data for the IGClose). Formula as follows:

RCSIG:= If(C/IGClose=0,C/XAOClose,C/IGClose);

I have also tried to plot in a date from which to calculate the RCSIG with the aim being that it only calculates the RCSIG after it has three months data for the IGClose. For any period prior it uses the XAOClose to calculate the RCS. Formula as folows:

RCSIG:= If((Month()>6 and Year()=2000) or Year()>2000, (C/IGClose),(C/XAOClose));

Unfortunately none of these work.

Clearly I am missing something and would appareciate any suggestions at why this may not be working.

Many Thanks

Hello,

Unfortunately, the Relative Strength Comparative calculation you are performing will not return a 0 in the case of no data. It will simply be considered "NA" or "Undefined" for the period where both data items do not have data.

There are functions that can capture this information, such as the "IsDefined" or "IsUndefined" functions.

As a simple example:

Code:
IsUndefined(C / Security("Online:SPY",C))

In this example, if I were to open a chart of AAPL.O with maximum data I would have data going back to 1981. SPY only goes back to 1993. So every point prior to the 1993 start date on SPY data returns a "1" value. IsDefined would work similarly, except it would report a 0 prior to 1993 and a 1 on every bar afterward.

You can probably combine this with your IF condition, so that if the data calculation is undefined in a particular segment, you could switch to another calculation instead.

Code:
If(IsDefined(C/IGClose)=0,C/XAOClose,C/IGClose);

DWMcGrack  
#3 Posted : Thursday, September 15, 2022 1:46:41 AM(UTC)
DWMcGrack

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/30/2022(UTC)
Posts: 5

Was thanked: 1 time(s) in 1 post(s)
Thanks for this. I have tried the following: RCSIG:= If(IsDefined(C/IGClose),(C/IGClose),(C/XAOClose)); RCSIG:= If(IsDefined(C/IGClose)=1,(C/IGClose),(C/XAOClose)); RCSIG:= If(IsDefined(C/IGClose)=0,(C/XAOClose),(C/IGClose)); RCSIG:= IF(IsUndefined(C/IGClose),(C/XAOClose),(C/IGClose)); RCSIG:= IF(IsUndefined(C/IGClose)=1,(C/XAOClose),(C/IGClose)); RCSIG:= IF(IsUndefined(C/IGClose)=0,(C/IGClose),(C/XAOClose)); Unfortunately, they do not return any results for the period where the IG has no data. I was wondering whether the problem could be in the following: RCSIG>Ref(HHV(RCSIG,13),-1) For the first period that C/IGClose gives a result, it then looks back 13 periods for C/IGClose, but as there is no data it gives an NA result again?
wabbit  
#4 Posted : Thursday, September 15, 2022 5:47:24 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)

I'll try to post something to clarify the issue:

Code:

ma:= mov(c,100,s);
{plot}
ma;

We know the value of "ma" is undefined in the first 100 bars, so you'd think that by trying to call the IsUndefined() function would return a value of '1' for those first 100 bars and then '0' after... and you'd be correct!

Code:

ma:= mov(c,100,s);
{plot}
IsUndefined(ma);

So, why does If() get borked? It has to do with the way MS deals with what it considers "FirstValid" and "LastValid" The "FirstValid" bar of "ma" is the 100th bar and the "LastValid" bar is the last bar on the chart; the "FirstValid" bar of the IsUndefined() function is bar 1 and the "LastValid" bar is the last bar on the chart. When combined in any fashion, MS screws things up by looking the for the LAST "FirstValid" and the FIRST "LastValid" bars and only returning values for bars in that range! See for yourself:

Code:

ma:= mov(c,100,s);
{plot}
If(IsUndefined(ma),0,ma);

To go one step further, forward reference the ma and see:

Code:

ma:= Mov(C,100,S);
ma2:=Ref(ma,+100);
{plot}
If(IsUndefined(ma),LastValue(0),ma + ma2);

You need to go outside MS to fix this annoyance.

wabbit :D

P.S. Check your PM

Edited by user Thursday, September 15, 2022 6:05:41 AM(UTC)  | Reason: fixed code tags

thanks 1 user thanked wabbit for this useful post.
MS Support on 9/15/2022(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.