Example #1
0
        protected override void OnStateChange()
        {
            base.OnStateChange();

            switch (base.State)
            {
            //case State.Undefined:
            //    break;
            case State.SetDefaults:
                base.Name        = string.Format("_{0}", this.GetType().Name);
                base.Description = @"Template description.";

                base.Calculate = Calculate.OnEachTick;
                break;

            //case State.Configure:
            //    break;
            //case State.Active:
            //    break;
            case State.DataLoaded:

                // NOTE: verified working mechanism which fires OnBarUpdate for the indicator
                lock (this.NinjaScripts)
                {
                    this.NinjaScripts.Add(this.touchIndicator = new _BareIndicator()
                    {
                        Parent = this, IsCreatedByStrategy = true
                    });
                }

                // NOTE: this mechanism does not work properly in a 3rd party dll scenario.  Use above method which does work.
                //base.AddChartIndicator(this.touchIndicator = new _BareIndicator());

                break;
                //case State.Historical:
                //    break;
                //case State.Transition:
                //    break;
                //case State.Realtime:
                //    break;
                //case State.Terminated:
                //    break;
                //case State.Finalized:
                //    break;
                //default:
                //    break;
            }
        }
Example #2
0
        protected override void OnStateChange()
        {
            base.OnStateChange();

            #region State Flow

            // adding a strategy via Strategies Panel (Ctrl+S)
            //
            // SetDefaults (strat window) Terminated (strat window) SetDefaults (strat window)
            // SetDefaults (click add) SetDefaults (click OK) Terminated (click OK) Terminated (strat
            // window closed) Configure Account gets set EditGuid gets set ChartBars gets set
            // ChartControl gets set Instrument gets set TradingHours gets set SetDefaults Name gets
            // set EditGuid gets set to null NinjaScripts gets initialized Terminated TradingHours
            // gets set Name gets set NinjaScripts gets incremented Configure Id gets set ChartBars
            // gets set ChartControl gets set ChartPanel gets set TradingHours gets set DataLoaded
            // Bars gets set ChartPanel gets set TradingHours gets set Historical Position gets set
            // Bars gets set CurrentBar = -1 Dispatcher gets set Transition Realtime ChartPanel gets set

            #endregion State Flow

            switch (base.State)
            {
            case State.Undefined:
                break;

            case State.SetDefaults:

                base.Name      = string.Format("_{0}", this.GetType().Name);
                base.Calculate = Calculate.OnEachTick;

                base.EntriesPerDirection = 5;
                base.IncludeCommission   = true;

                base.IncludeTradeHistoryInBacktest             = false;
                base.IsExitOnSessionCloseStrategy              = true;
                base.IsInstantiatedOnEachOptimizationIteration = true;
                base.MaximumBarsLookBack       = MaximumBarsLookBack.TwoHundredFiftySix;
                base.SupportsOptimizationGraph = false;
                break;

            case State.Configure:
                this.candleStickPatternLogic = new CandleStickPatternLogic(this, 7);
                //base.SetProfitTarget(CalculationMode.Percent, 0.02);
                //base.SetTrailStop(CalculationMode.Percent, 0.01);

                // add any data series necessary
                //base.AddDataSeries(BarsPeriodType.Minute, 1);
                break;

            case State.Active:
                break;

            case State.DataLoaded:

                // verified working mechanism which fires OnBarUpdate for the indicator
                lock (this.NinjaScripts)
                {
                    this.NinjaScripts.Add(this.touchIndicator = new _BareIndicator()
                    {
                        Parent = this, IsCreatedByStrategy = true
                    });
                }

                this.testTimer          = new Timer(5000);
                this.testTimer.Elapsed += this.TestTimer_Elapsed;

                // NOTE: this method does not fire indiciator data events
                //this.templateIndicator = new TemplateIndicator() { Parent = this };
                //base.AddChartIndicator(this.templateIndicator = new TemplateIndicator() { Parent = this });
                break;

            case State.Historical:
                break;

            case State.Transition:
                break;

            case State.Realtime:
                this.testTimer.Start();
                break;

            case State.Terminated:
                if (this.testTimer != null)
                {
                    this.testTimer.Elapsed -= this.TestTimer_Elapsed;
                }
                break;

            case State.Finalized:
                break;

            default:
                break;
            }
        }