Beispiel #1
0
 protected override void OnStateChange()
 {
     base.OnStateChange();
     if (State == State.SetDefaults)
     {
         Description                  = @"Use Customized Chart Trader.";
         Name                         = "StgChartTrader";
         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;
         IsUnmanaged = false;
     }
     else if (State == State.Configure)
     {
     }
     else if (State == State.DataLoaded)
     {
         giChartTrader = GIChartTrader(this.Input);
         AddChartIndicator(giChartTrader);
         giChartTrader.RaiseIndicatorEvent += OnTradeByChartTrader;
     }
 }
        protected override void OnStateChange()
        {
            base.OnStateChange();
            if (State == State.SetDefaults)
            {
                Description = "Hedge ES, NQ, and RTY";
                Name        = "StgEQRHedger";
                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                Calculate = Calculate.OnBarClose;
                //IsFillLimitOnTouch							= false;
                TraceOrders         = false;
                BarsRequiredToTrade = 22;
                IsUnmanaged         = false;
                OrderFillResolution = OrderFillResolution.Standard;
                EntriesPerDirection = 1;
                DefaultQuantity     = 5;
                StopTargetHandling  = StopTargetHandling.PerEntryExecution;
                MM_ProfitFactorMax  = 1;
                MM_ProfitFactorMin  = 0;
                TG_TradeEndH        = 10;
                TG_TradeEndM        = 45;
                //IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                // Add an MSFT 1 minute Bars object to the strategy
                //AddDataSeries("NQ 06-20", Data.BarsPeriodType.Minute, 13);
                AddDataSeries("NQ 09-20", Data.BarsPeriodType.Minute, 4);
                AddDataSeries("RTY 09-20", Data.BarsPeriodType.Minute, 4);
                SetOrderQuantity = SetOrderQuantity.Strategy;                 // calculate orders based off default size
                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 200);
            }
            else if (State == State.DataLoaded)
            {
                rsi  = RSI(14, 1);
                rsi1 = RSI(BarsArray[1], 14, 1);
                rsi2 = RSI(BarsArray[2], 14, 1);
                adx  = ADX(14);
                adx1 = ADX(BarsArray[1], 14);
                adx2 = ADX(BarsArray[2], 14);

                giPctSpd      = GIPctSpd(8);
                giChartTrader = GIChartTrader(this.Input);
                // Add RSI and ADX indicators to the chart for display
                // This only displays the indicators for the primary Bars object (main instrument) on the chart
                AddChartIndicator(rsi);
                AddChartIndicator(adx);
                AddChartIndicator(giPctSpd);
                AddChartIndicator(giChartTrader);

                giPctSpd.RaiseIndicatorEvent      += OnTradeByPctSpd;
                giPctSpd.TM_ClosingH               = TG_TradeEndH;
                giPctSpd.TM_ClosingM               = TG_TradeEndM;
                giChartTrader.RaiseIndicatorEvent += OnTradeByChartTrader;
                SetPrintOut(1);
                Print(String.Format("{0}: IsUnmanaged={1}", this.GetType().Name, IsUnmanaged));
                Print(String.Format("{0}: DataLoaded...BarsArray.Length={1}", this.GetType().Name, BarsArray.Length));

                //this.Dispatcher.Invoke(() =>
                this.Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    //be.Show();
                }));
            }
        }