示例#1
0
        public NarrowChannel CheckNewSlope(int bar)
        {
            NarrowChannel channel = new NarrowChannel(this);

            channel.addBar(bar);
            channel.Calculate();
            return(channel);
        }
        public virtual void ContinueOrEnd()
        {
            NarrowChannel channel   = Tapes[0];
            int           top       = channel.High;
            int           bottom    = channel.Low;
            double        close     = Bars.Close[0];
            bool          isSuccess = false;

            if (Tapes[0].IsDown)
            {
                if (close > top)
                {
                    isSuccess = TryNewTape(Tapes[0].LastLowBar, Trend.Up);
                }
                else if (close < bottom)
                {
                    isSuccess = TryNewTape(Tapes[0].LastHighBar, Trend.Down);
                }
            }
            else if (Tapes[0].IsUp)
            {
                if (close < bottom)
                {
                    isSuccess = TryNewTape(Tapes[0].LastHighBar, Trend.Down);
                }
                else if (close > top)
                {
                    isSuccess = TryNewTape(Tapes[0].LastLowBar, Trend.Up);
                }
            }
            else
            {
                if (close < bottom)
                {
                    isSuccess = TryNewTape(Tapes[0].LastHighBar, Trend.Down);
                }
                else if (close > top)
                {
                    isSuccess = TryNewTape(Tapes[0].LastLowBar, Trend.Up);
                }
            }
            if (!isSuccess)
            {
                channel.TryExtend();
                return;
            }
        }
        public override bool OnIntervalClose()
        {
            if (tapes.Count == 0)
            {
                TryNewTape(Bars.CurrentBar, Trend.Flat);
                return(true);
            }

            ContinueOrEnd();

            if (tapes.Count > 1)
            {
                NarrowChannel line   = tapes[1];
                int           lastBO = line.BreakoutBar;
                if (line.IsUp && line.Direction != tapes[0].Direction)
                {
                    int    lastHighBar = line.LastHighBar;
                    double lastHigh    = Bars.High[Bars.CurrentBar - lastHighBar];
                    if (lows.Count == 0 || lastHighBar - lows[0].X > 1)
                    {
                        if (highs.Count == 0 || lastHighBar != highs[0].X)
                        {
                            NewHigh(lastHighBar, lastHigh);
                        }
                    }
                }
                else if (line.IsDown && line.Direction != tapes[0].Direction)
                {
                    int    lastLowBar = line.LastLowBar;
                    double lastLow    = Bars.Low[Bars.CurrentBar - lastLowBar];

                    if (highs.Count == 0 || lastLowBar - highs[0].X > 1)
                    {
                        if (lows.Count == 0 || lastLowBar != lows[0].X)
                        {
                            NewLow(lastLowBar, lastLow);
                        }
                    }
                }
            }
            return(true);
        }
        protected bool TryNewTape(int lastLineBar, Trend trend)
        {
            NarrowChannel channel = new NarrowChannel(Bars);

            channel.BreakoutBar     = Bars.CurrentBar;
            channel.LongColor       = LongColor;
            channel.ShortColor      = ShortColor;
            channel.Chart           = Chart;
            channel.DrawLines       = drawLines;
            channel.ReDrawLines     = RedrawLines;
            channel.DrawSolidLines  = drawSolidLines;
            channel.DrawDashedLines = drawDashedLines;
            channel.Extend          = extend;
            if (channel.TryInitialize(lastLineBar, trend))
            {
                tapes.Add(channel);
//				hasNewChannel = true;
//				if( tapes.Count < 2 || channel.Direction != tapes[1].Direction) {
//					strategy.FireEvent(new NewChannel().SetDirection(channel.Direction).ExpirySeconds(30));
//				}
                return(true);
            }
            return(false);
        }
示例#5
0
 public NarrowChannel(NarrowChannel other)
 {
     this.bars = other.bars;
     lrHigh    = new LinearRegression(other.lrHigh.Coord);
     lrLow     = new LinearRegression(other.lrLow.Coord);
 }
示例#6
0
        public void TryExtend()
        {
            bool recalculate = true;

            if (CountPoints > 100)
            {
                return;
            }
            NarrowChannel channel = CheckNewSlope(bars.CurrentBar);

            switch (Direction)
            {
            default:
            case Trend.Flat:
                if (channel.Direction != Trend.Flat)
                {
                    recalculate = false;
                }
                break;

            case Trend.Up:
                if (channel.Direction != Trend.Up)
                {
                    recalculate = false;
                }
                break;

            case Trend.Down:
                if (channel.Direction != Trend.Down)
                {
                    recalculate = false;
                }
                break;
            }
            if (CountPoints > 3)
            {
                recalculate = false;
            }
            addBar(bars.CurrentBar);
            try {
                if (recalculate)
                {
                    Calculate();
                }
                UpdateEnds();                  // Was before calcMaxDev
                calcHighest();
                if (recalculate)
                {
                    calcMaxDev();
                }
                if (drawLines)
                {
                    if (reDrawLines)
                    {
                        RedrawChannel();
                    }
                    else
                    {
                        DrawChannel();
                    }
                }
            } catch (ApplicationException ex) {
                log.Notice(ex.ToString());
                return;
            }
            return;
        }