Previous macd cross

I am trying to create code to Explore for a previous cross of SIGNAL over MACD on daily charts. I got this far which does find the cross for current data:


BuyPrice = 0;
SellPrice = 0;
ShortPrice = Open;
CoverPrice = Open;

Short =
Cross (Signal(),MACD());  

Filter = short;  

The plan is to look for that cross on previous days, but I cannot figure out where to place the -1 or -2 to indicate previous bars. I've tried every likely spot, but nothing works.

Thanks.

BuyPrice = 0;
SellPrice = 0;
ShortPrice = Open;
CoverPrice = Open;

Short = Cross (Signal(),MACD());  

NumberOfPreviosBar = 2;
Filter = BarsSince(short) == NumberOfPreviosBar;  

Thank you awilson. That solved it.

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