Exemplo n.º 1
0
        public override void Initialise(StockSerie stockSerie, StockOrder lastBuyOrder, bool supportShortSelling)
        {
            base.Initialise(stockSerie, lastBuyOrder, supportShortSelling);
             this.SRTrailStop = stockSerie.GetTrailStop(trailName);

             this.adxDecorator = stockSerie.GetDecorator("DIV(1)", ((IStockIndicator)TriggerIndicator).Name);
        }
        public static IStockViewableSeries CreateInitialisedFrom(IStockViewableSeries aViewableSerie, StockSerie stockSerie)
        {
            if (!stockSerie.Initialise()) return null;

             IStockViewableSeries viewableSerie = null;
             switch (aViewableSerie.Type)
             {
            case ViewableItemType.Indicator:
               viewableSerie = stockSerie.GetIndicator(aViewableSerie.Name);
               break;
            case ViewableItemType.Decorator:
               viewableSerie = stockSerie.GetDecorator(aViewableSerie.Name, ((IStockDecorator)aViewableSerie).DecoratedItem);
               break;
            case ViewableItemType.PaintBar:
               viewableSerie = stockSerie.GetPaintBar(aViewableSerie.Name);
               break;
            case ViewableItemType.TrailStop:
               viewableSerie = stockSerie.GetTrailStop(aViewableSerie.Name);
               break;
            case ViewableItemType.Trail:
               viewableSerie = stockSerie.GetTrail(aViewableSerie.Name, ((IStockTrail)aViewableSerie).TrailedItem);
               break;
            default:
               break;
             }
             return viewableSerie;
        }
        public static IStockViewableSeries GetViewableItem(string fullString, StockSerie stockSerie)
        {
            IStockViewableSeries viewableSerie = null;
             string[] fields = fullString.Split('|');
             int offset = 2;
             switch (fields[0].ToUpper())
             {
            case "INDICATOR":
               if (stockSerie == null)
               {
                  viewableSerie = StockIndicatorManager.CreateIndicator(fields[1]);
               }
               else
               {
                  viewableSerie = stockSerie.GetIndicator(fields[1]);
               }
               offset = 2;
               break;
            case "PAINTBAR":
               if (stockSerie == null)
               {
                  viewableSerie = StockPaintBarManager.CreatePaintBar(fields[1]);
               }
               else
               {
                  viewableSerie = stockSerie.GetPaintBar(fields[1]);
               }
               offset = 2;
               break;
            case "TRAILSTOP":
               if (stockSerie == null)
               {
                  viewableSerie = StockTrailStopManager.CreateTrailStop(fields[1]);
               }
               else
               {
                  viewableSerie = stockSerie.GetTrailStop(fields[1]);
               }
               offset = 2;
               break;
            case "DECORATOR":
               if (stockSerie == null)
               {
                  viewableSerie = StockDecoratorManager.CreateDecorator(fields[1], fields[2]);
               }
               else
               {
                  viewableSerie = stockSerie.GetDecorator(fields[1], fields[2]);
               }
               offset = 3;
               break;
            case "TRAIL":
               if (stockSerie == null)
               {
                  viewableSerie = StockTrailManager.CreateTrail(fields[1], fields[2]);
               }
               else
               {
                  viewableSerie = stockSerie.GetTrail(fields[1], fields[2]);
               }
               offset = 3;
               break;
            default:
               return null;
             }

             if (viewableSerie != null)
             {
            for (int i = 0; i < viewableSerie.SeriesCount; i++)
            {
               int index = 2 * i + offset;
               if (index < fields.Length)
               {
                  viewableSerie.SeriePens[i] = GraphCurveType.PenFromString(fields[index]);
                  viewableSerie.SerieVisibility[i] = bool.Parse(fields[index + 1]);
               }
               else
               {
                  viewableSerie.SerieVisibility[i] = true;
               }
            }
            if (fields[0].ToUpper() == "DECORATOR")
            {
               offset += viewableSerie.SeriesCount*2;
               IStockDecorator decorator = viewableSerie as IStockDecorator;
               for (int i = 0; i < decorator.EventCount; i++)
               {
                  int index = 2 * i + offset;
                  if (index < fields.Length)
                  {
                     decorator.EventPens[i] = GraphCurveType.PenFromString(fields[index]);
                     decorator.EventVisibility[i] = bool.Parse(fields[index + 1]);
                  }
                  else
                  {
                     decorator.EventVisibility[i] = true;
                  }
               }
            }
             }
             return viewableSerie;
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            CreateEventSeries(stockSerie.Count);

            IStockDecorator originalDecorator = stockSerie.GetDecorator(this.Name.Replace("WAIT", ""), this.DecoratedItem);

            this.Series[0] = originalDecorator.Series[0];
            this.Series[1] = originalDecorator.Series[1];
            this.Series[2] = originalDecorator.Series[2];

            IStockTrailStop trailIndicator = stockSerie.GetTrailStop("TRAILHL(1)");

            FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
            FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);

            int exhaustionTopIndex =0;
            int exhaustionBottomIndex = 1;
            int bearishDivergenceIndex = 2;
            int bullishDivergenceIndex = 3;

            int upTrendIndex = 0;

            bool waitExhaustionTop = false;
            bool waitExhaustionBottom = false;
            bool waitBearishDivergence = false;
            bool waitBullishDivergence = false;

            for (int i = 10; i < stockSerie.Count; i++)
            {
               if (waitExhaustionTop)
               {
                  if (!trailIndicator.Events[upTrendIndex][i])// (highSerie[i - 1] > highSerie[i])
                  {
                     waitExhaustionTop = false;
                     this.eventSeries[exhaustionTopIndex][i] = true;
                  }
               }
               else
               {
                  if (originalDecorator.Events[exhaustionTopIndex][i])
                  {
                     if (!trailIndicator.Events[upTrendIndex][i])// (highSerie[i - 1] > highSerie[i])
                     {
                        this.eventSeries[exhaustionTopIndex][i] = true;
                     }
                     else
                     {
                        waitExhaustionTop = true;
                     }
                  }
               }

               if (waitBearishDivergence)
               {
                  if (!trailIndicator.Events[upTrendIndex][i])// (highSerie[i - 1] > highSerie[i])
                  {
                     waitBearishDivergence = false;
                     this.eventSeries[bearishDivergenceIndex][i] = true;
                  }
               }
               else
               {
                  if (originalDecorator.Events[bearishDivergenceIndex][i])
                  {
                     if (!trailIndicator.Events[upTrendIndex][i])// (highSerie[i - 1] > highSerie[i])
                     {
                        this.eventSeries[bearishDivergenceIndex][i] = true;
                     }
                     else
                     {
                        waitBearishDivergence = true;
                     }
                  }
               }
               if (waitExhaustionBottom)
               {
                  if (trailIndicator.Events[upTrendIndex][i]) // (lowSerie[i - 1] < lowSerie[i])
                  {
                     waitExhaustionBottom = false;
                     this.eventSeries[exhaustionBottomIndex][i] = true;
                  }
               }
               else
               {
                  if (originalDecorator.Events[exhaustionBottomIndex][i])
                  {
                     if (trailIndicator.Events[upTrendIndex][i]) // (lowSerie[i - 1] < lowSerie[i])
                     {
                        this.eventSeries[exhaustionBottomIndex][i] = true;
                     }
                     else
                     {
                        waitExhaustionBottom = true;
                     }
                  }
               }

               if (waitBullishDivergence)
               {
                  if (trailIndicator.Events[upTrendIndex][i]) // (lowSerie[i - 1] < lowSerie[i])
                  {
                     waitBullishDivergence = false;
                     this.eventSeries[bullishDivergenceIndex][i] = true;
                  }
               }
               else
               {
                  if (originalDecorator.Events[bullishDivergenceIndex][i])
                  {
                     if (trailIndicator.Events[upTrendIndex][i]) // (lowSerie[i - 1] < lowSerie[i])
                     {
                        this.eventSeries[bullishDivergenceIndex][i] = true;
                     }
                     else
                     {
                        waitBullishDivergence = true;
                     }
                  }
               }
            }
             }
        }