Breadth Risk On & Off

Hii

I am trying to code both breadth conditions for risk on and risk off as per below article but i think my code is not correct. Can you please help.

https://www.linkedin.com/pulse/identifying-risk-off-signals-market-breadth-david-pieper
Regards,
Deepak

v1 = GETDATA(CODE=STOCKS ABOVE 50 MA -NF 50 :Market Breadth); 
v2 = v1<65; 
v3 = CLOSE() < (HIGHESTHIGH(BARS=252) - (0.25/100) * HIGHESTHIGH(BARS=252)); 
v4 = v2 and v3; 
v5 = TIMESINCESIGNAL(v4) < 10; 
v6 = v1 CrossesBelow 50; 
v5 and v6

Hi,

Are you applying the script to the SPX directly? If not, V3 needs to use a GETDATA() for the SPX index as well. I’d also use the WithinRange() function to work out if the close is within the zone it needs to be. Here it is in isolation…

D1 = GETDATA(CODE=SPX:WI) ;
D2 = HIGHESTHIGH(D1, BACKTYPE=Bars, BARS=256);
WITHINRANGE(D1,D2, PERCENT=0.25)

If adjusting the script to use the above does not fix the issue you are seeing please provide more information on what the problem is.

Sir

I think my code for below condition is not correct. Yes i am directly applying to nifty rather than spx.

Condition 3: If Condition 1 & 2, start a days since true count#
Condition 4: If days since true count <= ten days and the percentage of S&P 500 members crosses below 50%, signal risk-off
Condition 5: If percentage of members crosses above 66%, reset condition = true

Regards,
Deepak

Hii Sir

Can you find error if possible.

Regards,
Deepak

Hi,

You’ll need to provide more information, I am not sure what isn’t working based on what you’ve posted so far, and the source you have is for SPX not NIFTY, meaning there would be custom bread codes being used as well? Include all the scripts you’re using to build any custom breadth codes, and a screen shot of where your final script is showing an incorrect result.

Hii Sir,

When i applied below formula to spx it didnot match with number of signals as said in the article. Please see attached pic. Let me pose my question differently how u would have coded it for spx.

v1 = GETDATA(CODE=S5FI:BM); 
v2 = v1<65; 
v3 = CLOSE() < (HIGHESTHIGH(BARS=252) - (0.25/100) * HIGHESTHIGH(BARS=252)); 
v4 = v2 and v3; 
v5 = TIMESINCESIGNAL(v4) < 10; 
v6 = v1 CrossesBelow 50; 
v5 and v6

Hi,

I would code the 5 conditions (for the first set of rules) this way:

//Get Breadth Data
V1 = GETDATA(CODE=MKTBRSG1:Market Breadth);
//Get Index Data
V2 = GETDATA(CODE=SPX:WI) ;
//Find Index Highest High over last 252 Bars
V3 = HIGHESTHIGH(V2, BARS=252) ;
//Condition 1
COND1 = V1 <= 65;
//Condition 2
COND2 = WITHINRANGE(V2,V3, PERCENT=0.25) ;
//Is Condition 1 and 2 True
V4 = COND1 and COND2 ;
//Condition 3
COND3 = TIMESINCESIGNAL(V4) ;
//Condition 4
COND4 = COND3 <= 10 and V1 CrossesBelow 50 ;
//Condition 5
COND5 = V1 CrossesAbove 66 ;
//Switch Between Cond 4 and Cond 5
SWITCH(COND4,COND5)

Thank you Matthew,

I was also very interested in this topic/script.

Best wishes,
Thomas