public override void ApplyTo(StockSerie stockSerie)
        {
            // Calculate Bands
             int period = (int)this.parameters[0];
             FloatSerie ema = stockSerie.GetIndicator("EMA(" + period + ")").Series[0];
             FloatSerie atr = stockSerie.GetIndicator("ATR(" + period + ")").Series[0];

             float upCoef = (float)this.parameters[1];
             float downCoef = (float)this.parameters[2];

             FloatSerie upperKeltnerBand = ema + atr * upCoef;
             this.series[0] = upperKeltnerBand;
             this.Series[0].Name = this.SerieNames[0];

             FloatSerie lowerKeltnerBand = ema + atr * downCoef;
             this.series[1] = lowerKeltnerBand;
             this.Series[1].Name = this.SerieNames[1];

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

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

             for (int i = 1; i < upperKeltnerBand.Count; i++)
             {
            this.eventSeries[0][i] = closeSerie[i] > upperKeltnerBand[i];
            this.eventSeries[1][i] = closeSerie[i] < lowerKeltnerBand[i];
            this.eventSeries[2][i] = closeSerie[i] >= lowerKeltnerBand[i] && closeSerie[i] <= upperKeltnerBand[i];
             }
        }
 public StockAlertDef(StockSerie.StockBarDuration barDuration, string indicatorType, string indicatorName, string eventName)
 {
     this.BarDuration = barDuration;
      this.IndicatorType = indicatorType;
      this.IndicatorName = indicatorName;
      this.EventName = eventName;
 }
        public override void ApplyTo(StockSerie stockSerie)
        {
            // Calculate Bands
             int period = (int)this.parameters[0];
             FloatSerie ema = stockSerie.GetIndicator("EMA(" + period + ")").Series[0];
             FloatSerie highEma = stockSerie.GetSerie(StockDataType.HIGH).CalculateEMA(period);
             FloatSerie lowEma = stockSerie.GetSerie(StockDataType.LOW).CalculateEMA(period);
             FloatSerie diff = highEma - lowEma;

             FloatSerie atr = stockSerie.GetIndicator("ATR(" + period + ")").Series[0];

             float upCoef = (float)this.parameters[1];
             float downCoef = (float)this.parameters[2];

             FloatSerie upperMYBAND = ema + diff * upCoef;
             this.series[0] = upperMYBAND;
             this.Series[0].Name = this.SerieNames[0];

             FloatSerie lowerMYBAND = ema + diff * downCoef;
             this.series[1] = lowerMYBAND;
             this.Series[1].Name = this.SerieNames[1];

             this.series[2] = ema;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

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

             bool waitingForBearSignal = false;
             bool waitingForBullSignal = false;

             for (int i = 1; i < upperMYBAND.Count; i++)
             {
            if (waitingForBearSignal && highSerie[i - 1] >= highSerie[i] && closeSerie[i - 1] >= closeSerie[i])
            {
               // BearishSignal
               this.eventSeries[3][i] = true;
               waitingForBearSignal = false;
            }
            if (highSerie[i] >= upperMYBAND[i])
            {
               waitingForBearSignal = true;
               this.eventSeries[0][i] = true;
            }
            if (waitingForBullSignal && lowSerie[i - 1] <= lowSerie[i] && closeSerie[i - 1] <= closeSerie[i])
            {
               // BullishSignal
               this.eventSeries[2][i] = true;
               waitingForBullSignal = false;
            }
            if (lowSerie[i] <= lowerMYBAND[i])
            {
               waitingForBullSignal = true;
               this.eventSeries[1][i] = lowSerie[i] <= lowerMYBAND[i];
            }
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie longStopSerie;
             FloatSerie shortStopSerie;
             FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
             FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);

             float indicatorMax = (float)this.Parameters[2];
             float indicatorCenter = (float)this.Parameters[3];
             float indicatorWeight = (float)this.Parameters[4];

             stockSerie.CalculateVarTrailStop((int)this.Parameters[0], ((string)this.Parameters[1]).Replace('_', ','), indicatorMax, indicatorCenter, indicatorWeight, out longStopSerie, out shortStopSerie);
             this.Series[0] = longStopSerie;
             this.Series[1] = shortStopSerie;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

             for (int i = (int)this.Parameters[0]; i < stockSerie.Count; i++)
             {
            this.Events[0][i] = !float.IsNaN(longStopSerie[i]);
            this.Events[1][i] = !float.IsNaN(shortStopSerie[i]);
            this.Events[2][i] = float.IsNaN(longStopSerie[i - 1]) && !float.IsNaN(longStopSerie[i]);
            this.Events[3][i] = float.IsNaN(shortStopSerie[i - 1]) && !float.IsNaN(shortStopSerie[i]);
            this.Events[4][i] = !float.IsNaN(longStopSerie[i - 1]) && !float.IsNaN(longStopSerie[i]) && longStopSerie[i - 1] < longStopSerie[i];
            this.Events[5][i] = !float.IsNaN(shortStopSerie[i - 1]) && !float.IsNaN(shortStopSerie[i]) && shortStopSerie[i - 1] > shortStopSerie[i];
            this.Events[6][i] = !float.IsNaN(longStopSerie[i]) && !float.IsNaN(longStopSerie[i - 1]) && lowSerie[i] > longStopSerie[i] && lowSerie[i - 1] <= longStopSerie[i - 1];
            this.Events[7][i] = !float.IsNaN(shortStopSerie[i]) && !float.IsNaN(shortStopSerie[i - 1]) && highSerie[i] < shortStopSerie[i] && highSerie[i - 1] >= shortStopSerie[i - 1];
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            int period = (int)this.parameters[0];

             IStockIndicator momentum = stockSerie.GetIndicator("MOMENTUM(" + period + ",1,10)");
             FloatSerie momentumSerie = momentum.Series[0];

             FloatSerie atrSerie = stockSerie.GetSerie(StockDataType.ATR);
             FloatSerie distSerie = momentumSerie.Div(atrSerie.Cumul(period));

             //cciSerie = cciSerie.CalculateSigmoid(100f, 0.02f).CalculateEMA((int)Math.Sqrt();
             //FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE);
             //for (int i = 10; i < cciSerie.Count; i++)
             //{
             //    if (cciSerie[i] > overbought && cciSerie[i] <= cciSerie[i - 1] && closeSerie[i] >= closeSerie[i-1])
             //    {
             //        cciSerie[i] = cciSerie[i - 1] + (100 - cciSerie[i - 1]) / 4f;
             //    }
             //    else if (cciSerie[i] < oversold && cciSerie[i] >= cciSerie[i - 1] && closeSerie[i] <= closeSerie[i-1])
             //    {
             //        cciSerie[i] = cciSerie[i - 1] *0.75f;
             //    }
             //}

             this.series[0] = distSerie;
             this.series[0].Name = this.Name;
        }
 public override void Initialise(StockSerie stockSerie, StockOrder lastBuyOrder, bool supportShortSelling)
 {
     base.Initialise(stockSerie, lastBuyOrder, supportShortSelling);
      this.oscSerie = null;
      this.trailStop = StockTrailStopManager.CreateTrailStop("TRAILHL(3)");
      this.trailStop.ApplyTo(stockSerie);
 }
        public StockStrategyScannerDlg(StockDictionary stockDictionary, StockSerie.Groups stockGroup, StockSerie.StockBarDuration barDuration, string strategyName)
        {
            InitializeComponent();

             this.stockDictionary = stockDictionary;
             this.barDuration = barDuration;

             // Initialise group combo box
             groupComboBox.Items.AddRange(this.stockDictionary.GetValidGroupNames().ToArray());
             groupComboBox.SelectedItem = stockGroup.ToString();
             groupComboBox.SelectedValueChanged += new EventHandler(groupComboBox_SelectedValueChanged);

             // Initialise Strategy Combo box
             this.strategyComboBox.Items.Clear();
             List<string> strategyList = StrategyManager.GetStrategyList();
             foreach (string name in strategyList)
             {
            this.strategyComboBox.Items.Add(name);
             }
             this.strategyComboBox.SelectedItem = strategyName;
             this.strategyComboBox.SelectedValueChanged += new EventHandler(strategyComboBox_SelectedValueChanged);

             periodComboBox.SelectedIndex = 0;

             OnBarDurationChanged(barDuration);
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie longStopSerie;
             FloatSerie shortStopSerie;

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

             IStockIndicator bbIndicator = stockSerie.GetIndicator(this.Name.Replace("TRAIL", ""));
             stockSerie.CalculateBBTrailStop(bbIndicator.Series[1], bbIndicator.Series[0], out longStopSerie, out shortStopSerie);
             this.Series[0] = longStopSerie;
             this.Series[1] = shortStopSerie;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

             for (int i = 5; i < stockSerie.Count; i++)
             {
            bool upTrend;
            this.Events[0][i] = upTrend = float.IsNaN(shortStopSerie[i]);
            this.Events[1][i] = !upTrend;
            this.Events[2][i] = upTrend && !this.Events[0][i - 1];
            this.Events[3][i] = !upTrend && !this.Events[1][i - 1];
            this.Events[4][i] = upTrend && this.Events[0][i - 1] && lowSerie[i - 1] <= longStopSerie[i - 1] && lowSerie[i] > longStopSerie[i];
            this.Events[5][i] = !upTrend && this.Events[1][i - 1] && HighSerie[i - 1] >= shortStopSerie[i - 1] && HighSerie[i] < shortStopSerie[i]; ;
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie longStopSerie;
             FloatSerie shortStopSerie;
             FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
             FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);

             stockSerie.CalculateHLAVGTrailStop((int)this.Parameters[0], (int)this.Parameters[1], out longStopSerie, out shortStopSerie);
             this.Series[0] = longStopSerie;
             this.Series[1] = shortStopSerie;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

             for (int i = 5; i < stockSerie.Count; i++)
             {
            this.Events[0][i] = !float.IsNaN(longStopSerie[i]);
            this.Events[1][i] = !float.IsNaN(shortStopSerie[i]);
            this.Events[2][i] = float.IsNaN(longStopSerie[i - 1]) && !float.IsNaN(longStopSerie[i]);
            this.Events[3][i] = float.IsNaN(shortStopSerie[i - 1]) && !float.IsNaN(shortStopSerie[i]);
            this.Events[4][i] = !float.IsNaN(longStopSerie[i - 1]) && !float.IsNaN(longStopSerie[i]) && longStopSerie[i - 1] < longStopSerie[i];
            this.Events[5][i] = !float.IsNaN(shortStopSerie[i - 1]) && !float.IsNaN(shortStopSerie[i]) && shortStopSerie[i - 1] > shortStopSerie[i];
            this.Events[6][i] = !float.IsNaN(longStopSerie[i]) && !float.IsNaN(longStopSerie[i - 1]) && lowSerie[i] > longStopSerie[i] && lowSerie[i - 1] <= longStopSerie[i - 1];
            this.Events[7][i] = !float.IsNaN(shortStopSerie[i]) && !float.IsNaN(shortStopSerie[i - 1]) && highSerie[i] < shortStopSerie[i] && highSerie[i - 1] >= shortStopSerie[i - 1];
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie lowEMASerie = stockSerie.GetIndicator(this.SerieNames[0]).Series[0];
            FloatSerie highEMASerie = stockSerie.GetIndicator(this.SerieNames[1]).Series[0];

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

            this.Series[0] = lowEMASerie;
            this.Series[1] = highEMASerie;

            // Detecting events
            this.CreateEventSeries(stockSerie.Count);

            for (int i = (int)this.parameters[0]; i < stockSerie.Count; i++)
            {
                if (lowSerie[i] > highEMASerie[i])
                {
                    this.Events[0][i] = true;
                    if (!this.Events[0][i-1])
                        this.Events[2][i] = true;
                }
                else if (highSerie[i] < lowEMASerie[i])
                {
                    this.Events[1][i] = true;
                    if (!this.Events[1][i - 1])
                        this.Events[3][i] = true;
                }
                else
                {
                    this.Events[4][i] = true;
                }
            }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE);
             FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
             FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);
             int fastPeriod = (int)this.parameters[0];
             int slowPeriod = (int)this.parameters[1];
             FloatSerie maSerie = closeSerie.CalculateKEMA(fastPeriod, slowPeriod);
             this.series[0] = maSerie;
             this.series[0].Name = this.Name;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);
             for (int i = 2; i < maSerie.Count; i++)
             {
            this.eventSeries[0][i] = (maSerie[i - 2] > maSerie[i - 1] && maSerie[i - 1] < maSerie[i]);
            this.eventSeries[1][i] = (maSerie[i - 2] < maSerie[i - 1] && maSerie[i - 1] > maSerie[i]);
            this.eventSeries[2][i] = closeSerie[i-1] < maSerie[i-1] && closeSerie[i] > maSerie[i];
            this.eventSeries[3][i] = closeSerie[i-1] > maSerie[i-1] && closeSerie[i] < maSerie[i];
            this.eventSeries[4][i] = lowSerie[i] > maSerie[i] && lowSerie[i - 1] < maSerie[i - 1];
            this.eventSeries[5][i] = highSerie[i] < maSerie[i] && highSerie[i - 1] > maSerie[i - 1];
            this.eventSeries[6][i] = lowSerie[i] > maSerie[i] && closeSerie[i - 1] < closeSerie[i];
            this.eventSeries[7][i] = highSerie[i] < maSerie[i] && closeSerie[i - 1] > closeSerie[i];
             }
        }
        public void AddStock(int index, StockSerie stockSerie)
        {
            StockDailyValue dailyValue = stockSerie.ValueArray[index];
             StockDailyValue futureValue = null;
             float dailyVariationClose = 0.0f;
             float dailyVariationLow = 0.0f;
             float dailyVariationHigh = 0.0f;

             for (int i = 0; i < NB_VALUES; i++)
             {
            futureValue = stockSerie.Values.ElementAt(index + i + 1);

            dailyVariationClose = (futureValue.CLOSE - dailyValue.CLOSE) / dailyValue.CLOSE;
            dailyVariationLow = (futureValue.LOW - dailyValue.CLOSE) / dailyValue.CLOSE;
            dailyVariationHigh = (futureValue.HIGH - dailyValue.CLOSE) / dailyValue.CLOSE;

            variationClose[i] += dailyVariationClose;
            variationLow[i] += dailyVariationLow;
            variationHigh[i] += dailyVariationHigh;

            minVariationClose = Math.Min(minVariationClose, dailyVariationClose);
            minVariationLow = Math.Min(minVariationLow, dailyVariationLow);
            minVariationHigh = Math.Min(minVariationHigh, dailyVariationHigh);

            maxVariationClose = Math.Max(minVariationClose, dailyVariationClose);
            maxVariationLow = Math.Max(minVariationLow, dailyVariationLow);
            maxVariationHigh = Math.Max(minVariationHigh, dailyVariationHigh);
             }
             nbVariationValue++;
        }
        public override bool LoadData(string rootFolder, StockSerie stockSerie)
        {
            string[] row = stockSerie.StockName.Split('/');
             string serieName = row[0] + "/" + row[1];
             if (!StockDictionary.StockDictionarySingleton.ContainsKey(row[0]))
             {
            throw new Exception("Stock " + row[0] + " Not found, cannot calculate ratio");
             }
             StockSerie s1 = StockDictionary.StockDictionarySingleton[row[0]];
             if (!StockDictionary.StockDictionarySingleton.ContainsKey(row[1]))
             {
            throw new Exception("Stock " + row[1] + " Not found, cannot calculate ratio");
             }
             StockSerie s2 = StockDictionary.StockDictionarySingleton[row[1]];

             // Generate ratio serie
             StockSerie s3 = s1.GenerateRelativeStrenthStockSerie(s2);

             // Copy Into current serie
             stockSerie.IsInitialised = false;
             foreach (var pair in s3)
             {
            stockSerie.Add(pair.Key, pair.Value);
             }
             return true;
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie fastSerie = stockSerie.GetIndicator(this.SerieNames[0]).Series[0].ShiftForward((int)this.parameters[3]);
            FloatSerie mediumSerie = stockSerie.GetIndicator(this.SerieNames[1]).Series[0].ShiftForward((int)this.parameters[4]);
            FloatSerie slowSerie = stockSerie.GetIndicator(this.SerieNames[2]).Series[0].ShiftForward((int)this.parameters[5]);

            this.Series[0] = fastSerie;
            this.Series[1] = mediumSerie;
            this.Series[2] = slowSerie;

            // Detecting events
            this.CreateEventSeries(stockSerie.Count);

            for (int i = 2; i < stockSerie.Count; i++)
            {
                if (fastSerie[i] > mediumSerie[i] && mediumSerie[i] > slowSerie[i])
                {
                    this.Events[0][i] = true;
                }
                else if (fastSerie[i] < mediumSerie[i] && mediumSerie[i] < slowSerie[i])
                {
                    this.Events[1][i] = true;
                }
            }
        }
 public void Initialise(StockSerie serie)
 {
     this.stockSerie = serie;
     this.lowSerie = stockSerie.GetSerie(StockDataType.LOW);
     this.highSerie = stockSerie.GetSerie(StockDataType.HIGH);
     this.closeSerie = stockSerie.GetSerie(StockDataType.CLOSE);
 }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie emaSerie = stockSerie.GetSerie(StockDataType.CLOSE).CalculateEMA((int)this.Parameters[0]);
             FloatSerie indexSerie = new FloatSerie(stockSerie.Count);

             for (int i = 1; i < stockSerie.Count; i++)
             {
            int count = 0;
            for (int j = i - 1; j >= 0; j--)
            {
               if (emaSerie[i] > emaSerie[j])
               {
                  count++;
               }
               else
               {
                  break;
               }
            }
            indexSerie[i] = count;
             }

             this.series[0] = indexSerie;
             this.Series[0].Name = this.Name;
        }
        public override bool DownloadIntradayData(string rootFolder, StockSerie stockSerie)
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
             {
            NotifyProgress("Downloading intraday for " + stockSerie.StockName);

            string fileName = rootFolder + INTRADAY_FOLDER + "\\" + stockSerie.ShortName.Replace(':', '_') + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + ".txt";

            if (File.Exists(fileName))
            {
               if (File.GetLastWriteTime(fileName) > DateTime.Now.AddMinutes(-2))
                  return false;
            }
            using (WebClient wc = new WebClient())
            {
               wc.Proxy.Credentials = CredentialCache.DefaultCredentials;

               string url;

               string isin = stockSerie.ISIN;
               string market = "CBFR";

               url = "http://www5.warrants.commerzbank.com/services/RetailMobile.svc/v1_0_3/charthistory?isin={isin}&mkt={market}&property=Bid&period=5&dayshistory=10&includebarprice=5";
               url = url.Replace("{isin}", isin);
               url = url.Replace("{market}", market);

               wc.DownloadFile(url, fileName);
               stockSerie.IsInitialised = false;
            }
             }
             return true;
        }
 public CommentReportDlg(StockDictionary stockDictionary, GraphCloseControl graphCloseControl, StockSerie.Groups group)
 {
     InitializeComponent();
      this.stockDictionary = stockDictionary;
      this.graphCloseControl = graphCloseControl;
      this.stockGroup = group;
 }
Example #19
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 override bool LoadData(string rootFolder, StockSerie stockSerie)
 {
     bool res = false;
      string fileName = rootFolder + HARPEX_FILENAME;
      res = this.ParseHarpex(stockSerie, fileName);
      return res;
 }
 public static IStockStrategy CreateStrategy(string name, StockSerie stockSerie, StockOrder lastBuyOrder, bool supportShortSelling)
 {
     IStockStrategy strategy = null;
      try
      {
     if (name.StartsWith("@"))
        return CreateFilteredStrategy(name, stockSerie, lastBuyOrder, supportShortSelling);
     if (strategyList == null)
     {
        GetStrategyList();
     }
     if (strategyList.Contains(name))
     {
        StrategyManager sm = new StrategyManager();
        strategy =
                    (IStockStrategy)
                        sm.GetType().Assembly.CreateInstance("StockAnalyzer.StockStrategyClasses." + name);
        strategy.Initialise(stockSerie, lastBuyOrder, supportShortSelling);
     }
      }
      catch (Exception ex)
      {
     throw new StockAnalyzerException("Failed to create strategy " + name, ex);
      }
      return strategy;
 }
        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 override void ApplyTo(StockSerie stockSerie)
        {
            this.CreateEventSeries(stockSerie.Count);

             FloatSerie closeSerie = stockSerie.GetSerie(StockDataType.CLOSE).CalculateEMA((int)this.parameters[1]);
             FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
             FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);
             FloatSerie hlSerie= new FloatSerie(stockSerie.Count, this.SerieNames[0]);
             this.Series[0] = hlSerie;

             int period = (int)this.parameters[0];

             float min, max;
             for (int i = 0; i < period; i++)
             {
            min = lowSerie.GetMin(0, i);
            max = highSerie.GetMax(0, i);
            hlSerie[i] = (min + max)/2f;
             }
             for (int i = period; i < stockSerie.Count; i++)
             {
            min = lowSerie.GetMin(i-period, i);
            max = highSerie.GetMax(i - period, i);
            hlSerie[i] = (min + max)/2f;
             }

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);
             for (int i = 2; i < hlSerie.Count; i++)
             {
            this.eventSeries[0][i] = (hlSerie[i - 2] > hlSerie[i - 1] && hlSerie[i - 1] < hlSerie[i]);
            this.eventSeries[1][i] = (hlSerie[i - 2] < hlSerie[i - 1] && hlSerie[i - 1] > hlSerie[i]);
            this.eventSeries[2][i] = closeSerie[i - 1] < hlSerie[i - 1] && closeSerie[i] > hlSerie[i];
            this.eventSeries[3][i] = closeSerie[i - 1] > hlSerie[i - 1] && closeSerie[i] < hlSerie[i];
            this.eventSeries[4][i] = lowSerie[i] > hlSerie[i] && lowSerie[i - 1] < hlSerie[i - 1];
            this.eventSeries[5][i] = highSerie[i] < hlSerie[i] && highSerie[i - 1] > hlSerie[i - 1];
            this.eventSeries[6][i] = lowSerie[i] > hlSerie[i] && closeSerie[i - 1] < closeSerie[i];
            this.eventSeries[7][i] = highSerie[i] < hlSerie[i] && closeSerie[i - 1] > closeSerie[i];
            if (this.eventSeries[8][i - 1])
            {
               // Check if BullRun Persists
               this.eventSeries[8][i] = !this.eventSeries[5][i];
            }
            else
            {
               // Check if BullRun Starts
               this.eventSeries[8][i] = this.eventSeries[4][i];
            }
            if (this.eventSeries[9][i - 1])
            {
               // Check if BearRun Persists
               this.eventSeries[9][i] = !this.eventSeries[4][i];
            }
            else
            {
               // Check if BearRun Starts
               this.eventSeries[9][i] = this.eventSeries[5][i];
            }
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            FloatSerie indicatorSerie = stockSerie.GetIndicator(this.parameters[0].ToString()).Series[0];
             FloatSerie speedSerie = indicatorSerie - indicatorSerie.CalculateEMA((int) this.parameters[1]);

             this.series[0] = speedSerie;
             this.Series[0].Name = this.Name;
        }
        public StockFinancialForm(StockSerie stockSerie)
        {
            InitializeComponent();

            this.Text = "Financials for " + stockSerie.ShortName + " - " + stockSerie.StockName;
            stockSerie.Financial.CalculateRatios();
            this.stockFinancialUserControl1.DataContext = stockSerie.Financial;
        }
        public override bool LoadData(string rootFolder, StockSerie stockSerie)
        {
            StockPortofolio portfolio = StockPortofolioList.Instance.FirstOrDefault(p => p.Name == stockSerie.StockName);
             if (portfolio == null) return false;

             portfolio.ToSerie(stockSerie);

             return true;
        }
        public override bool DownloadDailyData(string rootFolder, StockSerie stockSerie)
        {
            string url = @"http://www.gurufocus.com/ownership/%TICKER";
             url = url.Replace("%TICKER", stockSerie.ShortName);

             ShortInterestSerie siSerie = StockDictionary.StockDictionarySingleton.ShortInterestDictionary[stockSerie.StockName];
             siSerie.Initialise();

             if (siSerie.Count > 0 && siSerie.Keys.Last() > (DateTime.Today.AddDays(15))) return false;

             if (File.GetLastWriteTime(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName + "_SI.html").Date != DateTime.Today)
             {
            StockWebHelper swh = new StockWebHelper();
            if (swh.DownloadFile(Settings.Default.RootFolder + SHORTINTEREST_FOLDER, stockSerie.ShortName + "_SI.html", url))
            {
               string html = string.Empty;
               using (
                  StreamReader rw =
                     new StreamReader(Settings.Default.RootFolder + SHORTINTEREST_FOLDER + stockSerie.ShortName +
                                      "_SI.html"))
               {
                  html = rw.ReadToEnd();
                  html = html.Remove(0, html.IndexOf("<th>Short Interest</th>"));
                  html = html.Remove(0, html.IndexOf("<tr><td>"));
                  html = html.Remove(html.IndexOf("</tbody>"));

                  html = html.Replace("</td></tr><tr><td>", Environment.NewLine);

                  html = html.Replace("</td><td>", ";");

                  html = html.Replace("<tr><td>", "");
                  html = html.Replace("</td></tr>", "");
               }
               using (Stream stringStream = new MemoryStream(Encoding.UTF8.GetBytes(html.Trim())))
               {
                  using (StreamReader rw = new StreamReader(stringStream))
                  {
                     while (!rw.EndOfStream)
                     {
                        string[] fields = rw.ReadLine().Split(';');
                        ShortInterestValue siValue = new ShortInterestValue(DateTime.Parse(fields[0], usCulture),
                           float.Parse(fields[1], usCulture), 0f, 0f);

                        if (!siSerie.ContainsKey(siValue.Date))
                        {
                           siSerie.Add(siValue.Date, siValue);
                        }
                     }
                  }
               }

               siSerie.SaveToFile();
            }
             }
             return false;
        }
Example #28
0
        public HorseRaceDlg(string group, StockSerie.StockBarDuration barDuration)
        {
            InitializeComponent();

             (this.elementHost1.Child as HorseRaceControl).ViewModel.BarDuration = barDuration;
             (this.elementHost1.Child as HorseRaceControl).ViewModel.Group = group;
             (this.elementHost1.Child as HorseRaceControl).SelectedStockChanged += StockAnalyzerForm.MainFrame.OnSelectedStockChanged;

             StockAnalyzerForm.MainFrame.NotifyBarDurationChanged += MainFrame_NotifyBarDurationChanged;
        }
        public override bool LoadData(string rootFolder, StockSerie stockSerie)
        {
            // Read archive first
            string fileName = stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + ".csv";
            string fullFileName = rootFolder + ARCHIVE_FOLDER + "\\" + fileName;
            bool res = ParseCSVFile(stockSerie, fullFileName);

            fullFileName = rootFolder + FOLDER + "\\" + fileName;
            return ParseCSVFile(stockSerie, fullFileName) || res;
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            IStockTrail stockTrail = stockSerie.GetTrail(this.parameters[0].ToString().Replace('_', ','),
            this.parameters[1].ToString().Replace('_', ','));

             int i = 0;
             foreach (BoolSerie boolSerie in stockTrail.Events)
             {
            this.Events[i++] = boolSerie;
             }
        }