コード例 #1
0
        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);
        }
コード例 #2
0
        public MTFViewModel()
        {
            indicatorName = "TRAILHL(2)";

             this.group = StockSerie.Groups.EURONEXT;
             this.stockSeries = StockDictionary.StockDictionarySingleton.Values.Where(s => s.BelongsToGroup(group)).ToList();
             this.NbStocks = stockSeries.Count();
             this.Trends = new ObservableCollection<MTFTrend>();
             this.barDuration1 = StockSerie.StockBarDuration.Daily;
             this.barDuration2 = StockSerie.StockBarDuration.TLB;
             this.BarDuration3 = StockSerie.StockBarDuration.TLB_3D;

             dispatcher = Dispatcher.CurrentDispatcher;
        }
コード例 #3
0
        public StockScannerDlg(StockDictionary stockDictionary, StockSerie.Groups stockGroup, StockSerie.StockBarDuration barDuration, Dictionary<string, List<string>> theme)
        {
            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);

            periodComboBox.SelectedIndex = 0;
            completeBarCheckBox.Checked = true;

            OnThemeChanged(theme);
            OnBarDurationChanged(barDuration);

            oneRadioButton.Checked = true;
        }
コード例 #4
0
 public void OnBarDurationChanged(StockSerie.StockBarDuration barDuration)
 {
     this.barDuration = barDuration;
      selectedStockListBox.Items.Clear();
 }
コード例 #5
0
ファイル: MainFrame.cs プロジェクト: dadelcarbo/StockAnalyzer
        private string GenerateDailyReport()
        {
            CleanImageFolder();

            string mailReport = string.Empty;
            string htmlReport = string.Empty;

            string commentTitle = string.Empty;
            string commentBody = string.Empty;
            int imageCount = 0;
            ImageFormat imageFormat = ImageFormat.Png;
            List<string> cidList = new List<string>();
            List<string> fileNameList = new List<string>();

            //string hostIP = "ftp://ultimatechartist.com";
            //string userName = "******";
            //string password = "******";

            //StockFTP ftp = new StockFTP(hostIP, userName, password);
            //string[] files = ftp.directoryListDetailed(".");

            #region report multi TimeFrame

            StockSerie.StockBarDuration[] durations = new StockSerie.StockBarDuration[]
             {
            StockSerie.StockBarDuration.Daily,
            StockSerie.StockBarDuration.Daily_EMA3,
            StockSerie.StockBarDuration.TLB,
            StockSerie.StockBarDuration.TLB_EMA3,
            StockSerie.StockBarDuration.TLB_3D,
            StockSerie.StockBarDuration.TLB_3D_EMA3
             };

            // Generate header
            string rowContent = CELL_TEXT_TEMPLATE.Replace("%TEXT%", "Stock Name");
            string headerRow = string.Empty;
            foreach (StockSerie.StockBarDuration duration in durations)
            {
                rowContent += CELL_TEXT_TEMPLATE.Replace("%TEXT%", duration.ToString());
            }
            headerRow = ROW_TEMPLATE.Replace("%ROW%", rowContent);

            string tableContent = headerRow;

            var stockList = this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40));

            StockSplashScreen.FadeInOutSpeed = 0.25;
            StockSplashScreen.ProgressVal = 0;
            StockSplashScreen.ProgressMax = stockList.Count();
            StockSplashScreen.ProgressMin = 0;
            StockSplashScreen.ShowSplashScreen();

            foreach (StockSerie serie in stockList)
            {
                try
                {
                    rowContent = CELL_TEXT_TEMPLATE.Replace("%TEXT%", serie.StockName);

                    StockSplashScreen.ProgressVal++;
                    StockSplashScreen.ProgressText = "Downloading " + serie.StockGroup + " - " + serie.StockName;

                    //StockDataProviderBase.DownloadSerieData(Settings.Default.RootFolder, serie);

                    foreach (StockSerie.StockBarDuration duration in durations)
                    {
                        serie.BarDuration = duration;
                        if (serie.Initialise() && serie.Count > 50)
                        {
                            IStockTrailStop trailStop = serie.GetTrailStop("TRAILHL(1)");
                            if (float.IsNaN(trailStop.Series[0].Last))
                            {
                                rowContent += CELL_DIR_IMG_TEMPLATE.Replace("%DIR%", "DOWN");
                            }
                            else
                            {
                                rowContent += CELL_DIR_IMG_TEMPLATE.Replace("%DIR%", "UP");
                            }
                        }
                        else
                        {
                            rowContent += CELL_TEXT_TEMPLATE.Replace("%TEXT%", "-");
                        }
                    }
                }
                finally
                {
                    // Add Row
                    tableContent += ROW_TEMPLATE.Replace("%ROW%", rowContent);
                }
            }

            StockSplashScreen.CloseForm(true);
            string table = MULTITIMEFRAME_HEADER + MULTITIMEFRAME_TABLE.Replace("%TABLE%", tableContent) +
                           MULTITIMEFRAME_FOOTER;

            if (!Directory.Exists(Settings.Default.RootFolder + "\\CommentReport"))
            {
                Directory.CreateDirectory(Settings.Default.RootFolder + "\\CommentReport");
                Directory.CreateDirectory(Settings.Default.RootFolder + "\\CommentReport\\img");
            }
            using (StreamWriter sw = new StreamWriter(Settings.Default.RootFolder + @"\CommentReport\report_table.html"))
            {
                sw.Write(table);
            }
            #endregion

            #region Report leaders

            this.CurrentTheme = "ReportTheme";
            this.barDurationComboBox.SelectedItem = StockSerie.StockBarDuration.Daily;

            string rankLeaderIndicatorName = "ROR(100,1,6)";
            string rankLoserIndicatorName = "ROD(100,1,6)";
            int nbLeaders = 10;
            string htmlLeaders = GenerateLeaderLoserTable(StockSerie.Groups.CAC40, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);
            htmlLeaders += GenerateLeaderLoserTable(StockSerie.Groups.EURO_A, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);
            htmlLeaders += GenerateLeaderLoserTable(StockSerie.Groups.EURO_B, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);
            htmlLeaders += GenerateLeaderLoserTable(StockSerie.Groups.EURO_C, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);

            htmlLeaders += GenerateLeaderLoserTable(StockSerie.Groups.COMMODITY, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);
            htmlLeaders += GenerateLeaderLoserTable(StockSerie.Groups.FOREX, rankLeaderIndicatorName, rankLoserIndicatorName, nbLeaders);

            mailReport += htmlLeaders;
            htmlReport += htmlLeaders;

            #endregion

            StockSerie previousStockSerie = this.CurrentStockSerie;
            string previousTheme = this.CurrentTheme;
            StockSerie.StockBarDuration previousBarDuration =
               (StockSerie.StockBarDuration)this.barDurationComboBox.SelectedItem;

            using (StreamReader sr = new StreamReader(Settings.Default.RootFolder + @"\report.cfg"))
            {
                //#region Report from config file

                //while (!sr.EndOfStream)
                //{
                //    string line = sr.ReadLine();
                //    //continue;
                //    if (string.IsNullOrWhiteSpace(line))
                //    {
                //        continue;
                //    }

                //    string[] fields = line.Split(';');
                //    if (fields[0].StartsWith("#Title", StringComparison.InvariantCultureIgnoreCase))
                //    {
                //        mailReport += htmlTitleTemplate.Replace(titleTemplate, fields[1]);
                //        htmlReport += htmlTitleTemplate.Replace(titleTemplate, fields[1]);
                //    }

                //    if (fields.Length == 0 || !this.StockDictionary.ContainsKey(fields[0]))
                //    {
                //        continue;
                //    }

                //    this.barDurationComboBox.SelectedItem =
                //       (StockSerie.StockBarDuration)Enum.Parse(typeof(StockSerie.StockBarDuration), fields[2]);
                //    this.CurrentStockSerie = this.StockDictionary[fields[0]];
                //    this.CurrentTheme = fields[1];

                //    if (fields.Length >= 4)
                //    {
                //        int nbBars = int.Parse(fields[3]);
                //        this.ChangeZoom(Math.Max(0, CurrentStockSerie.Count - 1 - nbBars), CurrentStockSerie.Count - 1);
                //    }

                //    StockSerie stockSerie = this.CurrentStockSerie;

                //    // Extract indicators
                //    string eventTypeString = ExtractEventsForReport();

                //    this.snapshotToolStripButton_Click(null, null);
                //    Image bitmap = Clipboard.GetImage();

                //    string fileName = GetFileName(DateTime.Now, stockSerie, imageFormat.ToString().ToLower());
                //    if (!System.IO.File.Exists(fileName))
                //    {
                //        bitmap.Save(fileName, imageFormat);
                //        fileNameList.Add(fileName);

                //        // Get image CID
                //        string cid = "Image_" + imageCount++;
                //        cidList.Add(cid);

                //        commentTitle = "\r\n" + stockSerie.StockName + "( " + fields[2] + ") - " + fields[1] + " - " +
                //                       stockSerie.Keys.Last().ToShortDateString() + "\r\n\r\n";

                //        // Build report from html template
                //        mailReport += htmlMailCommentTemplate.Replace(commentTitleTemplate, commentTitle)
                //           .Replace(commentTemplate, commentBody)
                //           .Replace(imageFileCID, cid);
                //        mailReport += eventTypeString;
                //        htmlReport += htmlCommentTemplate.Replace(commentTitleTemplate, commentTitle)
                //           .Replace(commentTemplate, commentBody)
                //           .Replace(imageFileLink,
                //              fileName.Replace(
                //                 StockAnalyzerSettings.Properties.Settings.Default.RootFolder + @"\CommentReport\", "./")
                //                 .Replace(@"\", "/"));
                //        htmlReport += eventTypeString;
                //    }
                //}

                //#endregion
            }

            #region Generate report from Portfolio

            //List<String> stockNames = this.StockPortofolioList.GetStockNames();
            //foreach (StockSerie stockSerie in this.StockDictionary.Values.Where(s => stockNames.Contains(s.StockName)))
            //{
            //   this.barDurationComboBox.SelectedItem = StockSerie.StockBarDuration.Bar_3;
            //   this.CurrentTheme = "TrendLine";
            //   this.CurrentStockSerie = stockSerie;

            //   string eventTypeString = ExtractEventsForReport();

            //   if (string.IsNullOrWhiteSpace(eventTypeString))
            //   {
            //      continue;
            //   }

            //   this.snapshotToolStripButton_Click(null, null);
            //   Image bitmap = Clipboard.GetImage();

            //   string fileName = GetFileName(DateTime.Today, stockSerie, imageFormat.ToString().ToLower());
            //   if (!System.IO.File.Exists(fileName))
            //   {
            //      bitmap.Save(fileName, imageFormat);
            //      fileNameList.Add(fileName);

            //      // Get image CID
            //      string cid = "Image_" + imageCount++;
            //      cidList.Add(cid);

            //      commentTitle = "\r\n" + stockSerie.StockName + "( " + this.barDurationComboBox.SelectedItem + ") - " +
            //                     " - " + stockSerie.Keys.Last().ToShortDateString() + "\r\n\r\n";

            //      // Build report from html template
            //      mailReport += htmlMailCommentTemplate.Replace(commentTitleTemplate, commentTitle)
            //         .Replace(commentTemplate, commentBody)
            //         .Replace(imageFileCID, cid);
            //      mailReport += eventTypeString;
            //      htmlReport += htmlCommentTemplate.Replace(commentTitleTemplate, commentTitle)
            //         .Replace(commentTemplate, commentBody)
            //         .Replace(imageFileLink,
            //            fileName.Replace(
            //               StockAnalyzerSettings.Properties.Settings.Default.RootFolder + @"\CommentReport\", "./")
            //               .Replace(@"\", "/"));
            //      htmlReport += eventTypeString;
            //   }
            //}

            #endregion

            #region Generate report from Events

            StockAlertDef cciEx = new StockAlertDef(StockSerie.StockBarDuration.Daily, "DECORATOR", "DIVWAIT(1.5,1)|CCIEX(50,12,20,0.0195,75,-75)", "ExhaustionBottom");
            StockAlertDef barAbove = new StockAlertDef(StockSerie.StockBarDuration.Daily, "INDICATOR", "HMA(30)", "FirstBarAbove");
            StockAlertDef barBelow = new StockAlertDef(StockSerie.StockBarDuration.Daily, "INDICATOR", "HMA(30)", "FirstBarBelow");
            StockAlertDef ResistanceBroken = new StockAlertDef(StockSerie.StockBarDuration.Daily, "PAINTBAR", "TRENDLINEHL(1,10)", "ResistanceBroken");
            StockAlertDef trailHL = new StockAlertDef(StockSerie.StockBarDuration.Daily, "TRAILSTOP", "TRAILHLS(2,3)", "BrokenUp");
            StockAlertDef trailHLSR = new StockAlertDef(StockSerie.StockBarDuration.Daily, "INDICATOR", "TRAILHLSR(5)", "ResistanceBroken");
            List<StockAlertDef> alerts = new List<StockAlertDef>();

            alerts.Clear();
            alerts.Add(cciEx);
            alerts.Add(barAbove);
            alerts.Add(barBelow);
            alerts.Add(trailHL);
            alerts.Add(ResistanceBroken);
            alerts.Add(trailHLSR);

            foreach (
               StockSerie stockSerie in this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40)))
            {
                //this.barDurationComboBox.SelectedItem = StockSerie.StockBarDuration.Daily;
                //this.CurrentTheme = "Empty";
                //this.CurrentStockSerie = stockSerie;

                StockSplashScreen.ProgressVal++;
                StockSplashScreen.ProgressSubText = "Scanning " + stockSerie.StockName;

                if (!stockSerie.Initialise() || stockSerie.Count < 200) continue;

                string alertMsg = string.Empty;
                foreach (StockAlertDef alert in alerts)
                {
                    if (stockSerie.MatchEvent(alert))
                    {
                        var values = stockSerie.GetValues(alert.BarDuration);
                        string alertLine = stockSerie.StockName + ";" + values.ElementAt(values.Count - 2).DATE.TimeOfDay +
                                           ";" + alert.ToString();

                        alertMsg += "<br>" + alertLine + ";" + stockSerie.GetValues(StockSerie.StockBarDuration.Daily).Last().CLOSE + "</br>";
                    }
                }
                if (!string.IsNullOrEmpty(alertMsg))
                {
                    commentTitle = "\r\n" + stockSerie.StockName + " - " + stockSerie.Keys.Last().ToShortDateString() + "\r\n";

                    // Build report from html template
                    //mailReport += htmlMailCommentTemplate.Replace(commentTitleTemplate, commentTitle)
                    //   .Replace(commentTemplate, commentBody)
                    //   //.Replace(imageFileCID, cid);
                    //mailReport += eventTypeString;
                    htmlReport += htmlAlertTemplate.Replace(commentTitleTemplate, commentTitle)
                       .Replace(commentTemplate, alertMsg);
                    //.Replace(imageFileLink,
                    //   fileName.Replace(StockAnalyzerSettings.Properties.Settings.Default.RootFolder + @"\CommentReport\",
                    //      "./").Replace(@"\", "/"));
                    //htmlReport += alertMsg;
                }
            }

            //this.snapshotToolStripButton_Click(null, null);
            //Image bitmap = Clipboard.GetImage();

            //string fileName = GetFileName(DateTime.Today, stockSerie, imageFormat.ToString().ToLower());
            //if (!System.IO.File.Exists(fileName))
            //{
            //   bitmap.Save(fileName, imageFormat);
            //   fileNameList.Add(fileName);

            //   // Get image CID
            //   string cid = "Image_" + imageCount++;
            //   cidList.Add(cid);

            //   commentTitle = "\r\n" + stockSerie.StockName + "( " + this.barDurationComboBox.SelectedItem + ") - " + " - " +
            //                  stockSerie.Keys.Last().ToShortDateString() + "\r\n\r\n";

            //   // Build report from html template
            //   mailReport += htmlMailCommentTemplate.Replace(commentTitleTemplate, commentTitle)
            //      .Replace(commentTemplate, commentBody)
            //      .Replace(imageFileCID, cid);
            //   mailReport += eventTypeString;
            //   htmlReport += htmlCommentTemplate.Replace(commentTitleTemplate, commentTitle)
            //      .Replace(commentTemplate, commentBody)
            //      .Replace(imageFileLink,
            //         fileName.Replace(StockAnalyzerSettings.Properties.Settings.Default.RootFolder + @"\CommentReport\",
            //            "./").Replace(@"\", "/"));
            //   htmlReport += eventTypeString;
            //}

            #endregion

            //AlternateView htmlView = AlternateView.CreateAlternateViewFromString(mailReport, null, "text/html");
            //int index = 0;
            //foreach (string cid in cidList)
            //{
            //    LinkedResource imagelink = new LinkedResource(fileNameList[index++], "image/" + imageFormat.ToString());
            //    imagelink.ContentId = cid;
            //    imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            //    htmlView.LinkedResources.Add(imagelink);
            //}
            //email.AlternateViews.Add(htmlView);

            using (StreamWriter sw = new StreamWriter(Settings.Default.RootFolder + @"\CommentReport\report.html"))
            {
                sw.Write(htmlReport);
            }
            // ftp.uploadDirectory("www/CommentReport", Settings.Default.RootFolder + @"\CommentReport");

            //           Process.Start("http://www.ultimatechartist.com/CommentReport/report.html");
            Process.Start(Settings.Default.RootFolder + @"\CommentReport\report.html");
            this.CurrentStockSerie = previousStockSerie;
            this.CurrentTheme = previousTheme;
            this.barDurationComboBox.SelectedItem = previousBarDuration;

            return mailReport;
        }
コード例 #6
0
 public void OnBarDurationChanged(StockSerie.StockBarDuration barDuration)
 {
     this.barDuration = barDuration;
 }