DALE!! MODIFIED AVERAGE TRUE RANGE TRAILING STOP (DATE SPECIFIC VERSION) ! Author: Sylvain Vervoort, TASC, June 2009 ! Coded by: Richard Denning 4/12/09 ! INPUTS: mo is 10. da is 2. yr is 2008. isLong is 1. ! 1 = for longs, 0 = for shorts atrLen is 5. atrMult is 3.5. ! ABBREVIATIONS: C is [close]. C1 is valresult(C,1). H is [high]. H1 is valresult(H,1). L is [low]. L1 is lowresult(L,1). ! MODIFIED AVERAGE TRUE RANGE AvgRng is simpleAvg(H - L, atrLen) . HiLo is iff(H - L < 1.5 * AvgRng, H - L, 1.5*AvgRng). HLmax is (H - C1) - (L - H1) / 2. Href is iff(L <= H1,H - C1,HLmax). LHmax is (C1 - L) - (L1 - H) / 2. Lref is iff(H >= L1, C1 - L, LHmax). Diff1 is Max(HiLo,Href). Diff2 is Max(Diff1,Lref). ATRM is expAvg(Diff2,atrLen*2-1,0). ! ATR TRAILING STOP FROM DATE startDate is makeDate(mo,da,yr). daysSinceStart is scanany(ruledate() = startDate, 5040) then offSetToDate(month(),day(),year()). loss is ATRM * atrMult. longStop is C-Loss. shortStop is C+Loss. maxVal is iff(reportdate() >= startDate,^highresult(longStop,^daysSinceStart+1),C). minVal is iff(reportdate() >= startDate,^lowresult(shortStop,^daysSinceStart+1),C). ! PLOT "TRAIL" AS CUSTOM INDICATOR TO SEE STOP ON CHART: trail is iff(reportdate() >= startDate and isLong = 1,maxVal, iff(reportdate() >= startDate and isLong <> 1,minVal,C)). Buy if reportdate() = startDate and isLong = 1. Exit if C < trail. SellShort if reportdate() = startDate and isLong <> 1. Cover if C > trail.  Rule Libraryÿÿ CCodeViewØÿÿÿÿ00:00