Ejemplo n.º 1
0
        public void CompareAgainstExternalDataForUpperBand()
        {
            var donchianChannel = new DonchianChannel("dch", 50);

            TestHelper.TestIndicator(donchianChannel, "spy_with_don50.txt", "Donchian Channels 50 Top",
                                     (ind, expected) => Assert.AreEqual(expected, (double)((DonchianChannel)ind).UpperBand.Current.Value));
        }
Ejemplo n.º 2
0
        public void ComputesPrimaryOutputCorrectly()
        {
            var donchianChannel = new DonchianChannel("dch", 50);

            TestHelper.TestIndicator(donchianChannel, "spy_with_don50.txt", "Donchian Channels 50 Mean",
                                     (ind, expected) => Assert.AreEqual(expected, (double)((DonchianChannel)ind).Current.Value));
        }
Ejemplo n.º 3
0
        public void CompareAgainstExternalDataForLowerBand()
        {
            var donchianChannel = new DonchianChannel("dch", 50);

            TestHelper.TestIndicator(donchianChannel, "spy_with_don50.txt", "Donchian Channels 50 Bottom",
                                     (ind, expected) => ((double)((DonchianChannel)ind).LowerBand.Current.Price).Should().Be(expected));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        ///
        /// I was thinking that MOMO could have not atr ratched but use a stop place where the
        /// prior atr stop was, for example, if a short momo, use the lower blue level as the
        /// max high to trigger a sell.
        /// </summary>
        protected override void Initialize()
        {
            atrTimes  = dparm1;
            atrPeriod = period1;
            //ratched = 0;

            atr = ATRTrailing(atrTimes, Period1, Ratched);
            Add(atr);

            kc = KeltnerChannel(offsetMultiplier, keltnerPeriod);
            Add(kc);

            dc = DonchianChannel(donchianPeriod);
            dc.Displacement      = 2;
            dc.PaintPriceMarkers = false;
            Add(dc);

            SetProfitTarget("", CalculationMode.Percent, dparm2);
            SetStopLoss("", CalculationMode.Percent, dparm2, false);
            //SetTrailStop("", CalculationMode.Percent, dparm2, false);

            CalculateOnBarClose = true;
            ExitOnClose         = false;
            IncludeCommission   = true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            //this.HallMaColored
            SetProfitTarget(CalculationMode.Ticks, iparm1);
            SetStopLoss(CalculationMode.Ticks, iparm1);
            //SetTrailStop("", CalculationMode.Percent, dparm2, false);

            smaLow  = HMA(Low, period1);
            smaHigh = HMA(High, period1);
            //Add(smaLow);
            //Add(smaHigh);
            smaHigh.Displacement = 0;
            smaLow.Displacement  = 0;

            hallMa = HallMaColored(Typical, period1);
            //hallMaFast = HallMaColored(Low, period2);
            Add(hallMa);
            //Add(hallMaFast);
            dc = DonchianChannel(period2);
            Add(dc);

            CalculateOnBarClose = true;
            ExitOnClose         = true;
            IncludeCommission   = false;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            ast = anaSuperTrend(1, 3, 3);
            dc  = DonchianChannel(20);
            hma = HMA(30);

            // Open Secret Sauce Long
            if (isFlat() &&
                enableLong
                //&& Close[0] <= ast.StopLine[0]
                && ast.UpTrend[0] && !ast.UpTrend[1]
                //&& ((dc.Upper[0] - dc.Lower[0])/TickSize >= 12)
                && Rising(hma)
                //&& (BarsSinceExit() > 5 || BarsSinceExit() == -1)
                )
            {
                EnterLong(DefaultQuantity);
                //EnterLongLimit(DefaultQuantity, ast.StopLine[0]);
            }

            // Open Secret Sauce Short
            if (isFlat() &&
                enableShort
                )
            {
                EnterShort(DefaultQuantity);
            }

            AtmStrategyHandler();
        }
Ejemplo n.º 7
0
        protected override void OnStart()
        {
            dc1 = Indicators.DonchianChannel(dcPeriod1);
            dc2 = Indicators.DonchianChannel(dcPeriod2);

            ema1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, emaPeriod1);
            ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, emaPeriod2);

            atr = Indicators.AverageTrueRange(atrPeriod, MovingAverageType.Exponential);
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DonchianSignal" /> class.
 /// </summary>
 /// <param name="indicator">The indicator.</param>
 /// <param name="periods">The periods.</param>
 /// <param name="direction">
 ///     The trade rule direction. Only used if the instance will be part of a
 ///     <see cref="Rule" /> class
 /// </param>
 /// <remarks>The oscillator must be registered BEFORE being used by this constructor.</remarks>
 public DonchianSignal(dynamic indicator, DonchianChannel donchian, int periods, Direction direction = Direction.LongOnly)
 {
     Initialize(indicator, direction);
     //donchian.UpperBand.Updated += new IndicatorUpdatedHandler(Max_Updated);
     //donchian.LowerBand.Updated += new IndicatorUpdatedHandler(Min_Updated);
     _donchian          = donchian;
     _upperBand         = donchian.UpperBand;
     _lowerBand         = donchian.LowerBand;
     _indicators        = new int[periods];
     indicator.Updated += new IndicatorUpdatedHandler(Price_Updated);
 }
Ejemplo n.º 9
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                  = @"Lazy River Strategy based on TradingView strategy.";
                Name                         = "TfsLazyRiverV3";
                Calculate                    = Calculate.OnBarClose;
                EntriesPerDirection          = 1;
                EntryHandling                = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = true;
                ExitOnSessionCloseSeconds    = 30;
                IsFillLimitOnTouch           = false;
                MaximumBarsLookBack          = MaximumBarsLookBack.TwoHundredFiftySix;
                OrderFillResolution          = OrderFillResolution.Standard;
                Slippage                     = 0;
                StartBehavior                = StartBehavior.WaitUntilFlat;
                TimeInForce                  = TimeInForce.Gtc;
                TraceOrders                  = false;
                RealtimeErrorHandling        = RealtimeErrorHandling.StopCancelClose;
                StopTargetHandling           = StopTargetHandling.PerEntryExecution;
                BarsRequiredToTrade          = 20;
                // Disable this property for performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
                MaFastPeriod = 20;
                MaSlowPeriod = 50;
                MaLongPeriod = 200;
                DcPeriod     = 14;
                RiskFactor   = 1;
                TradeLong    = true;
                TradeShort   = false;
            }
            else if (State == State.Configure)
            {
            }
            else if (State == State.DataLoaded)
            {
                maFast = EMA(MaFastPeriod);
                maSlow = EMA(MaSlowPeriod);
                maLong = SMA(MaLongPeriod);
                dc     = DonchianChannel(DcPeriod);

                maFast.Plots[0].Brush = Brushes.SkyBlue;
                maSlow.Plots[0].Brush = Brushes.DodgerBlue;
                maLong.Plots[0].Brush = Brushes.Blue;
                dc.Plots[0].Brush     = Brushes.Beige;

                AddChartIndicator(maFast);
                AddChartIndicator(maSlow);
                AddChartIndicator(maLong);
                AddChartIndicator(dc);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            dcFast = DonchianChannel(DonChanPeriod1);
            dcSlow = DonchianChannel(DonChanPeriod2);

            if (Position.MarketPosition != MarketPosition.Flat)
            {
                barsInTrend = 0;
                return;
            }

            switch (status)
            {
            case 0:
                if (barsInTrend != 0)
                {
                    barsInPriorTrendCount = barsInTrend;
                    barsInTrend           = 1;
                }
                status = GetBarLocation(0);
                break;

            case 1:
                if (GetBarLocation(0) != 1)
                {
                    status = 0;
                    break;
                }
                barsInTrend++;

                if (barsInTrend > 2)                         // start to look for a pullback to get in
                {
                    if (!UpBar(0))
                    {
                        DrawDot(CurrentBar + "L", false, 0, High[0] + 3 * TickSize, Color.Blue);
                        //DrawDot(CurrentBar + "!=", false, 0, High[0] + 3 * TickSize, Color.Black);
                        double limit = High[0] + 1 * TickSize;
                        //DrawText(CurrentBar + "LT", limit + "", 0, Low[0] - 8 * TickSize, Color.Black);
                        EnterLongStopLimit(limit, limit);
                    }
                }
                break;

            case -1:
                status = 0;
                break;

            default:

                break;
            }
        }
Ejemplo n.º 11
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description = @"TTMS momentum histogram with squeeze dots.";
                Name        = "TTMS";

                Calculate                = Calculate.OnPriceChange;
                IsOverlay                = false;
                DisplayInDataBox         = true;
                DrawOnPricePanel         = false;
                DrawHorizontalGridLines  = false;
                DrawVerticalGridLines    = false;
                PaintPriceMarkers        = true;
                ScaleJustification       = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                IsSuspendedWhileInactive = true;

                MomentumLength = 20;
                SqueezeLength  = 20;

                SqueezeDotBrush      = Brushes.Red;
                NormalDotBrush       = Brushes.Blue;
                HistAboveZeroRising  = Brushes.Lime;
                HistAboveZeroFalling = Brushes.DarkSlateGray;
                HistBelowZeroFalling = Brushes.Red;
                HistBelowZeroRising  = Brushes.DarkSlateGray;

                SoundAlertsOn  = false;
                BuySoundAlert  = "Alert3.wav";
                SellSoundAlert = "Alert4.wav";

                AddPlot(new Stroke(Brushes.DarkSlateGray, 5), PlotStyle.Bar, "MomentumHistogram");
                AddPlot(new Stroke(NormalDotBrush, 2), PlotStyle.Dot, "SqueezeDots");
            }
            else if (State == State.Configure)
            {
                lrm_            = new Series <double>(this);
                medianPriceOsc_ = new Series <double>(this);

                BB   = Bollinger(2.0, SqueezeLength);
                KC   = KeltnerChannel(1.5, SqueezeLength);
                DC   = DonchianChannel(MomentumLength);
                LR   = LinReg(medianPriceOsc_, MomentumLength);
                ema_ = EMA(MomentumLength);
            }
        }
Ejemplo n.º 12
0
        public void ResetsProperly()
        {
            var donchianChannelIndicator = new DonchianChannel("DCH", 50);

            foreach (var data in TestHelper.GetTradeBarStream("spy_with_don50.txt", false))
            {
                donchianChannelIndicator.Update(data);
            }

            Assert.IsTrue(donchianChannelIndicator.IsReady);
            Assert.IsTrue(donchianChannelIndicator.UpperBand.IsReady);
            Assert.IsTrue(donchianChannelIndicator.LowerBand.IsReady);

            donchianChannelIndicator.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(donchianChannelIndicator);
            TestHelper.AssertIndicatorIsInDefaultState(donchianChannelIndicator.UpperBand);
            TestHelper.AssertIndicatorIsInDefaultState(donchianChannelIndicator.LowerBand);
        }
Ejemplo n.º 13
0
        public IndicatorLogBot()
        {
            indicator = new DonchianChannel(new TDonchianChannel
            {
                Symbol    = "XAUUSD",
                TimeFrame = "h1",
                Periods   = 35,
                Log       = true,
            })
            {
                //Periods = 35,
            };

            DesiredSubscriptions = new List <MarketDataSubscription>()
            {
                //new MarketDataSubscription("XAUUSD", TimeFrame.m1),
                new MarketDataSubscription("XAUUSD", TimeFrame.h1),
                //new MarketDataSubscription("XAUUSD", TimeFrame.h2),
                //new MarketDataSubscription("EURUSD", TimeFrame.m1),
            };
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        ///
        /// </summary>
        protected override void Initialize()
        {
            atr = ATR(14);
            Add(atr);

            dc = DonchianChannel(DonchianPeriod);
            dc.Displacement      = 1;
            dc.PaintPriceMarkers = false;
            Add(dc);

//			// CL settings CST
//			Add(PitColor(Color.Blue, 80000, 15, 143000));

            SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
            SetStopLoss(CalculationMode.Ticks, StopLoss);
            //SetTrailStop(CalculationMode.Ticks, Iparm2);

            Unmanaged           = false;
            BarsRequired        = 10;
            CalculateOnBarClose = true;
            ExitOnClose         = false;
            IncludeCommission   = true;
        }