コード例 #1
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("================================================");
            }
        }
コード例 #2
0
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 0)
            {
                Print("==============");
                smaLine = SMA(SMAPeriod)[0];
                Print("Day middleValot " + middleValot);
                Print("SMA Line -> " + smaLine);

                double procentOfMiddleValot = (middleValot / 100) * ProcentFromMiddleValot;

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

                Print("lowLineRSIAnalog " + lowLineRSIAnalog);
                Print("highLineRSIAnalog " + highLineRSIAnalog);
                Print(Time[0].ToString());


                OnBarUpdateMain();
                Print(Time[0].ToString());


                //onBarData.PriceVolumeList.AddPriceVolume(priceVolume);
                Print("Count PriceVolume: " + onBarData.PriceVolumeOnBar.VolumePriceOnBar.Count);
                foreach (KeyValuePair <double, double> a in onBarData.PriceVolumeOnBar.VolumePriceOnBar)
                {
                    string priceVolumeText = string.Format("Price: {0}, count: {1}", a.Key, a.Value);
                    Print(priceVolumeText);
                }

                dailyData.OnBarDataList.Add(onBarData);
                priceVolume = new PriceVolume();
                onBarData   = new OnBarData(CurrentBar);
            }

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

                _lastPrice = Price;
                Price      = openPrice;

                StopLossAndTakeProfit(Price);

                double volume = Volumes[1][0];
                onBarData.PriceVolumeOnBar.AddPriceVolume(Price, volume);
                double currentVolume = onBarData.PriceVolumeOnBar.VolumePriceOnBar[Price];

                bool isCanInputOrders = false;
                foreach (DailyData dailyData in historyData.DailyDataList)
                {
                    foreach (ZigZagDiapasone zigZag in dailyData.ZigZagDiapasoneList)
                    {
                        double averageVolume = dailyData.GetAveragePriceVolume(5);

                        Print("Price -> " + Price);
                        Print("zigZag.SellLevelWithPostTicks -> " + zigZag.SellLevelWithPostTicks);
                        Print("zigZag.BuyLevelWithPostTicks -> " + zigZag.BuyLevelWithPostTicks);

                        if (Price > zigZag.SellLevelWithPostTicks && Price < zigZag.HighZigZag)
                        {
                            if (currentVolume > averageVolume)
                            {
                                BuyOrSell(Price, _lastPrice, OrderAction.Sell);
                                Print("Test sell");
                            }
                        }
                        else
                        if (Price < zigZag.BuyLevelWithPostTicks && Price > zigZag.LowZigZag)
                        {
                            if (currentVolume > averageVolume)
                            {
                                BuyOrSell(Price, _lastPrice, OrderAction.Buy);
                                Print("Test buy");
                            }
                        }
                    }
                }

                //historyData.ZigZagDiapasoneList[1].
            }

            if (BarsInProgress == 2)
            {
                historyData.AddDaylyZigZag(dailyData);

                int count = dailyData.ZigZagDiapasoneList.Count;

                for (int i = 0; i < count; i++)
                {
                    Print("Level by Day ->   Index: " + i + " Sell Level: " + dailyData.ZigZagDiapasoneList[i].SellLevel + " Buy Level: " + dailyData.ZigZagDiapasoneList[i].BuyLevel);
                }


                dailyData = new DailyData(Time[0]);

                middleValot = 0;

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