예제 #1
0
        /// <summary>
        /// download from file
        /// загрузить из файла
        /// </summary>
        public void Load()
        {
            if (!File.Exists(@"Engine\" + Name + @"Alert.txt"))
            {
                return;
            }
            try
            {
                using (StreamReader reader = new StreamReader(@"Engine\" + Name + @"Alert.txt"))
                {
                    Enum.TryParse(reader.ReadLine(), true, out Type);

                    string [] savesLine = reader.ReadLine().Split('%');

                    Lines = new ChartAlertLine[savesLine.Length - 1];

                    for (int i = 0; i < savesLine.Length - 1; i++)
                    {
                        Lines[i] = new ChartAlertLine();
                        Lines[i].SetFromSaveString(savesLine[i]);
                    }

                    Label       = reader.ReadLine();
                    Message     = reader.ReadLine();
                    BorderWidth = Convert.ToInt32(reader.ReadLine());
                    IsOn        = Convert.ToBoolean(reader.ReadLine());
                    IsMusicOn   = Convert.ToBoolean(reader.ReadLine());
                    IsMessageOn = Convert.ToBoolean(reader.ReadLine());

                    ColorLine  = Color.FromArgb(Convert.ToInt32(reader.ReadLine()));
                    ColorLabel = Color.FromArgb(Convert.ToInt32(reader.ReadLine()));
                    Enum.TryParse(reader.ReadLine(), out Music);

                    Enum.TryParse(reader.ReadLine(), true, out SignalType);
                    VolumeReaction      = reader.ReadLine().ToDecimal();
                    Slippage            = Convert.ToDecimal(reader.ReadLine());
                    NumberClosePosition = Convert.ToInt32(reader.ReadLine());
                    Enum.TryParse(reader.ReadLine(), true, out OrderPriceType);

                    reader.Close();
                }
            }
            catch (Exception)
            {
                // ignore
            }
        }
예제 #2
0
        /// <summary>
        /// Создать линию из точек
        /// </summary>
        /// <param name="valueOne">значение первой точки</param>
        /// <param name="valueTwo">значение второй точки</param>
        /// <param name="numberOne">номер первой точки</param>
        /// <param name="numberTwo">номер второй точки</param>
        /// <param name="candles">свечи</param>
        /// <returns>алерт</returns>
        private ChartAlertLine AlertLineCreate(decimal valueOne, decimal valueTwo, int numberOne, int numberTwo, List <Candle> candles)
        {
            // 2 рассчитываем движение индикатора за свечу на данном ТФ

            decimal stepCorner; // сколько наша линия проходит за свечку

            stepCorner = (valueTwo - valueOne) / (numberTwo - numberOne + 1);

            // 3 теперь строим массив значений линии параллельный свечному массиву

            decimal[] lineDecimals = new decimal[candles.Count];
            decimal   point        = valueOne;

            lineDecimals[numberOne] = point;

            for (int i = numberOne + 1; i < lineDecimals.Length; i++)
            { // бежим вперёд по массиву
                lineDecimals[i] = point;
                point          += stepCorner;
            }

            point = valueOne;
            for (int i = numberOne - 1; i > -1; i--)
            { // бежим назад по массиву
                lineDecimals[i] = point;
                point          -= stepCorner;
            }

            // 4 находим ближайший от начала час  и следующий за ним

            int firstHourCandle = -1;

            int secondHourCandle = -1;

            int nowHour = candles[candles.Count - 1].TimeStart.Hour;

            for (int i = candles.Count - 1; i > -1; i--)
            {
                if (nowHour != candles[i].TimeStart.Hour)
                {
                    nowHour = candles[i].TimeStart.Hour;

                    if (firstHourCandle == -1)
                    {
                        firstHourCandle = i + 1;
                    }
                    else
                    {
                        secondHourCandle = i + 1;
                        break;
                    }
                }
            }

            // 6 рассчитываем реальное положение алерта. В часах.

            if (secondHourCandle < 0 ||
                firstHourCandle < 0)
            {
                return(null);
            }

            DateTime startTime = candles[secondHourCandle].TimeStart;
            DateTime endTime   = candles[firstHourCandle].TimeStart;

            decimal startPoint = lineDecimals[secondHourCandle];
            decimal endPoint   = lineDecimals[firstHourCandle];

            // 5 далее рассчитываем значение линии на первом и втором часе

            ChartAlertLine line = new ChartAlertLine();

            line.TimeFirstPoint  = startTime;
            line.ValueFirstPoint = startPoint;

            line.TimeSecondPoint  = endTime;
            line.ValueSecondPoint = endPoint;

            return(line);
        }
예제 #3
0
        /// <summary>
        /// взять Линии для Алерта типа Chanal
        /// </summary>
        /// <param name="candles">свечи</param>
        /// <returns>линии</returns>
        private ChartAlertLine[] GetChanalLines(List <Candle> candles)
        {
            if (Slider.Value == 100)
            {
                decimal valueOne  = _candleOneValue;
                decimal valueTwo  = _candleTwoValue;
                int     numberOne = _candleOneNumber;
                int     numberTwo = _candleTwoNumber;

                ChartAlertLine[] lines = { AlertLineCreate(valueOne, valueTwo, numberOne, numberTwo, candles) };
                return(lines);
            }

            // 1 берём точки

            decimal onePoint  = _candleOneValue;
            int     oneNumber = _candleOneNumber; // первая точка линии

            decimal twoPoint   = _candleTwoValue;
            int     twoPNumber = _candleTwoNumber; // вторая точка линии

            decimal l023value1;
            decimal l023value2;

            decimal l038value1;
            decimal l038value2;

            decimal l050value1;
            decimal l050value2;

            decimal l061value1;
            decimal l061value2;

            decimal l076value1;
            decimal l076value2;

            decimal l0100value1;
            decimal l0100value2;

            decimal l0161value1;
            decimal l0161value2;

            decimal l0261value1;
            decimal l0261value2;

            decimal l0423value1;
            decimal l0423value2;

            decimal sliderValue = Convert.ToDecimal(Slider.Value);
            decimal devider;

            if (Slider.Value > 100)
            {
                devider = (sliderValue - 100) / 1000; // 100 / 1000 = 0,1

                l023value1 = onePoint + devider * onePoint * 0.23m;
                l023value2 = twoPoint + devider * twoPoint * 0.23m;

                l038value1 = onePoint + devider * onePoint * 0.38m;
                l038value2 = twoPoint + devider * twoPoint * 0.38m;

                l050value1 = onePoint + devider * onePoint * 0.50m;
                l050value2 = twoPoint + devider * twoPoint * 0.50m;

                l061value1 = onePoint + devider * onePoint * 0.61m;
                l061value2 = twoPoint + devider * twoPoint * 0.61m;

                l076value1 = onePoint + devider * onePoint * 0.76m;
                l076value2 = twoPoint + devider * twoPoint * 0.76m;

                l0100value1 = onePoint + devider * onePoint * 1m;
                l0100value2 = twoPoint + devider * twoPoint * 1m;

                l0161value1 = onePoint + devider * onePoint * 1.61m;
                l0161value2 = twoPoint + devider * twoPoint * 1.61m;

                l0261value1 = onePoint + devider * onePoint * 2.61m;
                l0261value2 = twoPoint + devider * twoPoint * 2.61m;

                l0423value1 = onePoint + devider * onePoint * 4.23m;
                l0423value2 = twoPoint + devider * twoPoint * 4.423m;
            }
            else
            {
                devider = (100 - sliderValue) / 1000; // 100 / 1000 = 0,1

                l023value1 = onePoint - devider * onePoint * 0.23m;
                l023value2 = twoPoint - devider * twoPoint * 0.23m;

                l038value1 = onePoint - devider * onePoint * 0.38m;
                l038value2 = twoPoint - devider * twoPoint * 0.38m;

                l050value1 = onePoint - devider * onePoint * 0.50m;
                l050value2 = twoPoint - devider * twoPoint * 0.50m;

                l061value1 = onePoint - devider * onePoint * 0.61m;
                l061value2 = twoPoint - devider * twoPoint * 0.61m;

                l076value1 = onePoint - devider * onePoint * 0.76m;
                l076value2 = twoPoint - devider * twoPoint * 0.76m;

                l0100value1 = onePoint - devider * onePoint * 1m;
                l0100value2 = twoPoint - devider * twoPoint * 1m;

                l0161value1 = onePoint - devider * onePoint * 1.61m;
                l0161value2 = twoPoint - devider * twoPoint * 1.61m;

                l0261value1 = onePoint - devider * onePoint * 2.61m;
                l0261value2 = twoPoint - devider * twoPoint * 2.61m;

                l0423value1 = onePoint - devider * onePoint * 4.23m;
                l0423value2 = twoPoint - devider * twoPoint * 4.23m;
            }



            // 2 расс


            ChartAlertLine oneLine = AlertLineCreate(onePoint, twoPoint, oneNumber, twoPNumber, candles);

            ChartAlertLine l023Line = AlertLineCreate(l023value1, l023value2, oneNumber, twoPNumber, candles);

            ChartAlertLine l038Line = AlertLineCreate(l038value1, l038value2, oneNumber, twoPNumber, candles);

            ChartAlertLine l050Line = AlertLineCreate(l050value1, l050value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l061Line = AlertLineCreate(l061value1, l061value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l076Line = AlertLineCreate(l076value1, l076value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l100Line = AlertLineCreate(l0100value1, l0100value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l161Line = AlertLineCreate(l0161value1, l0161value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l261Line = AlertLineCreate(l0261value1, l0261value2, oneNumber, twoPNumber, candles);
            ChartAlertLine l423Line = AlertLineCreate(l0423value1, l0423value2, oneNumber, twoPNumber, candles);

            ChartAlertLine[] alertLines = new ChartAlertLine[10];

            alertLines[0] = oneLine;
            alertLines[1] = l023Line;
            alertLines[2] = l038Line;
            alertLines[3] = l050Line;
            alertLines[4] = l061Line;
            alertLines[5] = l076Line;
            alertLines[6] = l100Line;
            alertLines[7] = l161Line;
            alertLines[8] = l261Line;
            alertLines[9] = l423Line;

            return(alertLines);
        }
예제 #4
0
        /// <summary>
        /// взять Линии для Алерта типа SpeedLine
        /// </summary>
        /// <param name="candles">свечки</param>
        /// <returns>линии</returns>
        private ChartAlertLine[] GetSpeedAlertLines(List <Candle> candles)
        {
            //1) Указываем первую точку
            //2) Указываем вторую точку
            //3) Между точками строиться прямоугольник
            //4) По вертикальному катету накладываем три точки. При этом на восходящем движении отсчет идет снизу вверх: пропорция 0.382______ 0.487_______ 0.618. Проводим через них три линии.

            decimal valueOneClick = _candleOneValue;

            decimal valueTwoClick;

            decimal devider = Convert.ToDecimal(Slider.Value - 100);

            valueTwoClick = _candleTwoValue + _candleTwoValue * Convert.ToDecimal(devider / 1000);

            // 1 если нажаты точки на одной прямой
            if (valueTwoClick == valueOneClick)
            {
                decimal valueOne  = _candleOneValue;
                decimal valueTwo  = _candleTwoValue;
                int     numberOne = _candleOneNumber;
                int     numberTwo = _candleTwoNumber;

                ChartAlertLine[] lines = { AlertLineCreate(valueOne, valueTwo, numberOne, numberTwo, candles) };
                return(lines);
            }

            // 2 находим высоту катета

            decimal highKatet;

            bool isUpSpeedLine;

            if (valueTwoClick > valueOneClick)
            {
                isUpSpeedLine = true;
                highKatet     = valueTwoClick - valueOneClick;
            }
            else
            {
                isUpSpeedLine = false;
                highKatet     = valueOneClick - valueTwoClick;
            }

            // объявляем точки для трёх линий

            decimal firstValueToAllLine  = _candleOneValue;
            int     firstNumberToAllLine = _candleOneNumber;

            int secondNumberToAllLine = _candleTwoNumber;

            decimal oneLineValue;
            decimal twoLineValue;
            decimal threeLineValue;

            if (isUpSpeedLine)
            {
                oneLineValue   = valueOneClick + highKatet * 0.382m;
                twoLineValue   = valueOneClick + highKatet * 0.487m;
                threeLineValue = valueOneClick + highKatet * 0.618m;
            }
            else
            {
                oneLineValue   = valueOneClick - highKatet * 0.382m;
                twoLineValue   = valueOneClick - highKatet * 0.487m;
                threeLineValue = valueOneClick - highKatet * 0.618m;
            }

            ChartAlertLine oneLine = AlertLineCreate(firstValueToAllLine, oneLineValue, firstNumberToAllLine,
                                                     secondNumberToAllLine, candles);

            ChartAlertLine twoLine = AlertLineCreate(firstValueToAllLine, twoLineValue, firstNumberToAllLine,
                                                     secondNumberToAllLine, candles);

            ChartAlertLine treeLine = AlertLineCreate(firstValueToAllLine, threeLineValue, firstNumberToAllLine,
                                                      secondNumberToAllLine, candles);

            ChartAlertLine[] alertLines = { oneLine, twoLine, treeLine };

            return(alertLines);
        }
        /// <summary>
        /// Create line of points
        /// Создать линию из точек
        /// </summary>
        /// <param name="valueOne">first point value/значение первой точки</param>
        /// <param name="valueTwo">second point value/значение второй точки</param>
        /// <param name="numberOne">first point number/номер первой точки</param>
        /// <param name="numberTwo">second point number/номер второй точки</param>
        /// <param name="candles">candles/свечи</param>
        /// <returns>alerts/алерт</returns>
        private ChartAlertLine AlertLineCreate(decimal valueOne, decimal valueTwo, int numberOne, int numberTwo, List <Candle> candles)
        {
            // 2 calculate indicator movement per candlestick on this TF
            // 2 рассчитываем движение индикатора за свечу на данном ТФ

            decimal stepCorner; // how long our line goes by candle //сколько наша линия проходит за свечку

            stepCorner = (valueTwo - valueOne) / (numberTwo - numberOne + 1);
            // 3 now build an array of line values parallel to candlestick array
            // 3 теперь строим массив значений линии параллельный свечному массиву

            decimal[] lineDecimals = new decimal[candles.Count];
            decimal   point        = valueOne;

            lineDecimals[numberOne] = point;

            for (int i = numberOne + 1; i < lineDecimals.Length; i++)
            {
                // running ahead of array.
                // бежим вперёд по массиву
                lineDecimals[i] = point;
                point          += stepCorner;
            }

            point = valueOne;
            for (int i = numberOne - 1; i > -1; i--)
            {
                // running backwards through array.
                // бежим назад по массиву
                lineDecimals[i] = point;
                point          -= stepCorner;
            }
            // 4 find nearest one from the beginning of hour and the next one after it.
            // 4 находим ближайший от начала час  и следующий за ним

            int firstHourCandle = -1;

            int secondHourCandle = -1;

            int nowHour = candles[candles.Count - 1].TimeStart.Hour;

            for (int i = candles.Count - 1; i > -1; i--)
            {
                if (nowHour != candles[i].TimeStart.Hour)
                {
                    nowHour = candles[i].TimeStart.Hour;

                    if (firstHourCandle == -1)
                    {
                        firstHourCandle = i + 1;
                    }
                    else
                    {
                        secondHourCandle = i + 1;
                        break;
                    }
                }
            }
            // 6 calculate real position of alert. In hours.
            // 6 рассчитываем реальное положение алерта. В часах.

            if (secondHourCandle < 0 ||
                firstHourCandle < 0)
            {
                return(null);
            }

            DateTime startTime = candles[secondHourCandle].TimeStart;
            DateTime endTime   = candles[firstHourCandle].TimeStart;

            decimal startPoint = lineDecimals[secondHourCandle];
            decimal endPoint   = lineDecimals[firstHourCandle];
            // 5 Then calculate line value of first and second hour
            // 5 далее рассчитываем значение линии на первом и втором часе

            ChartAlertLine line = new ChartAlertLine();

            line.TimeFirstPoint  = startTime;
            line.ValueFirstPoint = startPoint;

            line.TimeSecondPoint  = endTime;
            line.ValueSecondPoint = endPoint;

            return(line);
        }
        /// <summary>
        /// take Line for Alert type SpeedLine
        /// взять Линии для Алерта типа SpeedLine
        /// </summary>
        /// <param name="candles">candles/свечки</param>
        /// <returns>lines/линии</returns>
        private ChartAlertLine[] GetSpeedAlertLines(List <Candle> candles)
        {
            //1) Specify first point/Указываем первую точку
            //2) Specify second point/Указываем вторую точку
            //3) Rectangle built between points/Между точками строиться прямоугольник
            //4) Vertical catheter is overlaid with three dots. At same time, on ascending movement, countdown from bottom to top: proportion 0.382______ 0.487_______ 0.618. We draw three lines through them.
            //4) По вертикальному катету накладываем три точки. При этом на восходящем движении отсчет идет снизу вверх: пропорция 0.382______ 0.487_______ 0.618. Проводим через них три линии.

            decimal valueOneClick = _candleOneValue;

            decimal valueTwoClick;

            decimal devider = Convert.ToDecimal(Slider.Value - 100);

            valueTwoClick = _candleTwoValue + _candleTwoValue * Convert.ToDecimal(devider / 1000);
            // 1 if points are pressed on one straight line
            // 1 если нажаты точки на одной прямой
            if (valueTwoClick == valueOneClick)
            {
                decimal valueOne  = _candleOneValue;
                decimal valueTwo  = _candleTwoValue;
                int     numberOne = _candleOneNumber;
                int     numberTwo = _candleTwoNumber;

                ChartAlertLine[] lines = { AlertLineCreate(valueOne, valueTwo, numberOne, numberTwo, candles) };
                return(lines);
            }
            // 2 find the height of cathetus
            // 2 находим высоту катета

            decimal highKatet;

            bool isUpSpeedLine;

            if (valueTwoClick > valueOneClick)
            {
                isUpSpeedLine = true;
                highKatet     = valueTwoClick - valueOneClick;
            }
            else
            {
                isUpSpeedLine = false;
                highKatet     = valueOneClick - valueTwoClick;
            }
            // declare points for three lines
            // объявляем точки для трёх линий

            decimal firstValueToAllLine  = _candleOneValue;
            int     firstNumberToAllLine = _candleOneNumber;

            int secondNumberToAllLine = _candleTwoNumber;

            decimal oneLineValue;
            decimal twoLineValue;
            decimal threeLineValue;

            if (isUpSpeedLine)
            {
                oneLineValue   = valueOneClick + highKatet * 0.382m;
                twoLineValue   = valueOneClick + highKatet * 0.487m;
                threeLineValue = valueOneClick + highKatet * 0.618m;
            }
            else
            {
                oneLineValue   = valueOneClick - highKatet * 0.382m;
                twoLineValue   = valueOneClick - highKatet * 0.487m;
                threeLineValue = valueOneClick - highKatet * 0.618m;
            }

            ChartAlertLine oneLine = AlertLineCreate(firstValueToAllLine, oneLineValue, firstNumberToAllLine,
                                                     secondNumberToAllLine, candles);

            ChartAlertLine twoLine = AlertLineCreate(firstValueToAllLine, twoLineValue, firstNumberToAllLine,
                                                     secondNumberToAllLine, candles);

            ChartAlertLine treeLine = AlertLineCreate(firstValueToAllLine, threeLineValue, firstNumberToAllLine,
                                                      secondNumberToAllLine, candles);

            ChartAlertLine[] alertLines = { oneLine, twoLine, treeLine };

            return(alertLines);
        }