Exemplo n.º 1
0
        //
        #endregion//Properties


        #region Public Initialization Methods
        // *****************************************************************
        // ****                 Public Initialization                   ****
        // *****************************************************************
        //
        //
        // ****************************************
        // ****     Setup Initialize()         ****
        // ****************************************
        /// <summary>
        /// The Strategy has been created, and now we add its engines.
        /// When we call Engine.SetupInitialize() the engine can make NO assumptions
        /// about the Strategy, except that it and its StrategyHub exists.
        /// Other Engines may or may not exist.
        /// What is allowed is that Engines can spawn other Engines and add them
        /// to the *end* of the Strategy.m_Engines[] list freely.
        /// </summary>
        public void SetupInitialize(IEngineHub myHub)
        {
            StrategyHub = (StrategyHub)myHub;                           // store ptr to new parent hub.

            // First initialize each of my engines.
            int id = 0;

            while (id < m_Engines.Count)                                // Loop using while so that Engines can ADD new engines to end of list.
            {                                                           // Adding new engines spontaneously is allowed here only.
                Engine engine = m_Engines[id];
                engine.SetupInitialize(StrategyHub, this, id);          // Tell Engine his new Hub, and owner, and his new id#.

                // Keep track of important engine ptrs we need.
                if (engine is Engines.PricingEngine)                    // using simple "if"s allows one engine to play multiple roles.
                {
                    m_PricingEngine = (Engines.PricingEngine)engine;
                }
                if (engine is IOrderEngine)
                {
                    m_OrderEngine = (IOrderEngine)engine;
                }
                if (engine is ZGraphEngine)
                {
                    m_GraphEngine = (ZGraphEngine)engine;
                }

                id++;
            } //next engine id
            m_IsInitializeComplete = true;                               // after this point if engines are added, they have to manually Initialize
        }     //SetupInitialize()
Exemplo n.º 2
0
        //
        //
        //
        //
        // ****************************************
        // ****     Setup Initialize()         ****
        // ****************************************
        /// <summary>
        /// The Strategy has been created, and now we add its engines.
        /// When we call Engine.SetupInitialize() the engine can make NO assumptions
        /// about the Strategy, except that it and its StrategyHub exists.
        /// Other Engines may or may not exist.
        /// What is allowed is that Engines can spawn other Engines and add them
        /// to the *end* of the Strategy.m_Engines[] list freely.
        /// </summary>
        public void SetupInitialize(IEngineHub myHub)
        {
            StrategyHub = (StrategyHub)myHub;                           // store ptr to new parent hub.

            // First initialize each of my engines.
            int id = 0;

            while (id < m_Engines.Count)                                // Loop using while so that Engines can ADD new engines to end of list.
            {                                                           // Adding new engines spontaneously is allowed here only.
                Engine engine = m_Engines[id];
                engine.SetupInitialize(StrategyHub, this, id);          // Tell Engine his new Hub, and owner, and his new id#.

                // Keep track of important engine ptrs we need.
                if (engine is PricingEngine)                            // using simple "if"s allows one engine to play multiple roles.
                {
                    PricingEngines.Add((PricingEngine)engine);          //m_PricingEngine = (StrategyEngines.PricingEngine)engine;
                }
                if (engine is TradeEngine)
                {
                    m_OrderEngine = (TradeEngine)engine;
                }
                if (engine is ZGraphEngine)
                {
                    m_GraphEngine = (ZGraphEngine)engine;
                }
                if (engine is FauxQuote)
                {
                    m_QuoteEngine = (FauxQuote)engine;
                }
                id++;
            }//next engine id

            // Create missing basic engines
            if (m_OrderEngine == null)
            {
                m_OrderEngine = new TradeEngine();
                TryAddEngine(m_OrderEngine, myHub);
                m_OrderEngine.SetupInitialize(StrategyHub, this, -1);// Tell Engine his new Hub, and owner, and his new id# (which is already set in TryAddEngine()).
            }
            if (m_GraphEngine == null)
            {
                m_GraphEngine = new ZGraphEngine();
                TryAddEngine(m_GraphEngine, myHub);
                m_GraphEngine.SetupInitialize(StrategyHub, this, -1);
            }
            if (m_QuoteEngine == null)
            {
                QuoteEngine quoteEngine = new QuoteEngine();
                m_QuoteEngine = quoteEngine;
                TryAddEngine(quoteEngine, myHub);
                quoteEngine.SetupInitialize(StrategyHub, this, -1);
            }

            // Exit
            m_IsInitializeComplete = true;                               // Must be last line in this method.
        }//SetupInitialize()
Exemplo n.º 3
0
        //
        //
        /// <summary>
        /// Add a curve by definition.
        /// </summary>
        /// <param name="graphEngine"></param>
        /// <param name="graphName"></param>
        /// <param name="curveName"></param>
        /// <param name="graphID"></param>
        /// <param name="color"></param>
        /// <param name="dashStyle"></param>
        /// <param name="symbolType"></param>
        /// <returns></returns>
        public static void AddCurveToGraphEngine(ZGraphEngine graphEngine, string graphName, string curveName, int graphID, Color color, DashStyle dashStyle, SymbolType symbolType)
        {
            CurveDefinition curveDefinition = new CurveDefinition();

            curveDefinition.GraphName  = graphName;
            curveDefinition.CurveName  = curveName;
            curveDefinition.GraphID    = graphID;
            curveDefinition.CurveColor = color;
            curveDefinition.DashStyle  = dashStyle;
            curveDefinition.Symbol     = symbolType;
            graphEngine.AddDefinition(curveDefinition);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a curve by definition.
        /// </summary>
        /// <param name="graphEngine"></param>
        /// <param name="graphName"></param>
        /// <param name="curveName"></param>
        /// <param name="graphID"></param>
        /// <param name="color"></param>
        /// <param name="isLineVisible"></param>
        /// <param name="symbolType"></param>
        /// <param name="symbolFillColor"></param>
        /// <returns></returns>
        public static void AddCurveToGraphEngine(ZGraphEngine graphEngine, string graphName, string curveName, int graphID, Color color, bool isLineVisible, SymbolType symbolType, Color symbolFillColor)
        {
            CurveDefinition curveDefinition = new CurveDefinition();

            curveDefinition.GraphName       = graphName;
            curveDefinition.CurveName       = curveName;
            curveDefinition.GraphID         = graphID;
            curveDefinition.CurveColor      = color;
            curveDefinition.IsLineVisible   = isLineVisible;
            curveDefinition.Symbol          = symbolType;
            curveDefinition.SymbolFillColor = symbolFillColor;
            graphEngine.AddDefinition(curveDefinition);
        }
Exemplo n.º 5
0
        //
        //
        public override void SetupBegin(IEngineHub myEngineHub, IEngineContainer engineContainer)
        {
            base.SetupBegin(myEngineHub, engineContainer);  // call QuoteEngine base class
            if (ParentStrategy != null)
            {
                m_GraphEngine = ParentStrategy.m_GraphEngine;
            }

            #region Initialize Graph
            if (m_IsGraphEnabled && m_GraphEngine != null)
            {
                string[] strArray  = this.m_EngineName.Split(':');
                string   graphName = strArray[strArray.Length - 1];

                int graphID = 0;
                foreach (CurveDefinition c in m_GraphEngine.CurveDefinitions.CurveDefinitions)
                {
                    if (graphID <= c.GraphID)
                    {
                        graphID = c.GraphID + 1;
                    }                                                           // use next available ID#.
                }
                m_GraphID = graphID;

                CurveDefinition cdef;

                /*
                 * cdef = new CurveDefinition();
                 * cdef.GraphName = string.Format("{0}", graphName);
                 * cdef.CurveName = "Price";
                 * cdef.GraphID = graphID;
                 * cdef.CurveColor = Color.Black;
                 * cdef.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                 * cdef.Symbol = ZedGraph.SymbolType.None;
                 * m_GraphEngine.AddDefinition(cdef);
                 */
                cdef            = new CurveDefinition();
                cdef.GraphName  = string.Format("{0}", graphName);
                cdef.CurveName  = "Bid";
                cdef.GraphID    = graphID;
                cdef.CurveColor = Color.Gray;
                cdef.DashStyle  = System.Drawing.Drawing2D.DashStyle.Solid;
                cdef.Symbol     = ZedGraph.SymbolType.None;
                m_GraphEngine.AddDefinition(cdef);

                cdef            = new CurveDefinition();
                cdef.GraphName  = string.Format("{0}", graphName);
                cdef.CurveName  = "Ask";
                cdef.GraphID    = graphID;
                cdef.CurveColor = Color.Gray;
                cdef.DashStyle  = System.Drawing.Drawing2D.DashStyle.Solid;
                cdef.Symbol     = ZedGraph.SymbolType.None;
                m_GraphEngine.AddDefinition(cdef);


                cdef            = new CurveDefinition();
                cdef.CurveName  = UV.Lib.Utilities.QTMath.MktSideToLongString(0);
                cdef.GraphID    = graphID;
                cdef.CurveColor = Color.Blue;
                cdef.CurveWidth = 2.0F;
                cdef.DashStyle  = System.Drawing.Drawing2D.DashStyle.Solid;
                cdef.Symbol     = ZedGraph.SymbolType.None;
                m_GraphEngine.AddDefinition(cdef);

                cdef            = new CurveDefinition();
                cdef.CurveName  = UV.Lib.Utilities.QTMath.MktSideToLongString(1);
                cdef.GraphID    = graphID;
                cdef.CurveColor = Color.Red;
                cdef.CurveWidth = 2.0F;
                cdef.DashStyle  = System.Drawing.Drawing2D.DashStyle.Solid;
                cdef.Symbol     = ZedGraph.SymbolType.None;
                m_GraphEngine.AddDefinition(cdef);

                //
                // Position indicators
                //
                cdef                 = new CurveDefinition();
                cdef.CurveName       = "Long Entry";
                cdef.GraphID         = graphID;
                cdef.CurveColor      = Color.Blue;
                cdef.IsLineVisible   = false;
                cdef.Symbol          = ZedGraph.SymbolType.Triangle;
                cdef.SymbolFillColor = Color.Blue;
                m_GraphEngine.AddDefinition(cdef);

                cdef                 = new CurveDefinition();
                cdef.CurveName       = "Long Exit";
                cdef.GraphID         = graphID;
                cdef.CurveColor      = Color.Blue;
                cdef.IsLineVisible   = false;
                cdef.Symbol          = ZedGraph.SymbolType.TriangleDown;
                cdef.SymbolFillColor = Color.White;
                m_GraphEngine.AddDefinition(cdef);

                cdef                 = new CurveDefinition();
                cdef.CurveName       = "Short Entry";
                cdef.GraphID         = graphID;
                cdef.CurveColor      = Color.Red;
                cdef.IsLineVisible   = false;
                cdef.Symbol          = ZedGraph.SymbolType.TriangleDown;
                cdef.SymbolFillColor = Color.Red;
                m_GraphEngine.AddDefinition(cdef);

                cdef                 = new CurveDefinition();
                cdef.CurveName       = "Short Exit";
                cdef.GraphID         = graphID;
                cdef.CurveColor      = Color.Red;
                cdef.IsLineVisible   = false;
                cdef.Symbol          = ZedGraph.SymbolType.Triangle;
                cdef.SymbolFillColor = Color.White;
                m_GraphEngine.AddDefinition(cdef);

                //
                // Stops
                //
                cdef               = new CurveDefinition();
                cdef.CurveName     = "Stop Price";
                cdef.GraphID       = graphID;
                cdef.CurveColor    = Color.Green;
                cdef.IsLineVisible = false;
                cdef.DashStyle     = System.Drawing.Drawing2D.DashStyle.Solid;
                cdef.Symbol        = ZedGraph.SymbolType.HDash;
                m_GraphEngine.AddDefinition(cdef);
            }
            else
            {
                m_IsGraphEnabled = false;
            }
            #endregion // graph initialization.
        }
 //
 //
 /// <summary>
 /// Called by a model to add a graphing engine if we would like our stop prices to be
 /// added to the graph.
 /// </summary>
 /// <param name="zGraphEngine"></param>
 /// <param name="graphID"></param>
 /// <param name="curveName"></param>
 public void AddGraphEngine(ZGraphEngine zGraphEngine, int graphID, string curveName)
 {
     m_GraphEngine    = zGraphEngine;
     m_GraphId        = graphID;
     m_StopCurvveName = curveName;
 }