/// <summary>
        /// User, Please Describe In Short What The Signal Is Doing ...
        /// This signal sends alternatly Buy/Sell orders each time its called depending on its start event.
        /// </summary>
        ///
        /// <param name="signalBase"> Passed base class of signal usercode engine. </param>
        ///
        /// <param name="historicMarketData"> All marked data of all instrument in signals scope up to latest quotes.
        ///                                   ### Use this parameter if your Signal should process historical market data from all provided instruments. ### </param>
        ///
        /// <param name="tradeParams"> Contains all parameters needed to trade the signal.
        ///                            ### Use this parameter to change/override Signal Properties from "InternelGet-/SetParameter()" method. ### </param>
        ///
        /// <param name="trigInstrData"> When start event is NewBar or NewQuote, the instruments market data triggered the event.
        ///                              ### Use this parameter if your Signal should process the updated instument only. ### </param>
        ///
        /// <param name="queuedTicks"> During NewQuote start event, it happens that ticks are missed during calculation.
        ///                            This missed ticks are queued and passed in 'queuedTicks' for next start event.
        ///                            The most recent tick from "Trigger Instrument" is added as LAST element so all recent unprocessed ticks are passed
        ///                            within "queuedTicks" parameter.
        ///                            ### Use this parameter if your Signal works on tick level and you don't want to miss any tick. ### </param>
        ///
        /// <returns> Returns a list of trade signals for execution market or backtest. </returns>

        public static List <TradeSignal> DetectSignals(SignalBase signalBase, Dictionary <Selection, IEnumerable <Bar> > historicMarketData,
                                                       Auxiliaries.ExecuteTradesParam tradeParams,
                                                       Dictionary <Selection, IEnumerable <Bar> > trigInstrData = null,
                                                       IEnumerable <Tick> queuedTicks = null)
        {
            tradeParams.EvalCount++;
            var  trades = new List <TradeSignal>();
            Side side   = Side.Sell;

            foreach (var item in historicMarketData)
            {
                if (tradeParams.EvalCount % 2 == 0)
                {
                    side = Side.Buy;
                }
                else
                {
                    side = Side.Sell;
                }

                trades.Add(new TradeSignal
                {
                    Instrument = item.Key,
                    Time       = item.Value.Last().Date,
                    Price      = item.Value.Last().MeanClose,
                    Side       = side
                });
            }
            return(trades);
        }
        public static List <TradeSignal> BacktestPriceSegmentProcessor(SignalBase signalBase, Dictionary <Selection, IEnumerable <Bar> > marketData,
                                                                       Auxiliaries.ExecuteTradesParam tradeParams,
                                                                       PriceConstants btBarSegment, Func <Dictionary <Selection, IEnumerable <Bar> >, List <TradeSignal> > detectSignals,
                                                                       Dictionary <Selection, IEnumerable <Bar> > trigInstrData = null,
                                                                       IEnumerable <Tick> queuedTicks = null)
        {
            var modMarketData = marketData.ToDictionary(k => k.Key, v => v.Value.Select(b => new Bar(b)).ToList().AsEnumerable());
            var origLast      = marketData.Last().Value.Last();
            var modLast       = modMarketData.Last().Value.Last();

            List <TradeSignal> trades = null;

            switch (btBarSegment)
            {
            case PriceConstants.OPEN:
                modLast.HighAsk  = origLast.OpenAsk;
                modLast.HighBid  = origLast.OpenBid;
                modLast.LowAsk   = origLast.OpenAsk;
                modLast.LowBid   = origLast.OpenBid;
                modLast.CloseAsk = origLast.OpenAsk;
                modLast.CloseBid = origLast.OpenBid;
                modLast.HighAsk  = origLast.OpenAsk;

                trigInstrData = modMarketData;
                trades        = detectSignals(modMarketData);
                break;

            case PriceConstants.HIGH:
                modLast.LowAsk   = origLast.HighAsk;
                modLast.LowBid   = origLast.HighBid;
                modLast.CloseAsk = origLast.HighAsk;
                modLast.CloseBid = origLast.HighBid;
                trigInstrData    = modMarketData;
                trades           = detectSignals(modMarketData);
                break;

            case PriceConstants.LOW:
                modLast.CloseAsk = origLast.LowAsk;
                modLast.CloseBid = origLast.LowBid;
                trigInstrData    = modMarketData;
                trades           = detectSignals(modMarketData);
                break;

            case PriceConstants.CLOSE:
                trigInstrData = modMarketData;
                trades        = detectSignals(modMarketData);
                break;

            case PriceConstants.OHLC:
                signalBase.Alert($"origin openAsk: {origLast.OpenAsk}");
                signalBase.Alert($"origin openBid: {origLast.OpenBid}");
                signalBase.Alert($"origin mean: {origLast.MeanOpen}");
                signalBase.Alert($"origin highAsk: {origLast.HighAsk}");
                signalBase.Alert($"origin highBid: {origLast.HighBid}");
                signalBase.Alert($"origin mean: {origLast.MeanHigh}");
                signalBase.Alert($"origin lowAsk: {origLast.LowAsk}");
                signalBase.Alert($"origin lowBid: {origLast.LowBid}");
                signalBase.Alert($"origin mean: {origLast.MeanLow}");
                signalBase.Alert($"origin closeAsk: {origLast.CloseAsk}");
                signalBase.Alert($"origin closeBid: {origLast.CloseBid}");
                signalBase.Alert($"origin mean: {origLast.MeanClose}");
                modLast.HighAsk  = origLast.OpenAsk;
                modLast.HighBid  = origLast.OpenBid;
                modLast.LowAsk   = origLast.OpenAsk;
                modLast.LowBid   = origLast.OpenBid;
                modLast.CloseAsk = origLast.OpenAsk;
                modLast.CloseBid = origLast.OpenBid;
                trigInstrData    = modMarketData;
                signalBase.Alert($"mod openAsk: {modLast.OpenAsk}");
                signalBase.Alert($"mod openBid: {modLast.OpenBid}");
                signalBase.Alert($"mod mean: {modLast.MeanOpen}");
                signalBase.Alert($"mod highAsk: {modLast.HighAsk}");
                signalBase.Alert($"mod highBid: {modLast.HighBid}");
                signalBase.Alert($"mod mean: {modLast.MeanHigh}");
                signalBase.Alert($"mod lowAsk: {modLast.LowAsk}");
                signalBase.Alert($"mod lowBid: {modLast.LowBid}");
                signalBase.Alert($"mod mean: {modLast.MeanLow}");
                signalBase.Alert($"mod closeAsk: {modLast.CloseAsk}");
                signalBase.Alert($"mod closeBid: {modLast.CloseBid}");
                signalBase.Alert($"mod mean: {modLast.MeanClose}");
                var trades1 = detectSignals(modMarketData);
                trades = trades1;

                //signalBase.Alert($"origin openAsk: {origLast.OpenAsk}");
                //signalBase.Alert($"origin openBid: {origLast.OpenBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanOpen}");
                //signalBase.Alert($"origin highAsk: {origLast.HighAsk}");
                //signalBase.Alert($"origin highBid: {origLast.HighBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanHigh}");
                //signalBase.Alert($"origin lowAsk: {origLast.LowAsk}");
                //signalBase.Alert($"origin lowBid: {origLast.LowBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanLow}");
                //signalBase.Alert($"origin closeAsk: {origLast.CloseAsk}");
                //signalBase.Alert($"origin closeBid: {origLast.CloseBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanClose}");
                modLast.HighAsk  = origLast.HighAsk;
                modLast.HighBid  = origLast.HighBid;
                modLast.LowAsk   = origLast.HighAsk;
                modLast.LowBid   = origLast.HighBid;
                modLast.CloseAsk = origLast.HighAsk;
                modLast.CloseBid = origLast.HighBid;
                trigInstrData    = modMarketData;
                //signalBase.Alert($"mod openAsk: {modLast.OpenAsk}");
                //signalBase.Alert($"mod openBid: {modLast.OpenBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanOpen}");
                //signalBase.Alert($"mod highAsk: {modLast.HighAsk}");
                //signalBase.Alert($"mod highBid: {modLast.HighBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanHigh}");
                //signalBase.Alert($"mod lowAsk: {modLast.LowAsk}");
                //signalBase.Alert($"mod lowBid: {modLast.LowBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanLow}");
                //signalBase.Alert($"mod closeAsk: {modLast.CloseAsk}");
                //signalBase.Alert($"mod closeBid: {modLast.CloseBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanClose}");
                var trades2 = detectSignals(modMarketData);
                trades.AddRange(trades2);

                //signalBase.Alert($"origin openAsk: {origLast.OpenAsk}");
                //signalBase.Alert($"origin openBid: {origLast.OpenBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanOpen}");
                //signalBase.Alert($"origin highAsk: {origLast.HighAsk}");
                //signalBase.Alert($"origin highBid: {origLast.HighBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanHigh}");
                //signalBase.Alert($"origin lowAsk: {origLast.LowAsk}");
                //signalBase.Alert($"origin lowBid: {origLast.LowBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanLow}");
                //signalBase.Alert($"origin closeAsk: {origLast.CloseAsk}");
                //signalBase.Alert($"origin closeBid: {origLast.CloseBid}");
                //signalBase.Alert($"origin mean: {origLast.MeanClose}");
                modLast.LowAsk   = origLast.LowAsk;
                modLast.LowBid   = origLast.LowBid;
                modLast.CloseAsk = origLast.LowAsk;
                modLast.CloseBid = origLast.LowBid;
                trigInstrData    = modMarketData;
                //signalBase.Alert($"mod openAsk: {modLast.OpenAsk}");
                //signalBase.Alert($"mod openBid: {modLast.OpenBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanOpen}");
                //signalBase.Alert($"mod highAsk: {modLast.HighAsk}");
                //signalBase.Alert($"mod highBid: {modLast.HighBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanHigh}");
                //signalBase.Alert($"mod lowAsk: {modLast.LowAsk}");
                //signalBase.Alert($"mod lowBid: {modLast.LowBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanLow}");
                //signalBase.Alert($"mod closeAsk: {modLast.CloseAsk}");
                //signalBase.Alert($"mod closeBid: {modLast.CloseBid}");
                //signalBase.Alert($"mod mean: {modLast.MeanClose}");
                var trades3 = detectSignals(modMarketData);
                trades.AddRange(trades3);

                modLast.CloseAsk = origLast.CloseAsk;
                modLast.CloseBid = origLast.CloseBid;
                modMarketData    = marketData;
                trigInstrData    = modMarketData;
                signalBase.Alert($"origin openAsk: {origLast.OpenAsk}");
                signalBase.Alert($"origin openBid: {origLast.OpenBid}");
                signalBase.Alert($"origin mean: {origLast.MeanOpen}");
                signalBase.Alert($"origin highAsk: {origLast.HighAsk}");
                signalBase.Alert($"origin highBid: {origLast.HighBid}");
                signalBase.Alert($"origin mean: {origLast.MeanHigh}");
                signalBase.Alert($"origin lowAsk: {origLast.LowAsk}");
                signalBase.Alert($"origin lowBid: {origLast.LowBid}");
                signalBase.Alert($"origin mean: {origLast.MeanLow}");
                signalBase.Alert($"origin closeAsk: {origLast.CloseAsk}");
                signalBase.Alert($"origin closeBid: {origLast.CloseBid}");
                signalBase.Alert($"origin mean: {origLast.MeanClose}");

                signalBase.Alert($"mod openAsk: {modLast.OpenAsk}");
                signalBase.Alert($"mod openBid: {modLast.OpenBid}");
                signalBase.Alert($"mod mean: {modLast.MeanOpen}");
                signalBase.Alert($"mod highAsk: {modLast.HighAsk}");
                signalBase.Alert($"mod highBid: {modLast.HighBid}");
                signalBase.Alert($"mod mean: {modLast.MeanHigh}");
                signalBase.Alert($"mod lowAsk: {modLast.LowAsk}");
                signalBase.Alert($"mod lowBid: {modLast.LowBid}");
                signalBase.Alert($"mod mean: {modLast.MeanLow}");
                signalBase.Alert($"mod closeAsk: {modLast.CloseAsk}");
                signalBase.Alert($"mod closeBid: {modLast.CloseBid}");
                signalBase.Alert($"mod mean: {modLast.MeanClose}");
                var trades4 = detectSignals(modMarketData);

                trades.AddRange(trades4);
                break;

            case PriceConstants.OLHC:
                modLast.HighAsk  = origLast.OpenAsk;
                modLast.HighBid  = origLast.OpenBid;
                modLast.LowAsk   = origLast.OpenAsk;
                modLast.LowBid   = origLast.OpenBid;
                modLast.CloseAsk = origLast.OpenAsk;
                modLast.CloseBid = origLast.OpenBid;
                trigInstrData    = modMarketData;
                trades1          = detectSignals(modMarketData);
                trades           = trades1;

                modLast.HighAsk  = origLast.LowAsk;
                modLast.HighBid  = origLast.LowBid;
                modLast.CloseAsk = origLast.LowAsk;
                modLast.CloseBid = origLast.LowBid;
                trigInstrData    = modMarketData;
                trades3          = detectSignals(modMarketData);
                trades.AddRange(trades3);

                modLast.CloseAsk = origLast.HighAsk;
                modLast.CloseBid = origLast.HighBid;
                trigInstrData    = modMarketData;
                trades2          = detectSignals(modMarketData);
                trades.AddRange(trades2);

                trigInstrData = modMarketData;
                trades4       = detectSignals(modMarketData);
                trades.AddRange(trades4);
                break;
            }

            return(trades);
        }