Buy / Short signals repainting

Hi All,

I have created one simple code where buying above first candle high and shorting below first candle low.

With this I want to add criteria which says that, for buy signal it should not break today's low and it should not break today's high for short signal before taking those trades. (It is fine if its breaks after trades are completed).

But it removes old buy or short signal if high/low is broken after trade completion.

FCL=ValueWhen(Day()!=Ref(Day(),-1),L); // Day first candle low
FCH=ValueWhen(Day()!=Ref(Day(),-1),H); // Day first candle high

Buy = Cross(H,FCH) AND L >= FCL; // Low should not be broken before buy
Sell = Cross(EMA(C,10),C );

Short = Cross(FCL,L) AND H <= FCH; // High should not be broken before sell
Cover = Cross(C, EMA(C,10));

Short signal screenshot before high was broken :

Please find the screenshots withShort signal screenshot before high was broken

Signals removed after high is broken :

Signals removed after high is broken

I have tried multiple options with valuewhen , timenum etc but not able to figure it out.

Could you please help to correct the same.

Thanks.
Mahesh

For that you can use LowestSince( EXPRESSION, ARRAY, Nth = 1 )


This for Buy and HighestSince() for short.

You can write your code based on this type of flow.

newDay = Day() != Ref( Day(), -1 );
lowAfterOpen = LowestSince( newDay, L );

FCL = ValueWhen( newDay, L );
FCH = ValueWhen( newDay, H ); 

Buy = Cross( H, FCH ) AND NOT ( lowAfterOpen < FCL);
// Low should not be broken before buy

Dear nsm51,

Thank you for your inputs and it looks good in first look.

I will update it as solution once my final testing is completed.

Regards,
Mahesh

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