If I understand you correctly, you want to count the number of bars that are spent above and below the crossovers. A possible way is to use the Flip and BarsSince functions.
A possible code would look something like this.
ma9 = MA( C, 9 );
ma50 = MA( C, 50 );
Cross9Above50 = Cross( ma9, ma50 );
Cross9Below50 = Cross( ma50, ma9 );
Condition1 = Flip( Cross9Below50, Cross9Above50 );
Condition2 = Flip( Cross9Above50, Cross9Below50 );
Count1 = BarsSince( Condition1 ); // if you don't want to count the crossing bar, then "-1"
Count2 = BarsSince( Condition2 );
Filter = 1;
// I like to make my Explorations "easy on the eyes"
dynamic_color = IIf(Cross9Above50 OR Cross9Below50, colorYellow, colorDefault );
dynamic_color2 = IIf(Count1 >0, colorlime, colorDefault );
dynamic_color3 = IIf(Count2 >0, colorRose, colorDefault );
Filter = 1;
AddColumn( Close, "Close" );
AddColumn( ma9, "ma9", 1.2, colorDefault, dynamic_color );
AddColumn( ma50, "ma50", 1.2, colorDefault, dynamic_color );
AddColumn( Count1, "Count1", 1.0, colorDefault, dynamic_color2 );
AddColumn( Count2, "Count2", 1.0,colorDefault, dynamic_color3 );
// Charting //
Plot( Count1, "Count1", colorGreen, styleThick );
Plot( Count2, "Count2", colorRed, styleThick );
Producing an Exploration and chart as below example.