{ TrendLine Triangle Long/Short Entry Strategy Written by: HamFon Contact: ncrowle@sprintmail.com Web site: www.hamfon.com/daytrade Date: 07/31/2002, first version 07/31/2002 Version: 1.00 Status: Gnu Public License - this indicator may be used or shared freely with no fee, as long as this original header comment is included. Purpose: Generates a Buy or Sell Short order based on ascending or descending triangle formed by trendlines. } inputs: Size (5), { Specifies how many bars on each side to validate a High or Low } EMALength (27), TimeStart (0), TimeEnd (0), { hhmm integer or 0 to ignore } AllowMultipleEntries (false), { blocks new trades if one already active } DoLong (true), DoShort (true) ; variables: loop (0), FoundHigh (false), FoundLow (false); array: DateIndex[1, 1] (0); { index offsets for [Low,High]; [StartDate, EndDate] } array: DataValue[1, 1] (0); { [Low,High]; [StartPrice, EndPrice] } if BarType <= 1 { minute or tick bars only } and CurrentBar > Size then begin FoundHigh = true; FoundLow = true; for loop = 1 to Size begin if L[Size] > L[Size + loop] or L[Size] > L[Size - loop] then FoundLow = false; if H[Size] < H[Size + loop] or H[Size] < H[Size - loop] then FoundHigh = false; end; if FoundHigh and CurrentBar - Size * 2 > DateIndex[1, 1] then begin DateIndex[1, 0] = DateIndex[1, 1]; DataValue[1, 0] = DataValue[1, 1]; DateIndex[1, 1] = CurrentBar - Size; DataValue[1, 1] = H[Size]; end; if FoundLow and CurrentBar - Size * 2 > DateIndex[0, 1] then begin DateIndex[0, 0] = DateIndex[0, 1]; DataValue[0, 0] = DataValue[0, 1]; DateIndex[0, 1] = CurrentBar - Size; DataValue[0, 1] = L[Size]; end; end; if DateIndex[0, 0] > 0 and DateIndex[1, 0] > 0 { make sure we have two trendlines } and (AllowMultipleEntries or MarketPosition = 0) and (TimeStart = 0 or Time >= TimeStart) and (TimeEnd = 0 or time <= TimeEnd) then begin if DoLong and DataValue[1, 1] > DataValue[1, 0] { higher highs } and DataValue[0, 1] > DataValue[0, 0] { higher lows } and DataValue[1, 1] - DataValue[1, 0] < DataValue[0, 1] - DataValue[0, 0] { ascending } and C - DataValue[1, 1] > DataValue[1, 1] - DataValue[1, 0] and C > DataValue[1, 1] and L > XAverage (C, EMALength) { order for long, chronologically: left high, left low, right high, right low } and DateIndex[1, 0] < DateIndex[0, 0] and DateIndex[0, 0] < DateIndex[1, 1] and DateIndex[1, 1] < DateIndex[0, 1] then begin Buy ("TriangleLE") next bar at C or higher; Alert ("Ham Triangle LE"); end; if DoShort and DataValue[1, 1] < DataValue[1, 0] { lower highs } and DataValue[0, 1] < DataValue[0, 0] { lower lows } and DataValue[1, 0] - DataValue[1, 1] > DataValue[0, 0] - DataValue[0, 1] { descending } and DataValue[0, 1] - C > DataValue[0, 0] - DataValue[0, 1] and L < XAverage (C, EMALength) { order for short, chronologically: left low, left high, right low, right high } and DateIndex[0, 0] < DateIndex[1, 0] and DateIndex[1, 0] < DateIndex[0, 1] and DateIndex[0, 1] < DateIndex[1, 1] then begin Sell Short ("TriangleSE") next bar at C or lower; Alert ("Ham Triangle SE"); end; end;