# Number of days above 20dma

Another tricky one for me. How do I find the number of days price has been above the 20dma since the last cross?

```ma20 = MA(BARS=20, CALC=Close);
cond = CLOSE() CrossesAbove ma20;
knt = MagicFormulaUsing(cond);
knt
```

knt should be ‘x’ days from the cross until the current day. The attached image should show knt=15 (or 14 ignoring the crossing day).

Thanks. Andy

Hi Andy,

The function you’re looking for is TIMESINCESIGNAL. Here it is in your code:

```// Andy #55261 Close Above 20MA, Days
ma20 = MA(BARS=20, CALC=Close);
cond = CLOSE() CrossesAbove ma20;
//knt = MagicFormulaUsing(cond);
knt = TIMESINCESIGNAL(cond,UNIT=Days, FIRSTSIGNALONLY=False);
knt```

You can show the result in a SHOWVIEW or, if you only want the number of days since the last cross you can use CHART ELEMENT, both shown in the following screenshot:

Cheers

Trevor

Thanks Trevor! Works great.

Here are some more TIMESINCESIGNAL examples:

https://forum.optuma.com/topic/timesincesignal-formulas/