Beispiel #1
0
        protected override void OnStateChange()
        {
            try {
                if (State == State.SetDefaults)
                {
                    if (TraceOrders)
                    {
                        Print(this.ToString() + ", State=" + State.ToString());
                    }
                    Description = @"Base Strategy for SpreadTrader, do no edit!";
                    Name        = "SpreadExitStrategy";
                    Zweistein.SpreadTraderWindow.StrategySetDefaults(this);

                    Units     = 1;
                    Calculate = Calculate.OnPriceChange;
                    base.BarsRequiredToTrade = 0;
                    Left = -1;
                    Top  = -1;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(strLeg2Instrument, BarsPeriod.BarsPeriodType, BarsPeriod.Value);
                    Zweistein.Money.UpdateRates();
                }
                else if (State == State.DataLoaded)
                {
                    if (stw == null)
                    {
                        string tmp = "";
                        for (int i = 0; i < 3; i++)
                        {
                            tmp = (string)DisplayName.Clone();
                            if (tmp.Contains("?"))
                            {
                                Zweistein.NinjaTraderLog.Process("SpreadExitstrategy.OnStateChange():", "tmp=" + tmp, LogLevel.Warning, LogCategories.Strategy);
                                System.Threading.Thread.Sleep(500);
                            }
                            else
                            {
                                break;
                            }
                        }
                        stw = Zweistein.SpreadTraderWindow.StrategyDataLoaded(this, Left, Top, spreads, tmp);
                        if (TraceOrders)
                        {
                            Print("stw=" + stw != null?tmp + ":" + stw.ToString():"null");
                        }
                    }
                }
                else if (State == State.Transition)
                {
                    if (string.IsNullOrEmpty(FirstLoadUTC))
                    {
                        FirstLoadUTC = DateTime.Now.ToUniversalTime().ToString("o");
                    }
                    if (TraceOrders)
                    {
                        Print(State.ToString() + " " + FirstLoadUTC);
                        Print(spreads.Count.ToString() + " Spreads found");
                    }
                    baccount_exeupdate       = true;
                    Account.ExecutionUpdate += Account_ExecutionUpdate;
                    if (stw != null)
                    {
                        Zweistein.SpreadTraderWindow.StrategyTransition(stw, spreads, Tickets);
                    }
                }
                else if (State == State.Terminated)
                {
                    if (Account != null && baccount_exeupdate == true)
                    {
                        Account.ExecutionUpdate -= Account_ExecutionUpdate;
                    }
                    Zweistein.SpreadTraderWindow.StrategyTerminated(stw, spreads, Tickets);
                }
            }
            catch (Exception ex) {
                Print("State.:" + ex.Message);
            }
        }