Buy with multiple conditions

I am stuck at creating buy condition.
Condition 1 = close above 52 week high
Condition 2 = while sell condition is NOT TRUE and price cross EMA(20)
Buy = Condition 1 AND Condition 2
Sell = Cross(EMA(20),EMA(10)

Problem with Condition 1 is after making close above 52 weeks, next week it will go below and conditon become false.
What I was trying to do was
-looking for stock that close above 52 week high
-And wait for the price to come down to EMA(20) and buy.

Please guide me to the right direction.


crss_hh52 = Cross(C,Ref(HHV(H,52),-1));
crss_ema = Cross(C,EMA(C,20));// or near above EMA or ...

Buy = crss_ema AND BarsSince(crss_hh52) > 0;
Sell = Cross(EMA(C,20),EMA(C,10));

Using code tags is one step in the right direction.
Please follow this advice: How to ask a good question


Hi fxshrat,
Thanks so much for your reply. That was the answer I was looking for.

thank you

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