Пример #1
0
                protected override void OnBarUpdate()
                {



                        if (_CurrentBar != CurrentBar)
                        {

                                if (BarDataCollection.Count > 0)
                                {
                                int lastBarIndexInCollection = BarDataCollection.Count - 1;
                                SortedList<double, QuoteDataAtPrice> LastSL =
BarDataCollection[lastBarIndexInCollection];
                                if (LastSL.Count > 0)
                                {
                                        double thePriceOfLargestSizeAtBidAndAtAsk =
GetPriceOfLargestSize(lastBarIndexInCollection,
dataType.bidAndAskSize);
                                        double theLargestSizeSinged =
GetLargestSizeSigned(lastBarIndexInCollection,
dataType.bidAndAskSize);

                                        int percentageOfBids = 0;
                                        int percentageOfAsks = 0;
                                        percentageOfBids = GetPercentageOfBids(lastBarIndexInCollection,
dataType.bidAndAskSize);
                                        percentageOfAsks = 100 - percentageOfBids;

                                        int percentageOfBidsAtTop = 0;
                                        int percentageOfAsksAtTop = 0;
                                        percentageOfBidsAtTop =
GetPercentageOfBidsAtTopOrBottom(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1], TopOrBottomEnum.Top);
                                        percentageOfAsksAtTop = 100 - percentageOfBidsAtTop;

                                        int percentageOfBidsAtBottom = 0;
                                        int percentageOfAsksAtBottom = 0;
                                        percentageOfBidsAtBottom =
GetPercentageOfBidsAtTopOrBottom(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1], TopOrBottomEnum.Bottom);
                                        percentageOfAsksAtBottom = 100 - percentageOfBidsAtBottom;

                                        int percentageOfDataAtTop = 0;
                                        int percentageOfDataAtBottom = 0;
                                        percentageOfDataAtTop =
GetPercentageOfDataAtTopHalfOfBar(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1]);
                                        percentageOfDataAtBottom = 100 - percentageOfDataAtTop;

                                        if (thePriceOfLargestSizeAtBidAndAtAsk > 0)
                                        {

                                                if (thePriceOfLargestSizeAtBidAndAtAsk > Median[1]
                                                        && (Open[1] > Median[1])
                                                        && IsTopOrBottomQuarter(Close[1], High[1], Low[1],TopOrBottomEnum.Bottom)
                                                        && Close[1] < EMA(Close,20)[1])
                                                {
                                                        //Potential short

//                                                       if (theLargestSizeSinged > 0)
//                                                      {
//                                                              BackColor = Color.MistyRose;
//                                                              PrintAlert(Time[1], "FULL SHORT");
//                                                      }
//                                                      else
//                                                      {
//                                                              PrintAlert(Time[1], "PARTIAL SHORT");
//                                                              BackColor = Color.LightGray;
//                                                      }

                                                        PotentialTrade newTrade = new PotentialTrade();
                                                        newTrade.SignalBar = lastBarIndexInCollection;
                                                        newTrade.SignalPrice = thePriceOfLargestSizeAtBidAndAtAsk;
                                                        newTrade.theTradeDirection = TradeDirection.Short;
                                                        newTrade.StopPrice = High[1] + TickSize;
                                                        newTrade.theTradeState = TradeState.Closed;
                                                        newTrade.ProfitPrice =  newTrade.SignalPrice -
(Math.Abs(newTrade.SignalPrice - newTrade.StopPrice) * 2);
                                                        PotentialTradesList.Add (newTrade);


//                                                       Print ("SHORT - Close[1] = " + Close[1]
//                                                      + " theLargestSizeAtBidAndAtAsk = " + thePriceOfLargestSizeAtBidAndAtAsk
//                                                      + " High = " +  High[1]
//                                                      + " Low = " +   Low[1]
//                                                      + " Time = " +   Time[1]);
                                                }
                                                else if  (thePriceOfLargestSizeAtBidAndAtAsk  < Median[1]
                                                        && (Open[1] < Median[1])
                                                        && IsTopOrBottomQuarter(Close[1], High[1], Low[1], TopOrBottomEnum.Top)
                                                        &&  Close[1] > EMA(Close,20)[1])
                                                {
                                                 //ALL - Close[1] = 139.77
                                                        //theLargestSizeAtBidAndAtAsk = 139.65
                                                        //High = 139.77
                                                        //Low = 139.59
                                                        //Close = 139.77
                                                        //Median = 139.68
                                                        //EMA20 = 139.656132929072
                                                        //Time = 4/4/2012 2:35:00 PM


//                                                       if (theLargestSizeSinged < 0)
//                                                      {
//                                                              BackColor = Color.LightCyan;
//                                                              PrintAlert(Time[1], "FULL LONG");
//                                                      }
//                                                      else
//                                                      {
//                                                              BackColor = Color.LightGray;
//                                                              PrintAlert(Time[1], "PARTIAL LONG");
//                                                      }

                                                        PotentialTrade newTrade = new PotentialTrade();
                                                        newTrade.SignalBar = lastBarIndexInCollection;
                                                        newTrade.SignalPrice = thePriceOfLargestSizeAtBidAndAtAsk;
                                                        newTrade.theTradeDirection = TradeDirection.Long;
                                                        newTrade.StopPrice = Low[1] - TickSize;
                                                        newTrade.theTradeState = TradeState.Closed;
                                                        newTrade.ProfitPrice = newTrade.SignalPrice +
(Math.Abs(newTrade.SignalPrice - newTrade.StopPrice) * 2);
                                                        PotentialTradesList.Add (newTrade);

                                                }

                                                PrintAlert(Time[1], "percentageOfAsksAtTop = " +
percentageOfAsksAtTop + "  percentageOfBidsAtTop = " +
percentageOfBidsAtTop);
                                                PrintAlert(Time[1], "percentageOfAsksAtBottom = " +
percentageOfDataAtBottom + "  percentageOfBidsAtBottom = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "percentageOfDataAtBottom = " +
percentageOfDataAtBottom + "  percentageOfDataAtTop = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "percentageOfBids = " + percentageOfBids + "
 percentageOfAsks = " +  percentageOfAsks);
                                                PrintAlert(Time[1], "percentageOfDataAtBottom = " +
percentageOfDataAtBottom + "  percentageOfDataAtTop = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "thePriceOfLargestSizeAtBidAndAtAsk = " +
thePriceOfLargestSizeAtBidAndAtAsk);
                                                PrintAlert(Time[1], "IsBarAerodynamic Bullish = " +
IsBarAerodynamic(1, MarketDirectionEnum.Bullish,
DirectionalFilterEnum.VeryStrong));
                                                PrintAlert(Time[1], "IsBarAerodynamic Bearish = " +
IsBarAerodynamic(1, MarketDirectionEnum.Bearish,
DirectionalFilterEnum.VeryStrong));


//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfAsksAtTop = 42
percentageOfBidsAtTop = 58
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfAsksAtBottom = 13
percentageOfBidsAtBottom = 87
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfDataAtBottom = 13
percentageOfDataAtTop = 87
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfBids = 59
percentageOfAsks = 41


                                                // && IsTopOrBottomQuarter(Close[1], High[1], Low[1], TopOrBottomEnum.Top)
                                                ///BULL
                                                if (percentageOfBids > percentageOfAsks
                                                        && (percentageOfDataAtTop) < percentageOfDataAtBottom
                                                        && thePriceOfLargestSizeAtBidAndAtAsk  < (Open[1] + Close[1]) / 2
                                                        && IsBarAerodynamic(1, MarketDirectionEnum.Bullish,
DirectionalFilterEnum.VeryStrong)
                                                        && Close[1] > EMA(Close,20)[1]
                                                        && Math.Abs(Open[1] - Close[1]) > EMA(_BodySize, 3)[1])
                                                {
                                                        //Bull breakout
                                                        DrawDiamond("Long" + CurrentBar, true, 1, Low[1] - (TickSize *
4), Color.LightCyan);
                                                        PrintAlert(Time[1],"LONG");
                                                }
                                                //BEAR
                                                else if (percentageOfBids < percentageOfAsks
                                                        && (percentageOfDataAtBottom) < percentageOfDataAtTop
                                                        && thePriceOfLargestSizeAtBidAndAtAsk >  (Open[1] + Close[1]) / 2
                                                        && IsBarAerodynamic(1, MarketDirectionEnum.Bearish,
DirectionalFilterEnum.VeryStrong)
                                                        && Close[1] < EMA(Close,20)[1]
                                                        && Math.Abs(Open[1] - Close[1]) > EMA(_BodySize, 3)[1])
                                                {
                                                        //Bear breakout
                                                        DrawDiamond("Shprt" + CurrentBar, true, 1, High[1] + (TickSize
* 4), Color.MistyRose);
                                                        PrintAlert(Time[1],"SHORT");
                                                }
                                        }
                                }
                                }
                                _CurrentBar = CurrentBar;
                                BarDataCollection.Add(CurrentBar, new SortedList<double,
QuoteDataAtPrice>());
                                _BodySize.Set (Math.Abs(Open[1] - Close[1]));
                        }
                }
                protected override void OnBarUpdate()
                {



                        if (_CurrentBar != CurrentBar)
                        {

                                if (BarDataCollection.Count > 0)
                                {
                                int lastBarIndexInCollection = BarDataCollection.Count - 1;
                                SortedList<double, QuoteDataAtPrice> LastSL =
BarDataCollection[lastBarIndexInCollection];
                                if (LastSL.Count > 0)
                                {
                                        double thePriceOfLargestSizeAtBidAndAtAsk =
GetPriceOfLargestSize(lastBarIndexInCollection,
dataType.bidAndAskSize);
                                        double theLargestSizeSinged =
GetLargestSizeSigned(lastBarIndexInCollection,
dataType.bidAndAskSize);

                                        int percentageOfBids = 0;
                                        int percentageOfAsks = 0;
                                        percentageOfBids = GetPercentageOfBids(lastBarIndexInCollection,
dataType.bidAndAskSize);
                                        percentageOfAsks = 100 - percentageOfBids;

                                        int percentageOfBidsAtTop = 0;
                                        int percentageOfAsksAtTop = 0;
                                        percentageOfBidsAtTop =
GetPercentageOfBidsAtTopOrBottom(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1], TopOrBottomEnum.Top);
                                        percentageOfAsksAtTop = 100 - percentageOfBidsAtTop;

                                        int percentageOfBidsAtBottom = 0;
                                        int percentageOfAsksAtBottom = 0;
                                        percentageOfBidsAtBottom =
GetPercentageOfBidsAtTopOrBottom(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1], TopOrBottomEnum.Bottom);
                                        percentageOfAsksAtBottom = 100 - percentageOfBidsAtBottom;

                                        int percentageOfDataAtTop = 0;
                                        int percentageOfDataAtBottom = 0;
                                        percentageOfDataAtTop =
GetPercentageOfDataAtTopHalfOfBar(lastBarIndexInCollection,
dataType.bidAndAskSize, Median[1]);
                                        percentageOfDataAtBottom = 100 - percentageOfDataAtTop;

                                        if (thePriceOfLargestSizeAtBidAndAtAsk > 0)
                                        {

                                                if (thePriceOfLargestSizeAtBidAndAtAsk > Median[1]
                                                        && (Open[1] > Median[1])
                                                        && IsTopOrBottomQuarter(Close[1], High[1], Low[1],TopOrBottomEnum.Bottom)
                                                        && Close[1] < EMA(Close,20)[1])
                                                {
                                                        //Potential short

//                                                       if (theLargestSizeSinged > 0)
//                                                      {
//                                                              BackColor = Color.MistyRose;
//                                                              PrintAlert(Time[1], "FULL SHORT");
//                                                      }
//                                                      else
//                                                      {
//                                                              PrintAlert(Time[1], "PARTIAL SHORT");
//                                                              BackColor = Color.LightGray;
//                                                      }

                                                        PotentialTrade newTrade = new PotentialTrade();
                                                        newTrade.SignalBar = lastBarIndexInCollection;
                                                        newTrade.SignalPrice = thePriceOfLargestSizeAtBidAndAtAsk;
                                                        newTrade.theTradeDirection = TradeDirection.Short;
                                                        newTrade.StopPrice = High[1] + TickSize;
                                                        newTrade.theTradeState = TradeState.Closed;
                                                        newTrade.ProfitPrice =  newTrade.SignalPrice -
(Math.Abs(newTrade.SignalPrice - newTrade.StopPrice) * 2);
                                                        PotentialTradesList.Add (newTrade);


//                                                       Print ("SHORT - Close[1] = " + Close[1]
//                                                      + " theLargestSizeAtBidAndAtAsk = " + thePriceOfLargestSizeAtBidAndAtAsk
//                                                      + " High = " +  High[1]
//                                                      + " Low = " +   Low[1]
//                                                      + " Time = " +   Time[1]);
                                                }
                                                else if  (thePriceOfLargestSizeAtBidAndAtAsk  < Median[1]
                                                        && (Open[1] < Median[1])
                                                        && IsTopOrBottomQuarter(Close[1], High[1], Low[1], TopOrBottomEnum.Top)
                                                        &&  Close[1] > EMA(Close,20)[1])
                                                {
                                                 //ALL - Close[1] = 139.77
                                                        //theLargestSizeAtBidAndAtAsk = 139.65
                                                        //High = 139.77
                                                        //Low = 139.59
                                                        //Close = 139.77
                                                        //Median = 139.68
                                                        //EMA20 = 139.656132929072
                                                        //Time = 4/4/2012 2:35:00 PM


//                                                       if (theLargestSizeSinged < 0)
//                                                      {
//                                                              BackColor = Color.LightCyan;
//                                                              PrintAlert(Time[1], "FULL LONG");
//                                                      }
//                                                      else
//                                                      {
//                                                              BackColor = Color.LightGray;
//                                                              PrintAlert(Time[1], "PARTIAL LONG");
//                                                      }

                                                        PotentialTrade newTrade = new PotentialTrade();
                                                        newTrade.SignalBar = lastBarIndexInCollection;
                                                        newTrade.SignalPrice = thePriceOfLargestSizeAtBidAndAtAsk;
                                                        newTrade.theTradeDirection = TradeDirection.Long;
                                                        newTrade.StopPrice = Low[1] - TickSize;
                                                        newTrade.theTradeState = TradeState.Closed;
                                                        newTrade.ProfitPrice = newTrade.SignalPrice +
(Math.Abs(newTrade.SignalPrice - newTrade.StopPrice) * 2);
                                                        PotentialTradesList.Add (newTrade);

                                                }

                                                PrintAlert(Time[1], "percentageOfAsksAtTop = " +
percentageOfAsksAtTop + "  percentageOfBidsAtTop = " +
percentageOfBidsAtTop);
                                                PrintAlert(Time[1], "percentageOfAsksAtBottom = " +
percentageOfDataAtBottom + "  percentageOfBidsAtBottom = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "percentageOfDataAtBottom = " +
percentageOfDataAtBottom + "  percentageOfDataAtTop = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "percentageOfBids = " + percentageOfBids + "
 percentageOfAsks = " +  percentageOfAsks);
                                                PrintAlert(Time[1], "percentageOfDataAtBottom = " +
percentageOfDataAtBottom + "  percentageOfDataAtTop = " +
percentageOfDataAtTop);
                                                PrintAlert(Time[1], "thePriceOfLargestSizeAtBidAndAtAsk = " +
thePriceOfLargestSizeAtBidAndAtAsk);
                                                PrintAlert(Time[1], "IsBarAerodynamic Bullish = " +
IsBarAerodynamic(1, MarketDirectionEnum.Bullish,
DirectionalFilterEnum.VeryStrong));
                                                PrintAlert(Time[1], "IsBarAerodynamic Bearish = " +
IsBarAerodynamic(1, MarketDirectionEnum.Bearish,
DirectionalFilterEnum.VeryStrong));


//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfAsksAtTop = 42
percentageOfBidsAtTop = 58
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfAsksAtBottom = 13
percentageOfBidsAtBottom = 87
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfDataAtBottom = 13
percentageOfDataAtTop = 87
//04/24/2012 01:55:00 - QQQ (5 min):  percentageOfBids = 59
percentageOfAsks = 41


                                                // && IsTopOrBottomQuarter(Close[1], High[1], Low[1], TopOrBottomEnum.Top)
                                                ///BULL
                                                if (percentageOfBids > percentageOfAsks
                                                        && (percentageOfDataAtTop) < percentageOfDataAtBottom
                                                        && thePriceOfLargestSizeAtBidAndAtAsk  < (Open[1] + Close[1]) / 2
                                                        && IsBarAerodynamic(1, MarketDirectionEnum.Bullish,
DirectionalFilterEnum.VeryStrong)
                                                        && Close[1] > EMA(Close,20)[1]
                                                        && Math.Abs(Open[1] - Close[1]) > EMA(_BodySize, 3)[1])
                                                {
                                                        //Bull breakout
                                                        DrawDiamond("Long" + CurrentBar, true, 1, Low[1] - (TickSize *
4), Color.LightCyan);
                                                        PrintAlert(Time[1],"LONG");
                                                }
                                                //BEAR
                                                else if (percentageOfBids < percentageOfAsks
                                                        && (percentageOfDataAtBottom) < percentageOfDataAtTop
                                                        && thePriceOfLargestSizeAtBidAndAtAsk >  (Open[1] + Close[1]) / 2
                                                        && IsBarAerodynamic(1, MarketDirectionEnum.Bearish,
DirectionalFilterEnum.VeryStrong)
                                                        && Close[1] < EMA(Close,20)[1]
                                                        && Math.Abs(Open[1] - Close[1]) > EMA(_BodySize, 3)[1])
                                                {
                                                        //Bear breakout
                                                        DrawDiamond("Shprt" + CurrentBar, true, 1, High[1] + (TickSize
* 4), Color.MistyRose);
                                                        PrintAlert(Time[1],"SHORT");
                                                }
                                        }
                                }
                                }
                                _CurrentBar = CurrentBar;
                                BarDataCollection.Add(CurrentBar, new SortedList<double,
QuoteDataAtPrice>());
                                _BodySize.Set (Math.Abs(Open[1] - Close[1]));
                        }