/// <summary>True if a break-out to the 'high' side is detected</summary> private bool IsBreakOutInternal(Monic trend, List <Peak> peaks, bool high) { // A break-out is when the latest candle is significantly above the upper trend line // or below the lower trend line and showing signs of going further. Also, the preceding candles // must be below the trend line. // No trend, no break-out if (trend == null) { return(false); } // The latest candle must be in the break-out direction var sign = high ? +1 : -1; var latest = Instrument.Latest; if (latest.Sign != sign) { return(false); } // The price must be beyond the trend by a significant amount var price_threshold = trend.F(0.0) + sign * Instrument.MCS; if (Math.Sign(latest.Close - price_threshold) != sign) { return(false); } // Only the latest few candles can be beyond the trend line // and all must be in the direction of the break out. if (peaks[0].Index < -2) { // Allow the last two candles to be part of the break out foreach (var c in Instrument.CandleRange(peaks[0].Index, -2)) { // If more than half the candle is beyond the trend line, not a breakout var ratio = sign * Instrument.Compare(c, trend, false); if (ratio > 0) { return(false); } } } return(true); }