I'm not sure how exactly parallel you are interested in scanning for. Adding a 'fudge factor' is a bit more involved, but for exactly matching slopes, it can be done this way:
Code:
input L1 = 9;
input L2 = 21;
input L3 = 50;
input lookback = 1;
def SMA1 = SimpleMovingAvg(price = CLOSE, length = L1);
def SMA2 = SimpleMovingAvg(price = CLOSE, length = L2);
def SMA3 = SimpleMovingAvg(price = CLOSE, length = L3);
def delta1 = SMA1 - SMA1[lookback];
def delta2 = SMA2 - SMA2[lookback];
def delta3 = SMA3 - SMA3[lookback];
plot eureka = if delta1 == delta2 and delta1 == delta3 then 1 else double.nan;
This code lets you specify the lengths for the three averages in bars, as well as the lookback -- the two bars to look at for difference calculation. It defaults to 1 bar (looking at the two most recent bars). If the differences between the SMA for this bar and the last bar are equal for all three moving averages, the lines are parallel.
perhaps that's what you meant, perhaps not.
to do something with a fudge factor, you would need to do something like this:
Code:
input fudge_factor = 0.02; # this is in cents -- adjust as needed for your instrument e.g. 0.00002 for /6E etc...
plot eureka = if (delta1 <= (delta2 + fudge_factor)) or (delta1 >= (delta2 - fudge_factor)) and (delta1 <= (delta3 + fudge_factor)) or (delta1 >= (delta3 - fudge_factor)) then 1 else double.nan;
... I think. I'm just writing code in the text editor, not ThinkOrSwim.
-mashume