{ Function NTStop Noise tolerant money management stop. This function detrends the price over the last N bars. The maximum deviation of price from the trend line is used to determine the size of the money management stop, which is returned. Copyright 2006 Breakout Futures www.BreakoutFutures.com } input: N (NumericSimple); { Lookback length } Var: HDet (0), { detrended high } LDet (0), { detrended low } Devi (0), { deviation from trend line } MaxDev (0), { maximum deviation } ii (0); { loop counter } { Calculate deviation of price from trend } MaxDev = 0; for ii = 0 to N Begin HDet = H[ii] - ((C[N] - C)/N * ii + C); LDet = L[ii] - ((C[N] - C)/N * ii + C); Devi = MaxList(AbsValue(HDet), AbsValue(LDet)); if Devi > MaxDev then MaxDev = Devi; End; { Use average of MaxDev over past N bars as stop size } NTStop = Average(MaxDev, N);