Ratio Calculation in Watchlist

Hi,

I have in some way a simple script, but it causes some unexpected errors.

I would like to calculate the ratio of two items, e.g. the SPX and the DJI, on a certain date and display it in a watchlist.

Here is my script:

SPX20001 = GETDATA(CODE=SPX:WI) ;
SPX20002 = BARDATE()==STRDATE(DATE=2000-12-01) ;
SPX20003 = VALUEWHEN(SPX20002) ;

DJI20001 = GETDATA(CODE=DJI:WI) ;
DJI20002 = BARDATE()==STRDATE(DATE=2000-12-01) ;
DJI20003 = VALUEWHEN(DJI20002) ;

RATIO1 = SPX20003 / DJI20003 ;

WATCHLIST1 = ISTICKER(CODE=SPX:WI) ;
WATCHLIST2 = IF(WATCHLIST1 == 1 , RATIO1, 0) ;
WATCHLIST2

The problem is code line “RATIO1”. The calculation is not done.

Here is the watchlist with the above script:

I get as result the value"1" for the SPX that is of course wrong.

The “VALUEWHEN” query values are correct.
For the SPX: 1,315.23
For the DJI: 10,373.54
The correct value for the ratio would be “0.126786”.

Do you have any idea what I have done wrong?

Thanks,
Thomas

Hi Thomas,

I think you need to create the ratio first and then use the VALUEWHEN:

SPX1 = GETDATA(CODE=SPX:WI) ;
DJI1 = GETDATA(CODE=DJI:WI);
RATIO1 = SPX1 / DJI1;
DATE1 = BARDATE()==STRDATE(DATE=2000-12-01);
RATIO2 = VALUEWHEN(RATIO1, DATE1);
WATCHLIST1=IF(ISTICKER(CODE=SPX:WI), RATIO2, 0);
WATCHLIST1

Thank you very much Darren, Small change, but big effect.