Ejemplo n.º 1
0
        protected void AutoStrategy1()
        {
            if (sessionIterator == null || BarsArray[0].IsFirstBarOfSession)
            {
                if (sessionIterator == null)
                {
                    sessionIterator = new Data.SessionIterator(BarsArray[0]);
                    sessionIterator.GetNextSession(Times[0][0], true);
                }
                else if (BarsArray[0].IsFirstBarOfSession)
                {
                    sessionIterator.GetNextSession(Times[0][0], true);
                }

                startTimeForShortEntries = sessionIterator.ActualSessionBegin.AddMinutes(15);
                endTimeForShortEntries   = startTimeForShortEntries.AddMinutes(45);
            }

            if (candleStickPatternLogic.Evaluate(ChartPattern.MorningStar) &&
                startTimeForShortEntries < Times[0][0] && Times[0][0] <= endTimeForShortEntries &&
                (Times[0][0].DayOfWeek == DayOfWeek.Monday || Times[0][0].DayOfWeek == DayOfWeek.Tuesday || Times[0][0].DayOfWeek == DayOfWeek.Thursday || Times[0][0].DayOfWeek == DayOfWeek.Saturday))
            {
                EnterShort();
            }
        }
Ejemplo n.º 2
0
        private void CalculateDays()
        {
            DateTime now = Cbi.Connection.PlaybackConnection != null ? Cbi.Connection.PlaybackConnection.Now : Core.Globals.Now;

            if (sessionIterator == null)
            {
                sessionIterator = new SessionIterator(Instrument.MasterInstrument.TradingHours);
            }
            if (now > sessionIterator.ActualTradingDayEndLocal)
            {
                sessionIterator.GetNextSession(now, false);

                lock (Instrument.MasterInstrument.RolloverCollection)
                {
                    foreach (Rollover rollover in Instrument.MasterInstrument.RolloverCollection)
                    {
                        if (rollover.ContractMonth == Instrument.Expiry)
                        {
                            CurrentValue = Instrument.MasterInstrument.GetNextRolloverDate(rollover.Date).Subtract(sessionIterator.ActualTradingDayExchange).TotalDays;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
 {
     if (marketDataUpdate.IsReset)
     {
         CurrentValue    = double.MinValue;
         sessionIterator = null;
         return;
     }
 }
Ejemplo n.º 4
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                  = @"Enter the description for your new custom Strategy here.";
                Name                         = "MarketSpread";
                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          = 1;
                Symbol2                      = "RTY 12-18";
                SpreadThreshold              = .01;
                // Disable this property for performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
            }
            else if (State == State.Configure)
            {
                sessionIterator = null;

                switch (BarsPeriod.BarsPeriodType)
                {
                case BarsPeriodType.Day:
                case BarsPeriodType.Week:
                case BarsPeriodType.Month:
                case BarsPeriodType.Year:
                case BarsPeriodType.Minute:
                case BarsPeriodType.Second:
                    AddDataSeries(Symbol2, BarsPeriod.BarsPeriodType, BarsPeriod.Value);
                    break;

                default:
                    break;
                }

                AddDataSeries(Data.BarsPeriodType.Second, 5);
                AddDataSeries(this.Symbol2, Data.BarsPeriodType.Second, 5);

                spread = Spread(BarsArray[0], 1, -1, true, this.Symbol2, BarsPeriod.BarsPeriodType, BarsPeriod.Value);
                AddChartIndicator(spread);
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator = new Data.SessionIterator(BarsArray[0]);
            }
        }
Ejemplo n.º 5
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                  = @"Enter the description for your new custom Strategy here.";
                Name                         = "LongTermAcd";
                Calculate                    = Calculate.OnBarClose;
                EntriesPerDirection          = 1;
                EntryHandling                = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = false;
                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          = 51;
                // Disable this property for performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;

                ShortTermPeriod        = 14;
                IntermediateTermPeriod = 30;
                LongTermPeriod         = 50;
            }
            else if (State == State.Configure)
            {
                AddDataSeries(BarsPeriodType.Minute, 1);
            }
            else if (State == State.DataLoaded)
            {
                todayPivotPriceSeries = new Series <double>(BarsArray[1]);

                pivotPrice = AcdDailyPivotPrice();
                AddChartIndicator(pivotPrice);

                shortTermMA = SMA(14);
                shortTermMA.Plots[0].Brush = shortTermBrush;
                AddChartIndicator(shortTermMA);

                intermediateTermMA = SMA(30);
                intermediateTermMA.Plots[0].Brush = intermediateTermBrush;
                AddChartIndicator(intermediateTermMA);

                longTermMA = SMA(50);
                longTermMA.Plots[0].Brush = longTermBrush;
                AddChartIndicator(longTermMA);

                sessionIterator = new Data.SessionIterator(BarsArray[1]);
            }
        }
Ejemplo n.º 6
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                  = @"Enter the description for your new custom Strategy here.";
                Name                         = "AcdSandbox";
                Calculate                    = Calculate.OnBarClose;
                EntriesPerDirection          = 1;
                EntryHandling                = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = false;
                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;

                ATicks        = 28;
                CTicks        = 16;
                ProjectHour   = 13;
                ProjectMinute = 0;
            }
            else if (State == State.Configure)
            {
                currentDate     = Core.Globals.MinDate;
                sessionIterator = null;

                AddDataSeries(Data.BarsPeriodType.Second, 30);
                AddDataSeries(Data.BarsPeriodType.Day, 1);

                guerillaAcdMasterIndicator = GuerillaAcdMasterIndicator(this.ATicks, this.CTicks, this.ProjectHour, this.ProjectMinute);
                AddChartIndicator(guerillaAcdMasterIndicator);

                greenBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.GreenBar, false, false, false, 0);
                AddChartIndicator(greenBarIndicator);

                redBarIndicator = GuerillaStickIndicator(GuerillaChartPattern.RedBar, false, false, false, 0);
                AddChartIndicator(redBarIndicator);
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator = new Data.SessionIterator(BarsArray[0]);
            }
        }
Ejemplo n.º 7
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                  = @"Enter the description for your new custom Strategy here.";
                Name                         = "Distilled";
                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;
            }
            else if (State == State.Configure)
            {
                sessionIterator = null;

                SetProfitTarget(CalculationMode.Ticks, 6);
                SetStopLoss(CalculationMode.Ticks, 16);

                //AddDataSeries(Data.BarsPeriodType.Second, 450);
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator = new Data.SessionIterator(BarsArray[0]);

                fullGreenBarIndicator = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.GreenBar, false, false, false, 0);
                fullRedBarIndicator   = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.RedBar, false, false, false, 0);

                fullHammerBarIndicator       = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.Hammer, false, false, false, 0);
                fullShootingStarBarIndicator = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.ShootingStar, false, false, false, 0);

                fullBullishTrendBarIndicator = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.BullishHalfBar, false, false, false, 0);
                fullBearishTrendBarIndicator = GuerillaStickIndicator(BarsArray[0], GuerillaChartPattern.BearishHalfBar, false, false, false, 0);

                //halfGreenBarIndicator = GuerillaStickIndicator(BarsArray[1], GuerillaChartPattern.GreenBar, false, false, false, 0);
                //halfRedBarIndicator = GuerillaStickIndicator(BarsArray[1], GuerillaChartPattern.RedBar, false, false, false, 0);
            }
        }
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionPriorDayOHLC;
                Name        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNamePriorDayOHLC;
                IsAutoScale = false;
                IsOverlay   = true;
                IsSuspendedWhileInactive = true;
                DrawOnPricePanel         = false;
                ShowClose = true;
                ShowLow   = true;
                ShowHigh  = true;
                ShowOpen  = true;

                AddPlot(new Stroke(Brushes.SteelBlue, DashStyleHelper.Dash, 2), PlotStyle.Hash, NinjaTrader.Custom.Resource.PriorDayOHLCOpen);
                AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Hash, NinjaTrader.Custom.Resource.PriorDayOHLCHigh);
                AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Hash, NinjaTrader.Custom.Resource.PriorDayOHLCLow);
                AddPlot(new Stroke(Brushes.SlateBlue, DashStyleHelper.Dash, 2), PlotStyle.Hash, NinjaTrader.Custom.Resource.PriorDayOHLCClose);
            }
            else if (State == State.Configure)
            {
                currentDate     = Core.Globals.MinDate;
                currentClose    = 0;
                currentHigh     = 0;
                currentLow      = 0;
                currentOpen     = 0;
                priorDayClose   = 0;
                priorDayHigh    = 0;
                priorDayLow     = 0;
                priorDayOpen    = 0;
                sessionIterator = null;
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator = new Data.SessionIterator(Bars);
            }
            else if (State == State.Historical)
            {
                if (!Bars.BarsType.IsIntraday)
                {
                    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PriorDayOHLCIntradayError, TextPosition.BottomRight);
                    Log(NinjaTrader.Custom.Resource.PriorDayOHLCIntradayError, LogLevel.Error);
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnBarUpdate()
        {
            base.OnBarUpdate();

            if (this.CurrentBars[0] < this.BarsRequiredToTrade)
            {
                return;
            }

            if (this.sessionIterator == null || this.BarsArray[0].IsFirstBarOfSession)
            {
                if (this.sessionIterator == null)
                {
                    this.sessionIterator = new Data.SessionIterator(this.BarsArray[0]);
                    this.sessionIterator.GetNextSession(this.Times[0][0], true);
                }
                else if (this.BarsArray[0].IsFirstBarOfSession)
                {
                    this.sessionIterator.GetNextSession(this.Times[0][0], true);
                }

                this.startTimeForLongEntries = this.sessionIterator.ActualSessionBegin.AddMinutes(15);
                this.endTimeForLongEntries   = this.startTimeForLongEntries.AddMinutes(75);
                this.startTimeForLongExits   = this.sessionIterator.ActualSessionEnd.AddMinutes(-90);
                this.endTimeForLongExits     = this.startTimeForLongExits.AddMinutes(45);
            }

            // example entry & exit logic
            if (this.startTimeForLongEntries < this.Times[0][0] &&
                this.Times[0][0] <= this.endTimeForLongEntries &&
                (this.Times[0][0].DayOfWeek == DayOfWeek.Monday || this.Times[0][0].DayOfWeek == DayOfWeek.Friday))
            {
                //this.EnterLong();
            }

            if (this.startTimeForLongExits < this.Times[0][0] &&
                this.Times[0][0] <= this.endTimeForLongExits &&
                (this.Times[0][0].DayOfWeek == DayOfWeek.Monday || this.Times[0][0].DayOfWeek == DayOfWeek.Friday))
            {
                //this.ExitLong();
            }

            this.touchIndicatorValue = this.touchIndicator.Value[0];
        }
Ejemplo n.º 10
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description              = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionCurrentDayOHL;
                Name                     = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameCurrentDayOHL;
                IsAutoScale              = false;
                DrawOnPricePanel         = false;
                IsOverlay                = true;
                IsSuspendedWhileInactive = true;
                ShowLow                  = true;
                ShowHigh                 = true;
                ShowOpen                 = true;
                BarsRequiredToPlot       = 0;

                AddPlot(new Stroke(Brushes.Goldenrod, DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLOpen);
                AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLHigh);
                AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLLow);
            }
            else if (State == State.Configure)
            {
                currentDate = Core.Globals.MinDate;
                currentOpen = double.MinValue;
                currentHigh = double.MinValue;
                currentLow  = double.MaxValue;
                lastDate    = Core.Globals.MinDate;
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator = new SessionIterator(Bars);
            }
            else if (State == State.Historical)
            {
                if (!Bars.BarsType.IsIntraday)
                {
                    Draw.TextFixed(this, "NinjaScriptInfo", Custom.Resource.CurrentDayOHLError, TextPosition.BottomRight);
                    Log(Custom.Resource.CurrentDayOHLError, LogLevel.Error);
                }
            }
        }
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description             = @"Enter the description for your new custom Indicator here.";
                Name                    = "GuerillaAcdMasterIndicator";
                Calculate               = Calculate.OnBarClose;
                IsOverlay               = true;
                IsAutoScale             = false;
                DisplayInDataBox        = true;
                DrawOnPricePanel        = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines   = true;
                PaintPriceMarkers       = true;
                ScaleJustification      = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;

                textFont = new Gui.Tools.SimpleFont()
                {
                    Size = 14
                };
                textColor = Brushes.WhiteSmoke;

                ATicks        = 28;
                CTicks        = 16;
                ProjectHour   = 13;
                ProjectMinute = 0;
                AddPlot(new Stroke(openingRangeBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "OpenHigh");
                AddPlot(new Stroke(openingRangeBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "OpenLow");
                AddPlot(new Stroke(aBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "AUp");
                AddPlot(new Stroke(aBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "ADown");
                AddPlot(new Stroke(cBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "CUp");
                AddPlot(new Stroke(cBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "CDown");
                AddPlot(new Stroke(pivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "PivotHigh");
                AddPlot(new Stroke(pivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "PivotLow");
                AddPlot(new Stroke(rollingPivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "RollingPivotHigh");
                AddPlot(new Stroke(rollingPivotBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "RollingPivotLow");
                AddPlot(new Stroke(transparentBrush, DashStyleHelper.Dash, 2), PlotStyle.Square, "MyOpen");
            }
            else if (State == State.Configure)
            {
                AddDataSeries(BarsPeriodType.Second, 30);
                AddDataSeries(BarsPeriodType.Day, 1);

                currentDate         = Core.Globals.MinDate;
                sessionIterator     = null;
                fastSessionIterator = null;

                opening      = 0;
                openingHigh  = 0;
                openingLow   = 0;
                currentAUp   = 0;
                currentADown = 0;
                currentCUp   = 0;
                currentCDown = 0;

                currentClose  = 0;
                currentHigh   = 0;
                currentLow    = 0;
                priorDayClose = 0;
                priorDayHigh  = 0;
                priorDayLow   = 0;
                priorDayLow   = 0;
                priorDayLow   = 0;

                aUpBreachedBar   = 0;
                aUpSuccessBar    = 0;
                aDownBreachedBar = 0;
                aDownSuccessBar  = 0;
                cUpBreachedBar   = 0;
                cUpSuccessBar    = 0;
                pivotUpperBound  = 0;
                pivotLowerBound  = 0;
            }
            else if (State == State.DataLoaded)
            {
                sessionIterator      = new Data.SessionIterator(BarsArray[0]);
                fastPivotPriceSeries = new Series <double>(BarsArray[1]);
                fastSessionIterator  = new Data.SessionIterator(BarsArray[1]);
                halfTimeFrame        = BarsArray[0].BarsPeriod.Value / 2;
                halfTimeFrameBars    = halfTimeFrame * 2;
                openingBars          = BarsArray[0].BarsPeriod.Value * 2;

                trueRangeSeries = new Series <double>(BarsArray[2]);
                aSeries         = new Series <double>(BarsArray[2]);
                cSeries         = new Series <double>(BarsArray[2]);

                dayNumberLineSeries = new Series <double>(BarsArray[2]);
                numberLineSeries    = new Series <double>(BarsArray[2]);
            }
        }
Ejemplo n.º 12
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description          = NinjaTrader.Custom.Resource.NinjaScriptMarketAnalyzerColumnDescriptionChartNetChange;
                Name                 = NinjaTrader.Custom.Resource.NinjaScriptMarketAnalyzerColumnNameChartNetChange;
                DownArea             = Brushes.Red;
                DownOutline          = Brushes.Red;
                IsDataSeriesRequired = true;
                Opacity              = 50;
                UpArea               = Brushes.LimeGreen;
                UpOutline            = Brushes.LimeGreen;
            }
            else if (State == State.Configure)
            {
                BarsPeriod = new Data.BarsPeriod {
                    BarsPeriodType = Data.BarsPeriodType.Minute, Value = 1
                };
                DaysBack  = 0;
                RangeType = Cbi.RangeType.Days;
                To        = Now.Date;

                if (Instrument != null)
                {
                    TradingHoursInstance = Instrument.MasterInstrument.TradingHours;
                    sessionIterator      = new Data.SessionIterator(TradingHoursInstance);

                    if (sessionIterator.IsInSession(Now, false, true))
                    {
                        tradingDayBegin = sessionIterator.GetTradingDayBeginLocal(sessionIterator.ActualTradingDayExchange);
                        tradingDayEnd   = sessionIterator.ActualTradingDayEndLocal;
                    }
                    else
                    {
                        DateTime tradingDay           = sessionIterator.ActualTradingDayExchange;
                        bool     isPreviousTradingDay = true;

                        while (true)
                        {
                            tradingDay = tradingDay.AddDays(-1);
                            if (sessionIterator.IsTradingDayDefined(tradingDay))
                            {
                                if (isPreviousTradingDay)
                                {
                                    tradingDayBegin      = sessionIterator.GetTradingDayBeginLocal(tradingDay);
                                    tradingDayEnd        = sessionIterator.GetTradingDayEndLocal(tradingDay);
                                    isPreviousTradingDay = false;
                                }
                                else
                                {
                                    DateTime tmpTradingDayEnd = sessionIterator.GetTradingDayEndLocal(tradingDay);
                                    DaysBack = (int)To.Subtract(tmpTradingDayEnd.Date).TotalDays + (tmpTradingDayEnd.Hour == 0 && tmpTradingDayEnd.Minute == 0 ? 1 : 0);
                                    break;
                                }
                            }
                        }

                        sessionIterator.GetNextSession(tradingDayBegin.AddSeconds(1), false);
                    }
                }
            }
        }