Ejemplo n.º 1
0
        private void OnBarUpdateMain()
        {
            Print("-------------------");

            ZigZagUpdateOnBar();

            if (lowBarPeriod == 0 || highBarPeriod == 0)
            {
                return;
            }

            if (highBarPeriod > lowBarPeriod)
            {
                isTrendOnPeriodDown = false;
                startBar            = lowBarPeriod - 1 - LeftZigZag;
                endBar = highBarPeriod - 1 + RightZigZag;
            }
            else
            {
                isTrendOnPeriodDown = true;
                startBar            = highBarPeriod - 1 - LeftZigZag;
                endBar = lowBarPeriod - 1 + RightZigZag;
            }
            periodOfCalculate = endBar - startBar;

            if (startBar < endBar && isChangePeriod)
            {
                sellLevelPrice = GetLowOrHighPriceOfBar(true, startBar, endBar);
                buyLevelPrice  = GetLowOrHighPriceOfBar(false, startBar, endBar);

                zigZagDiapasone.BuyLevel   = buyLevelPrice;
                zigZagDiapasone.SellLevel  = sellLevelPrice;
                zigZagDiapasone.LowZigZag  = lowZigZagPrice;
                zigZagDiapasone.HighZigZag = highZigZagPrice;


                Print("zigZagDiapasone.BuyLevel " + zigZagDiapasone.BuyLevel);
                Print("zigZagDiapasone.SellLevel " + zigZagDiapasone.SellLevel);
                Print("zigZagDiapasone.LowZigZag " + zigZagDiapasone.LowZigZag);
                Print("zigZagDiapasone.HighZigZag " + zigZagDiapasone.HighZigZag);

                dailyData.ZigZagDiapasoneList.Add(zigZagDiapasone);

                zigZagDiapasone = new ZigZagDiapasone(5);

                isChangePeriod = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;

            //zigzag
            zigZagHighSeries  = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagHighZigZags = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagLowSeries   = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagLowZigZags  = new DataSeries(this, MaximumBarsLookBack.Infinite);

            Add(PeriodType.Tick, 1);
            Add(PeriodType.Day, 1);

            historyData     = new HistoryData(SaveZigZagDaysOnHistory);
            dailyData       = new DailyData(Time[0]);
            zigZagDiapasone = new ZigZagDiapasone(5);
            onBarData       = new OnBarData(0);
            priceVolume     = new PriceVolume();
        }
Ejemplo n.º 3
0
        protected override void OnStartUp()
        {
            //zigzag
            zigZagHighSeries  = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagHighZigZags = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagLowSeries   = new DataSeries(this, MaximumBarsLookBack.Infinite);
            zigZagLowZigZags  = new DataSeries(this, MaximumBarsLookBack.Infinite);


            historyData = new HistoryData(SaveZigZagDaysOnHistory);

            dailyData       = new DailyData(Time[0]);
            zigZagDiapasone = new ZigZagDiapasone(AddTicksForOrderLevel * TickSize, CurrentBars[0]);
            barData         = new BarData(0, Time[0]);



            //Log
            logger = new Logger(LogType.Console, IsLogEnabled);
        }
Ejemplo n.º 4
0
 public void AddZigZagDiapasone(ZigZagDiapasone zigZagDiapasone)
 {
     ZigZagDiapasoneList.Add(zigZagDiapasone);
 }
Ejemplo n.º 5
0
        private void EnterOrders(string order1, string order2, double price, double previousPrice, OrderAction orderAction, ZigZagDiapasone zigZag)
        {
            Log("Текущая цена: " + price);
            Log("Предыдущая цена: " + previousPrice);

            {
                if (orderAction == OrderAction.BUY)
                {
                    EnterLong(order1);
                    EnterLong(order2);

                    Log("OrderAction.Buy");

                    isBuyOrder = true;

                    Log(zigZag.ToString(OrderAction.BUY));
                    zigZag.BuyZigZagDiapasone.DeleteZigZagDiapasone();
                    Log(zigZag.ToString(OrderAction.BUY));
                }
                else if (orderAction == OrderAction.SELL)
                {
                    EnterShort(order1);
                    EnterShort(order2);

                    Log("OrderAction.Sell");

                    isSellOrder = true;

                    Log(zigZag.ToString(OrderAction.SELL));
                    zigZag.SellZigZagDiapasone.DeleteZigZagDiapasone();
                    Log(zigZag.ToString(OrderAction.SELL));
                }

                startOrderPrice = price;


                SetProfitTarget(order1, CalculationMode.Ticks, ProfitTargetLarge);
                SetProfitTarget(order2, CalculationMode.Ticks, ProfitTargetSmall);
                SetStopLoss(order1, CalculationMode.Ticks, StopLoss, false);
                SetStopLoss(order2, CalculationMode.Ticks, StopLoss, false);
            }
        }
Ejemplo n.º 6
0
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < 5 && CurrentBars[1] < 5 && CurrentBars[2] < 5)
            {
                //	return;
            }


            if (BarsInProgress == 0)
            {
                indexBar = CurrentBars[0];

                previousLowBarApex  = Lows[0][0];
                previousHighBarApex = Highs[0][0];
                Log("CurrentBar -> " + indexBar);

                ZigZagUpdateOnBar();
                if (lowBarPeriod == 0 || highBarPeriod == 0)
                {
                    return;
                }

                Log("==================================================");
                Log("------Старт Обработки дефолтного таймфрейма-------");
                smaLine = SMA(SMAPeriod)[0];
                Log("Дневная валотильность: " + middleValot);
                Log("Текущая цена SMA линии -> " + smaLine);

                double procentOfMiddleValot = middleValot * ProcentFromMiddleValot / 100;

                lowLineRSIAnalog  = smaLine - procentOfMiddleValot;
                highLineRSIAnalog = smaLine + procentOfMiddleValot;

                Log("Уровень RSIA на покупку: " + lowLineRSIAnalog);
                Log("Уровень RSIA на продажу: " + highLineRSIAnalog);



                if (highBarPeriod > lowBarPeriod)
                {
                    isTrendOnPeriodDown = false;
                    startBar            = lowBarPeriod - 1 - LeftZigZag;
                    endBar = highBarPeriod - 1 + RightZigZag;
                }
                else
                {
                    isTrendOnPeriodDown = true;
                    startBar            = highBarPeriod - 1 - LeftZigZag;
                    endBar = lowBarPeriod - 1 + RightZigZag;
                }


                if (startBar < endBar && isChangePeriod)
                {
                    sellLevelPrice = GetLowOrHighPriceOfBar(true, startBar, endBar);
                    buyLevelPrice  = GetLowOrHighPriceOfBar(false, startBar, endBar);


                    zigZagDiapasone.AddedDateTime                  = Time[0];
                    zigZagDiapasone.BuyZigZagDiapasone.Level       = buyLevelPrice;
                    zigZagDiapasone.SellZigZagDiapasone.Level      = sellLevelPrice;
                    zigZagDiapasone.BuyZigZagDiapasone.ZigZagApex  = lowZigZagPrice;
                    zigZagDiapasone.SellZigZagDiapasone.ZigZagApex = highZigZagPrice;
                    zigZagDiapasone.HighApexPrice                  = Highs[0][CurrentBars[0] - highBarPeriod + 1];
                    zigZagDiapasone.LowApexPrice = Lows[0][CurrentBars[0] - lowBarPeriod + 1];

                    Log(zigZagDiapasone.ToString());

                    if (IsChangePriceAfterLastZigZagApexEnabled)
                    {
                        lastCompletedZigZagApexPriceDistance = 0;
                        int zigZagIndex = 0;
                        foreach (DailyData day in historyData.DailyDataList.Reverse <DailyData>())
                        {
                            foreach (ZigZagDiapasone zigZag in day.ZigZagDiapasoneList.Reverse <ZigZagDiapasone>())
                            {
                                if (zigZagIndex <= ChangePriceAfterZigZagCount)
                                {
                                    lastCompletedZigZagApexPriceDistance = lastCompletedZigZagApexPriceDistance + zigZag.DifferenceBetweenApex;
                                    zigZagIndex++;
                                    Log("zigZag.DifferenceBetweenApex -> " + zigZag.DifferenceBetweenApex);
                                }
                                else
                                {
                                    break;
                                    break;
                                }
                            }
                        }

                        Log("lastCompletedZigZagApexPriceDistance -> " + lastCompletedZigZagApexPriceDistance);
                        Log("zigZagIndex -> " + zigZagIndex.ToString());
                        lastCompletedZigZagApexPriceDistance = lastCompletedZigZagApexPriceDistance / zigZagIndex;
                        Log("lastCompletedZigZagApexPriceDistance after-> " + lastCompletedZigZagApexPriceDistance);

                        if (isTrendOnPeriodDown)
                        {
                            lastApexPrice = zigZagDiapasone.HighApexPrice;
                        }
                        else if (!isTrendOnPeriodDown)
                        {
                            lastApexPrice = zigZagDiapasone.LowApexPrice;
                        }
                    }


                    Log("Добавлен новый уровень на покупку: " + zigZagDiapasone.ToString(OrderAction.BUY));
                    Log("Добавлен новый уровень на продажу: " + zigZagDiapasone.ToString(OrderAction.SELL));

                    dailyData.AddZigZagDiapasone(zigZagDiapasone);

                    zigZagDiapasone = new ZigZagDiapasone(AddTicksForOrderLevel * TickSize, CurrentBars[0]);

                    isChangePeriod = false;
                }


                Log("Текущие уровни для входа в сделки: " + dailyData.ZigZagDiapasoneList.Count);
                foreach (DailyData daily in historyData.DailyDataList)
                {
                    foreach (ZigZagDiapasone zigzag in daily.ZigZagDiapasoneList)
                    {
                        Log(zigzag.ToString());
                    }
                }
                dailyData.OnBarDataList.Add(barData);


                barData = new BarData(CurrentBar, Time[0]);


                Log("------Конец Обработки дефолтного таймфрейма-------");
                Log(Time[0].ToString());
                Log("==================================================");
            }

            if (BarsInProgress == 1)
            {
                double openPrice = Opens[1][0];

                _previousPrice = _price;
                _price         = openPrice;

                BuyOrSell(_price, _previousPrice, CurrentBars[0]);
            }

            if (BarsInProgress == 2)
            {
                Log("================================================");
                Log("------Старт Обработки Дневного таймфрейма-------");

                historyData.AddDaylyZigZag(dailyData);

                Log("Дней сохранено в истории: " + historyData.DailyDataList.Count);

                middleValot = 0;
                for (int i = 0; i < DayOfSMAValot; i++)
                {
                    middleValot = middleValot + Highs[2][i] - Lows[2][i];
                }
                middleValot = middleValot / DayOfSMAValot;

                dailyData = new DailyData(Time[0]);

                Log("Дневная валотильность: " + middleValot);
                Log("------Конец Обработки Дневного таймфрейма-------");
                Log(Time[0].ToString());
                Log("================================================");
            }
        }