Buy signal to be omitted if not satisfy condition

I am trying to generate buy signal based on breaking defined range high and if close above VWAP. And that has been done code pasted below.

Now want to add more condition , if any candle close below range low then buy signal should not generated. I am trying to make that but unable to do so.

de = Day();
de1 = Ref(de, -1);
FC = de != de1;
BSFC = BarsSince(FC)+1;

HH3 = HHV(H, 3);
LL3 = LLV(L, 3);
FC2 = Ref(FC, -2);
 
RangeHigh = ValueWhen(FC2, HH3);
RangeLow = ValueWhen(FC2, LL3);
 
_Buy =  Close >  RangeHigh AND Close > VWAP  ; 
_Short = Close < RangeLow AND Close < VWAP ;

 
Buy = _Buy  ;
Short = _Short  ; 

Capture

Kindly help.

"Any candle" is too vague, because I doubt you mean "any candle in the entire price history". Do you mean "any candle from the current day" or "any candle since Event X occurred" or something else?

Also, you said you've tried but can't make it work. Please let us know what you've tried.

Thanks for your reply.

I must be specific in my post. Sorry for that.

Any candle from the current day before Buy signal generated.

I have tried this , but didn't work.

_Buy =  Close >  RangeHigh AND Close > VWAP AND Close < RangeLow ==False ; 

You were almost there. Instead of this in your Buy assignment:

Close < RangeLow ==False

Try something like this:

SumSince(FC, Close < RangeLow) == 0

That logic says that we should find all the times that Close was less than RangeLow, and sum (i.e. count) the number of times that condition has occurred since the start of the day (your FC variable).

2 Likes

Thanks mradtke for your reply. Actually I am using Amibroker version 6.0. SumSince option not available in this version.

Is there any other way instead of SumSince.

Look at the online documentation for SumSince(): https://www.amibroker.com/guide/afl/sumsince.html

There are alternative implementations shown there.

2 Likes

Thanks mradtke.

Resolved.

using " x = Sum( array, BarsSince( condition ) ); "

2 Likes