Example #1
0
 public static void Add(EntryBar entry)
 {
     worksheet.Cells[Count, 0] = new Cell(entry.entryBar.Date, "dd/mm/yyyy");
     worksheet.Cells[Count, 1] = new Cell(entry.entryBar.Date, "HH:mm:ss");
     worksheet.Cells[Count, 2] = new Cell(entry.Close);
     Count++;
 }
Example #2
0
 public static void Add(EntryBar entry)
 {
     worksheet.Cells[Count, 0] = new Cell(entry.entryBar.Date, "dd/mm/yyyy");
     worksheet.Cells[Count, 1] = new Cell(entry.entryBar.Date, "HH:mm:ss");
     worksheet.Cells[Count, 2] = new Cell(entry.EntryPrice);
     worksheet.Cells[Count, 3] = new Cell(entry.Direction);
     worksheet.Cells[Count, 4] = new Cell(entry.FixPrice);
     Count++;
 }
Example #3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            using (var sr = new StreamReader("C://Users/Артур/Desktop/архив котировок/Акции для WL/ХолМРСК/ХолМРСК.txt"))
            {
                currMonth.High = Double.MinValue;
                currMonth.Low = Double.MaxValue;
                prevMonth.Month = 1;
                prevMonth.Year = 99;
                wasTrade = false;
                notFirstMonth = false;
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    var edesc = line.Split(',');
                    var bar = new Bar(edesc[0], edesc[1], edesc[2], edesc[3], edesc[4], edesc[5], edesc[6]);
                    if (bar.Date.Month > prevMonth.Month || bar.Date.Year > prevMonth.Year)                            // проверяем изменился ли месяц
                    {
                        prevMonth.High = currMonth.High;
                        prevMonth.Low = currMonth.Low;
                        prevMonth.Month = bar.Date.Month;
                        prevMonth.Year = bar.Date.Year;
                        notFirstMonth = true;
                        wasTrade = false;
                        currMonth.High = bar.High;
                        currMonth.Low = bar.Low;
                    }
                    else
                    {
                        if (bar.High > currMonth.High) currMonth.High = bar.High; // отследиваем хай текущего месяца
                        if (bar.Low < currMonth.Low) currMonth.Low = bar.Low; // отслеживаем лоу текущего месяца

                        if (notFirstMonth && !wasTrade)
                        {
                            double currMonthHighLow = currMonth.High - currMonth.Low; // считаем диапазон текущего месяца
                            double prevMonthHighLow = prevMonth.High - prevMonth.Low; // считаем диапазон предыдущего месяца
                            if (currMonthHighLow > prevMonthHighLow)
                                {
                                    wasTrade = true;
                                    entrybar = new EntryBar(bar, Math.Sign(Math.Abs(currMonth.Low - bar.Close) - Math.Abs(currMonth.High - bar.Close)));
                                    if (entrybar.Direction != prevDirection)
                                    {   
                                        prevDirection = entrybar.Direction;
                                        Console.WriteLine("close:" + entrybar.Close + " dir:" + entrybar.Direction + " date:" + bar.Date); 
                                        Output.Add(entrybar);
                                    }
                                }
                        }
                    }
                }
                Console.WriteLine("Вышли из цикла");
                Output.Save();
            }

        }
Example #4
0
 public static void Add(EntryBar entry)
 {
     worksheet.Cells[Count, 0] = new Cell(entry.entryBar.Date, "dd/mm/yyyy");
     worksheet.Cells[Count, 1] = new Cell(entry.entryBar.Date, "HH:mm:ss");
     worksheet.Cells[Count, 2] = new Cell(entry.InitRisk);
     worksheet.Cells[Count, 3] = new Cell(entry.PrevDayHighLow);
     worksheet.Cells[Count, 4] = new Cell(entry.EntryPrice);
     worksheet.Cells[Count, 5] = new Cell(entry.Direction);
     worksheet.Cells[Count, 6] = new Cell(entry.Max1);
     worksheet.Cells[Count, 7] = new Cell(entry.Max2);
     worksheet.Cells[Count, 8] = new Cell(entry.Max3);
     worksheet.Cells[Count, 9] = new Cell(entry.Max4);
     worksheet.Cells[Count, 10] = new Cell(entry.FixPrice);
     worksheet.Cells[Count, 11] = new Cell(entry.Slipage);
     Count++;
 }
Example #5
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     using (var sr = new StreamReader("C://Users/Артур/Desktop/архив котировок/Акции для WL/RiМинИнтрадей/СклИнтрадейRI(01.2009-12.2012).txt"))
     {
         while (!sr.EndOfStream)
         {
             var line = sr.ReadLine();
             var edesc = line.Split(',');
             var bar = new Bar(edesc[0], edesc[1], edesc[2], edesc[3], edesc[4], edesc[5], edesc[6]);
             if (((bar.Date.Hour == 23) && (bar.Date.Minute == 49)) || ((bar.Date.Hour == 10) && (bar.Date.Minute == 59)))
             {
                 entrybar = new EntryBar(bar);
                 Output.Add(entrybar);
             }
         }
         Output.Save();
     }
 }
Example #6
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            using (var sr = new StreamReader("C://Users/Артур/Downloads/SPFB.RTS_121217_130201.txt"))
            {
                prev2Hour.Hour = 10;
                prevDay.Day = 17;
                curr2Hour.High = Double.MinValue;
                curr2Hour.Low = Double.MaxValue;

                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    var edesc = line.Split(',');
                    var bar = new Bar(edesc[0], edesc[1], edesc[2], edesc[3], edesc[4], edesc[5], edesc[6]);

                    if (bar.Date.Day != prevDay.Day)
                    {
                        prev2Hour.Hour = 10;
                        curr2Hour.High = bar.High;
                        curr2Hour.Low = bar.Low;
                        prevDay.Day = bar.Date.Day;
                        
                        if (wasTrade && !wasFix) 
                        {
                            entrybar.FixPrice = prevBar.Close;
                            Output.Add(entrybar);
                        }

                        wasTrade = false;
                        wasFix = false;
                        notFirst2Hour = false;
                    }


                    if (bar.Date.Hour - prev2Hour.Hour == 2 )
                    {
                        if (bar.Date.Hour < 13 && bar.Date.Minute == 0) 
                        {
                            first2Hour.High = curr2Hour.High;
                            first2Hour.Low = curr2Hour.Low;
                            notFirst2Hour = true;
                        }
                        prev2Hour.High = curr2Hour.High;
                        prev2Hour.Low = curr2Hour.Low;
                        curr2Hour.High = bar.High;
                        curr2Hour.Low = bar.Low;
                        prev2Hour.Hour = bar.Date.Hour;
                    }
                    else
                    {
                        prevBar = bar;
                        if (bar.High > curr2Hour.High) curr2Hour.High = bar.High; // отследиваем хай текущих 2 часов
                        if (bar.Low < curr2Hour.Low) curr2Hour.Low = bar.Low; // отслеживаем лоу текущих 2 часов
                    }

                    if (bar.Date.Hour - prev2Hour.Hour == 0 && notFirst2Hour)
                    {
                       //if ((prev2Hour.High > first2Hour.High && prev2Hour.Low < first2Hour.Low))     УБИРАЮ ЭТУ ЧАСТЬ, ГДЕ ОДНОВРЕМЕННО ЭКСТРЕМУМЫ РИСУЮТСЯ
                       //{
                       //    wasTrade = true;
                       //    wasFix = true;
                       //}
                        // чтоб тока в одну сторону хай или лоу превышался
                        if ((prev2Hour.High > first2Hour.High || prev2Hour.Low < first2Hour.Low) && !wasTrade) // УБРАЛ УСЛОВИЕ, ГДЕ ОДНОВРЕМЕННО ЭКСТРЕМУМЫ РИСУЮТСЯ
                        {
                            wasTrade = true;
                            double entryPrice;
                            int direction;
                            // определям дирекшн
                            if (prev2Hour.High > first2Hour.High) direction = -1;
                            else direction = 1;
                            if ((prev2Hour.High > first2Hour.High && prev2Hour.Low < first2Hour.Low))
                            {
                                if (Math.Abs(bar.Open - first2Hour.High) > Math.Abs(bar.Open - first2Hour.Low)) direction = 1;
                                else direction = -1;
                            }
                            entryPrice = bar.Open;
                            if (direction == 1) stopPrice = prev2Hour.Low - (prev2Hour.High - prev2Hour.Low) / 2;
                            else                stopPrice = prev2Hour.High + (prev2Hour.High - prev2Hour.Low) / 2;

                            entrybar = new EntryBar(bar, direction, entryPrice, 0);
                        }
                    }
                    if (wasTrade && !wasFix)
                    {
                        if (entrybar.Direction == 1)
                        {
                            if (bar.Low < stopPrice)
                            {
                                entrybar.FixPrice = stopPrice;
                                wasFix = true;
                                Output.Add(entrybar);
                            }
                        }
                        else
                        {
                            if (bar.High > stopPrice)
                            {
                                entrybar.FixPrice = stopPrice;
                                wasFix = true;
                                Output.Add(entrybar);
                            }
                        }
                    }

                }

            }
            Console.WriteLine("Вышли из цикла");
            Output.Save();
        }
Example #7
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            using (var sr = new StreamReader("C://Users/Артур/Desktop/output.txt"))
            {
                currDay.High = Double.MinValue;
                currDay.Low = Double.MaxValue;
                currHour.High = Double.MinValue;
                currHour.Low = Double.MaxValue;
                prevDay.Day = 11;
                wasTrade = false;
                wasFix = false;
                notFirstDay = false;
                notFirstHour = false;
                prevHour.Date = new DateTime(2020, 12, 12, 10, 59, 59);
                prevDay.Month = 1; // для месяцев добавляю
                prevDay.Year = 2009; // для лет добавляю
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    var edesc = line.Split(',');
                    var bar = new Bar(edesc[0], edesc[1], edesc[2], edesc[3], edesc[4], edesc[5], edesc[6]);
                   
                    if (bar.Date.Hour != prevHour.Date.Hour)
                    {
                        prevHour.High = currHour.High;
                        prevHour.Low = currHour.Low;
                        currHour.High = bar.High;
                        currHour.Low = bar.Low;
                        prevHour.Date = bar.Date;
                    }
                    else
                    {
                        if (bar.High > currHour.High) currHour.High = bar.High; // отследиваем хай текущего часа
                        if (bar.Low < currHour.Low) currHour.Low = bar.Low; // отслеживаем лоу текущего часа
                    }

                    if (bar.Date.Day > prevDay.Day || bar.Date.Month > prevDay.Month || bar.Date.Year > prevDay.Year)                            // проверяем изменился ли день
                    {
                        prevDay.High = currDay.High;
                        prevDay.Low = currDay.Low;
                        prevDay.Day = bar.Date.Day;
                        notFirstDay = true;
                        wasTrade = false;
                        wasFix = false;
                        currDay.High = bar.High;
                        currDay.Low = bar.Low;
                        prevHour.High = currHour.High;
                        prevHour.Low = currHour.Low;
                        currHour.High = bar.High;
                        currHour.Low = bar.Low;
                        prevHour.Date = bar.Date;
                        prevDay.Month = bar.Date.Month; // для месяцев добавляю
                        prevDay.Year = bar.Date.Year; // для лет добавляю
                    }
                    else
                    {
                        if (bar.High > currDay.High) currDay.High = bar.High; // отследиваем хай текущего дня
                        if (bar.Low < currDay.Low) currDay.Low = bar.Low; // отслеживаем лоу текущего дня
                        if (wasTrade && (entrybar.entryBar.Date.Hour < bar.Date.Hour))
                        {

                            if (entrybar.Direction == 1)
                            {
                                switch (-entrybar.entryBar.Date.Hour + bar.Date.Hour)
                                {
                                    case 1:
                                        entrybar.Max1 = prevHour.High - entrybar.EntryPrice;
                                        break;
                                    case 2:
                                        entrybar.Max2 = prevHour.High - entrybar.EntryPrice;
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 3:
                                        entrybar.Max3 = prevHour.High - entrybar.EntryPrice;
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 4:
                                        entrybar.Max4 = prevHour.High - entrybar.EntryPrice;
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 5:
                                        stopPrice = prevHour.Low - 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 6:
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 7:
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 8:
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 9:
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                    case 10:
                                        stopPrice = prevHour.Low - 1; // здесь для разных инструментов надо менять тик
                                        break;
                                }
                            }
                            else
                            {
                                switch (-entrybar.entryBar.Date.Hour + bar.Date.Hour)
                                {
                                    case 1:
                                        entrybar.Max1 = -prevHour.Low + entrybar.EntryPrice;
                                        break;
                                    case 2:
                                        entrybar.Max2 = -prevHour.Low + entrybar.EntryPrice;
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 3:
                                        entrybar.Max3 = -prevHour.Low + entrybar.EntryPrice;
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 4:
                                        entrybar.Max4 = -prevHour.Low + entrybar.EntryPrice;
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 5:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 6:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 7:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 8:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 9:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                    case 10:
                                        stopPrice = prevHour.High + 1;  // здесь для разных инструментов надо менять тик
                                        break;
                                }
                            }
                        }

                                            
                        
                        if (wasTrade && entrybar.Direction == 1 && stopPrice > bar.Low)
                        {
                            entrybar.FixPrice = stopPrice;
                            wasTrade = false;
                            wasFix = true;
                            switch (entrybar.entryBar.Date.Hour - bar.Date.Hour)
                            {
                                case 0:
                                    entrybar.Max1 = currHour.High - entrybar.EntryPrice;
                                    break;
                                case 1:
                                    entrybar.Max2  = currHour.High - entrybar.EntryPrice;
                                    break;
                                case 2:
                                    entrybar.Max3 = currHour.High - entrybar.EntryPrice;
                                    break;
                                case 3:
                                    entrybar.Max4 = currHour.High - entrybar.EntryPrice;
                                    break;
                            }
                            Output.Add(entrybar);

                        }
                        if (wasTrade && entrybar.Direction == -1 && stopPrice < bar.High)
                        {
                            entrybar.FixPrice = stopPrice;
                            wasTrade = false;
                            wasFix = true;
                            switch (entrybar.entryBar.Date.Hour - bar.Date.Hour)
                            {
                                case 0:
                                    entrybar.Max1 = -currHour.Low + entrybar.EntryPrice;
                                    break;
                                case 1:
                                    entrybar.Max2 = -currHour.Low + entrybar.EntryPrice;
                                    break;
                                case 2:
                                    entrybar.Max3 = -currHour.Low + entrybar.EntryPrice;
                                    break;
                                case 3:
                                    entrybar.Max4 = -currHour.Low + entrybar.EntryPrice;
                                    break;
                            }
                            Output.Add(entrybar);
                        }

                        if (bar.Date.Hour == 23 && bar.Date.Minute == 49 && wasTrade && entrybar.FixPrice == 0)
                        {
                            entrybar.FixPrice = bar.Close;
                            Output.Add(entrybar);
                        }

                        if (notFirstDay && !wasTrade && !wasFix)
                        {
                            double currDayHighLow = currDay.High - currDay.Low; // считаем диапазон текущего месяца
                            double prevDayHighLow = prevDay.High - prevDay.Low; // считаем диапазон предыдущего месяца
                            if ((currDayHighLow > prevDayHighLow) && (bar.Date.TimeOfDay < new TimeSpan(18, 45, 00)))
                            {
                                wasTrade = true;
                                double entryPrice;
                                double initRisk;
                                double slipage;
                                var direction = Math.Sign(Math.Abs(currDay.Low - bar.Close) - Math.Abs(currDay.High - bar.Close));
                                if (direction == 1)
                                {
                                    entryPrice = currDay.Low + prevDayHighLow + 1;  // здесь для разных инструментов надо менять тик
                                    initRisk = entryPrice - currHour.Low;
                                    stopPrice = currHour.Low - 1;  // здесь для разных инструментов надо менять тик
                                }
                                else
                                {
                                    entryPrice = currDay.High - prevDayHighLow - 1; // здесь для разных инструментов надо менять тик
                                    initRisk = currHour.High - entryPrice;
                                    stopPrice = currHour.High + 1; // здесь для разных инструментов надо менять тик
                                }
                                slipage = Math.Abs(entryPrice - bar.Close);

                                entrybar = new EntryBar(
                                    bar,
                                    direction,
                                    initRisk,
                                    prevDayHighLow,
                                    entryPrice,
                                    0,
                                    0,
                                    0,
                                    0,
                                    0,
                                    slipage
                                );
                                //  Console.WriteLine("close:" + entrybar.Close + " dir:" + entrybar.Direction + " date:" + bar.Date); 

                            }
                        }
                    }
                }
            }
            Console.WriteLine("Вышли из цикла");
            Output.Save();
        }