Duplicate buy signal

Hello All,

I face a problem that I am not able to fix and explain. Would like to ask a question here and see if anything I am missing, thanks.

Capture1

Here is my system, and I try to visualize the signal. As you can see, there are two Buy signals generated. I have already applied the exrem, if not, it would look like this:

Capture2

Also, I try to run the scan and backtest, and duplicate signal is on scan but not on the backtest.
Capture3
Capture4

Then I tried to trace the variable in my code and found the reason:

MA1 = MA(O, period);
MA2 = MA(O, period2);

POver = Cross(MA1, MA2);
PUnder = Cross(MA2, MA1) 
 
AverageP = (H + L + C + C )/4 ; 
  
AH = round(AverageP + (H - L)); 
AL = round(AverageP - (H - L));		 
 
Upper = ValueWhen(POver, ref(AH,-1)); 
Lower = ValueWhen(PUnder, ref(AL,-1)); 
 
UpperBarsSince = BarsSince(POver); 
LowerBarsSince = BarsSince(PUnder); 

UpperBarsSince = UpperBarsSince +1;
LowerBarsSince = LowerBarsSince + 1;

Buy1 = H >= Upper;
Buy1 = Buy1 AND Sum(Buy1, UpperBarsSince) <= 1 AND UpperBarsSince < LowerBarsSince;
 
Short1 = L <= Lower;
Short1 = Short1 AND Sum(Short1, LowerBarsSince) <= 1 AND LowerBarsSince < UpperBarsSince;

Buy = Buy1;
BuyPrice = Max(O, Upper);
Short = Short1;
ShortPrice = Min(O, Lower);

cover1 = Buy;
Cover = cover1;//
sell1 = Short;
Sell = sell1;

CoverPrice = IIf(cover1, BuyPrice,  O);
SellPrice = IIf(sell1, ShortPrice,  O);

Buy=ExRem(Buy,Sell);			
Sell=ExRem(Sell,Buy); 
Short=ExRem(Short,Cover); 
Cover=ExRem(Cover,Short);		

My 2nd Buy signal is generated becoz one of my conditions, POver = Cross(MA1, MA2), is true again after the first Buy signal. As the Buy1 turns true again(repeated signal), so Buy is true again too. But my question is, EXREM should have removed these repetitive signals? it does autally but why this one is missing?

Thanks a lot.

I just read the info. and understand that the scan is to show raw and unprocessed signals while backtest is removing redundant signals.

No matter I use the exrem or not, I will get the right signal by using backtest.

Then my question is still there, as I want to use it in auto-trade, I want to generate the signal exactly the same as the backtest. And I still don't understand why only this one is repetitive shown but not the others.......see if anyone here can give me a hand.

hi all,

i got the root cause, and i think it is worth to share here. Though the chance is very slim but in that very particular case, both Buy and Sell are equal to 1 and it seems in such case, EXREM will count both Buy and Sell, so its state is reset.

Capture

As seen, even though "Buyexrem = Exrem(Buy, Sell)" generates the true signal but in this case, the Exrem is "reset" and so it allows the next Buy signal.

I solve it by adding a line right under the Sell condition:

Sell = Sell AND NOT Buy;

Thanks.

1 Like

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