MA cross for the last x days

Hi there,
I tried following condition :

Buy = C > MA(C,50) AND Ref(C,-1) > MA(C,50) and ref(c,-2) > MA(C,50) e.t.c till ref(c,-20) > MA(C,50)

How can I code this further for example till the last 20 days. Does it mean I have to put 20 times ref(-.days) or it is possbile to short this code for an optimization run to test how man days make sense

Thanks for any help.


How about this idea

aboveMA = c> MA(C,50);
sumlast20 = sum(aboveMA, 20);
buy = sumlast20 == 20:

The equivalent to upper line is this one:

Buy = LLV(C,21) > MA(C,50);

Period is 21 because LLV() includes "current" bar.

No, that one is doing different thing than the one of first post.
It is doing this

cond = C > MA(C,50);
Buy = cond AND Ref(cond,-1) and ref(cond,-2) ... AND ref(cond,-20); 

So MA(C, 50) is part of Ref() too while in first post it is not.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.