# A New Trend Indicator: MSR

While my own research focus has generally shifted towards the technology of combining multi-indicator/multi-variable models, ultimately I depend on various single indicator inputs for this approach. Therefore, having indicators that capture something that is slightly different or can reduce the complexity of a model by condensing a concept into one number is still highly desirable. A good post by Quantum Financier highlights the importance of these issues: http://quantumfinancier.wordpress.com/2010/10/22/considerations-in-systemindicator-design/ .

In this case, I was looking for a support and resistance indicator that captured the typical or middle price over a short to intermediate time frame. I also wanted something that could be normalized so that I could avoid having the inflexibility of binary rules, or specific levels for entry and exits. This was something very simple that I came up with that performed well on the S&P500 (SPY), achieving nearly a 10% cagr which is impressive for a short-term indicator.

**MSR**= (10-day median of (H, L, C) – 20-day MAX (H, L, C))/(20-day MAX (H, L, C))

then take the 252-day percentrank of MSR or percentile ranking

long trades initiated>.5

short trades are initiated<.5

Some clarification needed on the formula….

Median H,L,C – take the median of each and divide by 3?

MAX H,L,C – take the highest value of H, L and C; or the highest value of H, the Lowest value of L, and the ? of C? ; and divide by 3?

And for the numerator – use absolute value or allow negatives?

Thanks,

Carl

Hi Carl,

My understanding is that Median(H,L,C) is the median taken from the 3 arrays combined, i.e. as if the three arrays were concatenated.

I am working on a Amibroker translation, which I will post as soon as I am done.

-QD-

Carl, it’s going to take some more time. I have build a first version, but it is very slow because of looping in looping. I am now looking to program a .dll to calculate the median of multiple arrays() in AB.

-QD-

hi there, that is correct, the H,L,and C are all considered as one sample for purposes of deriving the median. Carl the number is always negative and thus needs to be normalized. thank you very much Quanting for sharing–I will link over the weekend.

best

dv

hi QD,

you do not need loops in loops as you are not sorting, simply calculating percentrank.

i remember Ramon Cummins had posted a percentrankHLC sometime, and I believe this is the code he posted ( i am taking the liberty of posting it again, but his is the credit ). As with anything else, test before using !

See if this meets your needs.

function PercentRankHLC( Data1,Data2,Data3,Periods )

{

Count = 0;

for ( i = 0; i Ref( Data1, -i ), 1, 0 );

Count = Count + IIf ( Ref( Data3, 0 ) > Ref( Data2, -i ), 1, 0);

Count = Count + IIf ( Ref( Data3, 0 ) > Ref( Data3, -i ), 1, 0

);

}

return 100 * Count / (Periods*3-1);

}

Hi BGPL, this code calculates the percentrank of data3 in the combined data1, data2 and data3 arrays. The problem is that it does not calculate the Median of the 3 arrays combined. That is, testing if data3==50 won’t give the true median (as it does not test data1, data2 elements’. I hope this comes across.

I am currently considering to built a dll for this problem.

QD

Hi, it took a while to complete the Amibroker translation as I did end up writing a .dll for the Median function across 2 or 3 arrays.

The translation is available at my Blog.

QD

this got messed up in the formatting…

What was the time period that was backtested? I chose to go from July 09′ to 11/12/10 (used a couple week old yahoo finance download), and showed a net loss going long and short @ .5. However, when only going long @ > .5, the indicator performed very well (up 18.5% in 2010).

Apologies, I was actually not using the SPY. Sorry about that.