コード例 #1
0
 private double GetCloseOrHighLow(DowPivotOld _dp, TrendDir trendDir, int _barsAgo)
 {
     if (trendDir == TrendDir.Down)
     {
         if (_dp.UseHighLow)
         {
             return(_dp.Low[_barsAgo]);
         }
         else
         {
             return(_dp.Close[_barsAgo]);
         }
     }
     else if (trendDir == TrendDir.Up)
     {
         if (_dp.UseHighLow)
         {
             return(_dp.High[_barsAgo]);
         }
         else
         {
             return(_dp.Close[_barsAgo]);
         }
     }
     return(0);
 }
コード例 #2
0
        private void PrintPoint(DowPivotOld dowPivot)
        {
            if (!dowPivot.DrawProp.ShowTopBottomPoints)
            {
                return;
            }
            switch (trendDir)
            {
            case TrendDir.Down:
                Draw.Dot(dowPivot, (trendDir + " Dot " + PointIndex.ToString()), true,
                         Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, BarIndex),
                         Price, Brushes.Red).OutlineBrush = Brushes.Transparent;

                Draw.Text(dowPivot, trendDir + " Text " + PointIndex.ToString(), true, PointIndex.ToString(),
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, BarIndex),
                          Price, -15, Brushes.White,
                          new Gui.Tools.SimpleFont("Arial", 11),
                          System.Windows.TextAlignment.Center,
                          Brushes.Transparent, Brushes.Transparent, 100);
                break;

            case TrendDir.Up:
                Draw.Dot(dowPivot, (trendDir + " Dot " + PointIndex.ToString()), true,
                         Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, BarIndex),
                         Price, Brushes.Green).OutlineBrush = Brushes.Transparent;

                Draw.Text(dowPivot, trendDir + " Text " + PointIndex.ToString(), true, PointIndex.ToString(),
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, BarIndex),
                          Price, 15, Brushes.White,
                          new Gui.Tools.SimpleFont("Arial", 11),
                          System.Windows.TextAlignment.Center,
                          Brushes.Transparent, Brushes.Transparent, 100);
                break;
            }
        }
コード例 #3
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
        protected ZigZag(DowPivotOld dowPivot)
        {
            lows  = new List <HighLowPoint>();
            highs = new List <HighLowPoint>();

            this.dowPivot = dowPivot;
            PointCount    = 0;
        }
コード例 #4
0
 public HighLowPoint(DowPivotOld dowPivot, double price, int barIndex, int pointIndex, TrendDir trendDir)
 {
     this.Price      = price;
     this.BarIndex   = barIndex;
     this.PointIndex = pointIndex;
     this.trendDir   = trendDir;
     PrintPoint(dowPivot);
 }
コード例 #5
0
        public SwingForwardCalculationOld(DowPivotOld dowPivot) : base(dowPivot)
        {
            strength = (int)dowPivot.Strength;

            lastLowCache  = new ArrayList();
            lastHighCache = new ArrayList();

            lastTrend = TrendDir.Unknown;
        }
コード例 #6
0
        public SwingDelayedCalculation(DowPivotOld dowPivot) : base(dowPivot)
        {
            strength = (int)dowPivot.Strength;
            constant = (strength * 2) + 1;

            lastLowCache  = new ArrayList();
            lastHighCache = new ArrayList();

            lastTrend = TrendDir.Unknown;
        }
コード例 #7
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
        private void SetPlotBuyOrSell(DowPivotOld dowPivot, TrendDir trendDir)
        {
            switch (trendDir)
            {
            case TrendDir.Down:
                dowPivot.EntrySignal[0] = -1;
                break;

            case TrendDir.Up:
                dowPivot.EntrySignal[0] = 1;
                break;

            case TrendDir.Unknown:
                dowPivot.EntrySignal[0] = 0;
                break;
            }
        }
コード例 #8
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
        private void SetProfitTargetPrice(DowPivotOld dowPivot, PivotPoint pp, TrendDir trendDir)
        {
            if (dowPivot.ShowTargetAndStop)
            {
                // Set where will be drawn the finish target line
                const int endLine = -4;
                switch (trendDir)
                {
                case TrendDir.Down:
                    double nDown = pp.SecondHigh.Price - pp.FirstLow.Price < 0 ?
                                   (pp.SecondHigh.Price - pp.FirstLow.Price) * -1 :
                                   pp.SecondHigh.Price - pp.FirstLow.Price;
                    double downTarget = (dowPivot.PercentProfitTargetFibo / 100) * nDown;

                    downTarget -= pp.SecondHigh.Price;
                    downTarget *= -1;     // Inverte valor negativo para positivo

                    Draw.Line(dowPivot, dowPivot.CurrentBar.ToString(), false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, pp.FirstLow.BarIndex),
                              downTarget, endLine, downTarget, Brushes.Red, DashStyleHelper.Solid, 2);

                    dowPivot.ProfitTargetPriceSignal[0] = downTarget;
                    break;

                case TrendDir.Up:
                    double nUp = pp.SecondLow.Price - pp.FirstHigh.Price < 0 ?
                                 (pp.SecondLow.Price - pp.FirstHigh.Price) * -1 :
                                 pp.SecondLow.Price - pp.FirstHigh.Price;
                    double upTarget = (dowPivot.PercentProfitTargetFibo / 100) * nUp;

                    upTarget += pp.SecondLow.Price;

                    Draw.Line(dowPivot, dowPivot.CurrentBar.ToString(), false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, pp.FirstHigh.BarIndex),
                              upTarget, endLine, upTarget, Brushes.Green, DashStyleHelper.Solid, 2);

                    dowPivot.ProfitTargetPriceSignal[0] = upTarget;
                    break;

                case TrendDir.Unknown:
                    dowPivot.ProfitTargetPriceSignal[0] = dowPivot.Input[0];
                    break;
                }
            }
        }
コード例 #9
0
        public override void Calculate(DowPivotOld dowPivot)
        {
            //Calculation
            isFalling = GetCloseOrHighLow(dowPivot, TrendDir.Down, 0) < GetCloseOrHighLow(dowPivot, TrendDir.Down, 0 + 1);
            isRising  = GetCloseOrHighLow(dowPivot, TrendDir.Up, 0) > GetCloseOrHighLow(dowPivot, TrendDir.Up, 0 + 1);

            isOverLowPipDiff  = GetCloseOrHighLow(dowPivot, TrendDir.Down, 0) <= (GetHigh(0).Price - (dowPivot.Strength * (dowPivot.TickSize * 10)));
            isOverHighPipDiff = GetCloseOrHighLow(dowPivot, TrendDir.Up, 0) >= (GetLow(0).Price + (dowPivot.Strength * (dowPivot.TickSize * 10)));

            // Add low
            if (isFirstLowValue && isFalling && isOverLowPipDiff)
            {
                AddLow(dowPivot, GetCloseOrHighLow(dowPivot, TrendDir.Down, 0), dowPivot.CurrentBar);

                lastPrice = GetLow(0).Price;

                isFirstLowValue  = false;
                isFirstHighValue = true;
            }
            //Add high
            else if (isFirstHighValue && isRising && isOverHighPipDiff)
            {
                AddHigh(dowPivot, GetCloseOrHighLow(dowPivot, TrendDir.Up, 0), dowPivot.CurrentBar);

                lastPrice = GetHigh(0).Price;

                isFirstLowValue  = true;
                isFirstHighValue = false;
            }
            // Update low
            if (!isFirstLowValue && isFalling && isOverLowPipDiff && GetCloseOrHighLow(dowPivot, TrendDir.Down, 0) < lastPrice)
            {
                UpdateLow(dowPivot, GetCloseOrHighLow(dowPivot, TrendDir.Down, 0), dowPivot.CurrentBar);
                lastPrice = GetLow(0).Price;
            }
            // Update high
            else if (!isFirstHighValue && isRising && isOverHighPipDiff && GetCloseOrHighLow(dowPivot, TrendDir.Up, 0) > lastPrice)
            {
                UpdateHigh(dowPivot, GetCloseOrHighLow(dowPivot, TrendDir.Up, 0), dowPivot.CurrentBar);
                lastPrice = GetHigh(0).Price;
            }
        }
コード例 #10
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
        private void PrintPivots(DowPivotOld dowPivot, Situation state)
        {
            line1 = "Line 1 " + dowPivot.CurrentBar;
            line2 = "Line 2 " + dowPivot.CurrentBar;

            switch (state)
            {
            case Situation.AddHigh:
                lastHighLegTagLine3 = "Line 3 " + dowPivot.CurrentBar;
                Draw.Line(dowPivot, line1, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.FirstLow.BarIndex), high.FirstLow.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.FirstHigh.BarIndex), high.FirstHigh.Price, Brushes.Green, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                Draw.Line(dowPivot, line2, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.FirstHigh.BarIndex), high.FirstHigh.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.SecondLow.BarIndex), high.SecondLow.Price, Brushes.Green, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                Draw.Line(dowPivot, lastHighLegTagLine3, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.SecondLow.BarIndex), high.SecondLow.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.SecondHigh.BarIndex), high.SecondHigh.Price, Brushes.Green, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                break;

            case Situation.AddLow:
                lastLowLegTagLine3 = "Line 3 " + dowPivot.CurrentBar;
                Draw.Line(dowPivot, line1, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.FirstHigh.BarIndex), low.FirstHigh.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.FirstLow.BarIndex), low.FirstLow.Price, Brushes.Red, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                Draw.Line(dowPivot, line2, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.FirstLow.BarIndex), low.FirstLow.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.SecondHigh.BarIndex), low.SecondHigh.Price, Brushes.Red, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                Draw.Line(dowPivot, lastLowLegTagLine3, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.SecondHigh.BarIndex), low.SecondHigh.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.SecondLow.BarIndex), low.SecondLow.Price, Brushes.Red, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                break;

            case Situation.UpdateHigh:
                Draw.Line(dowPivot, lastHighLegTagLine3, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.SecondLow.BarIndex), high.SecondLow.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, high.SecondHigh.BarIndex), high.SecondHigh.Price, Brushes.Green, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                break;

            case Situation.UpdateLow:
                Draw.Line(dowPivot, lastLowLegTagLine3, false, Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.SecondHigh.BarIndex), low.SecondHigh.Price,
                          Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, low.SecondLow.BarIndex), low.SecondLow.Price, Brushes.Red, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                break;
            }
        }
コード例 #11
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
        private void PrintZigZagLines(DowPivotOld dowPivot, Situation situation)
        {
            if (lows.Count != 0 && highs.Count != 0 && dowPivot.DrawProp.ShowZigZag)
            {
                switch (situation)
                {
                case Situation.AddLow:
                    lowTagName = "Low line" + dowPivot.CurrentBar;
                    Draw.Line(dowPivot, lowTagName, false,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetHigh(0).BarIndex), GetHigh(0).Price,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetLow(0).BarIndex), GetLow(0).Price,
                              dowPivot.DrawProp.ZigZagColor, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                    break;

                case Situation.AddHigh:
                    highTagName = "High line" + dowPivot.CurrentBar;
                    Draw.Line(dowPivot, highTagName, false,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetLow(0).BarIndex), GetLow(0).Price,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetHigh(0).BarIndex), GetHigh(0).Price,
                              dowPivot.DrawProp.ZigZagColor, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                    break;

                case Situation.UpdateLow:
                    Draw.Line(dowPivot, lowTagName, false,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetHigh(0).BarIndex), GetHigh(0).Price,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetLow(0).BarIndex), GetLow(0).Price,
                              dowPivot.DrawProp.ZigZagColor, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                    break;

                case Situation.UpdateHigh:
                    Draw.Line(dowPivot, highTagName, false,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetLow(0).BarIndex), GetLow(0).Price,
                              Miscellaneous.ConvertBarIndexToBarsAgo(dowPivot, GetHigh(0).BarIndex), GetHigh(0).Price,
                              dowPivot.DrawProp.ZigZagColor, DashStyleHelper.Solid, dowPivot.DrawProp.ZigZagWidth);
                    break;
                }
            }
        }
コード例 #12
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
        private bool IsOverMinPercentPivotRetracement(DowPivotOld dowPivot, TrendDir trendDir, PivotPoint pp)
        {
            switch (trendDir)
            {
            case TrendDir.Down:
                double nDown = pp.FirstHigh.Price - pp.FirstLow.Price < 0 ?
                               (pp.FirstHigh.Price - pp.FirstLow.Price) * -1 :
                               pp.FirstHigh.Price - pp.FirstLow.Price;
                double downLimit = (dowPivot.FiboPivot.MinPercentOfPivotRetraction / 100) * nDown;

                downLimit += pp.FirstLow.Price;

                if (pp.SecondHigh.Price < downLimit)
                {
                    return(true);
                }

                break;

            case TrendDir.Up:
                double nUp = pp.FirstLow.Price - pp.FirstHigh.Price < 0 ?
                             (pp.FirstLow.Price - pp.FirstHigh.Price) * -1 :
                             pp.FirstLow.Price - pp.FirstHigh.Price;

                double upLimite = (dowPivot.FiboPivot.MinPercentOfPivotRetraction / 100) * nUp;

                upLimite -= pp.FirstHigh.Price;
                upLimite *= -1;     // Inverte valor negativo para positivo

                if (pp.SecondLow.Price > upLimite)
                {
                    return(true);
                }

                break;
            }
            return(false);
        }
コード例 #13
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
 protected void UpdateHigh(DowPivotOld dowPivot, double price, int barIndex)
 {
     highs[highs.Count - 1].Update(dowPivot, price, barIndex);
     PrintZigZagLines(dowPivot, Situation.UpdateHigh);
 }
コード例 #14
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
 protected void UpdateLow(DowPivotOld dowPivot, double price, int barIndex)
 {
     lows[lows.Count - 1].Update(dowPivot, price, barIndex);
     PrintZigZagLines(dowPivot, Situation.UpdateLow);
 }
コード例 #15
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
 protected void AddHigh(DowPivotOld dowPivot, double price, int barIndex)
 {
     highs.Add(new HighLowPoint(dowPivot, price, barIndex, PointCount, TrendDir.Up));
     PrintZigZagLines(dowPivot, Situation.AddHigh);
     PointCount++;
 }
コード例 #16
0
 public SwingForwardCalculationNew(DowPivotOld dowPivot) : base(dowPivot)
 {
     strength  = (int)dowPivot.Strength;
     lastTrend = TrendDir.Unknown;
 }
コード例 #17
0
 public static void PrintError(DowPivotOld dowPivot, string text)
 {
     Draw.TextFixed(dowPivot, "Error debug", text, TextPosition.BottomRight);
 }
コード例 #18
0
 public static double GetClosrOrHigh(DowPivotOld dowPivot)
 {
     return(dowPivot.UseHighLow ? dowPivot.High[0] : dowPivot.Close[0]);
 }
コード例 #19
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
 private void SetStopLossPrice(DowPivotOld dowPivot, double price)
 {
     dowPivot.StopLossPriceSignal[0] = price;
 }
コード例 #20
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
 public PivotLogic(DowPivotOld dowPivot)
 {
     SetStopLossPrice(dowPivot, dowPivot.Input[0]);                // Initiate
     SetProfitTargetPrice(dowPivot, currentPP, TrendDir.Unknown);  // Initiate
     SetPlotBuyOrSell(dowPivot, TrendDir.Unknown);                 // Set signal to 0 before a entry
 }
コード例 #21
0
 public void Update(DowPivotOld dowPivot, double price, int barIndex)
 {
     Price    = price;
     BarIndex = barIndex;
     PrintPoint(dowPivot);
 }
コード例 #22
0
        public override void Calculate(DowPivotOld dowPivot)
        {
            ISeries <double> lows;
            ISeries <double> highs;

            if (dowPivot.UseHighLow)
            {
                lows  = dowPivot.Low;
                highs = dowPivot.High;
            }
            else
            {
                lows  = dowPivot.Close;
                highs = dowPivot.Close;
            }

            #region Calcula primeiro ponto
            // Este laço faz o calculo das primeiras barras do gráfico
            if (dowPivot.IsFirstTickOfBar && GetHigh(0) == null && GetLow(0) == null)
            {
                initLowCache.Add(new HighLowAndIndex(lows[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant));
                initHighCache.Add(new HighLowAndIndex(highs[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant));

                HighLowAndIndex lowCandidate  = initLowCache[0];
                HighLowAndIndex highCandidate = initHighCache[0];

                if (initLowCache.Count - 1 >= strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (initLowCache[i].Price < lowCandidate.Price)
                        {
                            lowCandidate = initLowCache[i];
                        }
                    }
                }

                if (initHighCache.Count - 1 >= strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (initHighCache[i].Price > highCandidate.Price)
                        {
                            highCandidate = initHighCache[i];
                        }
                    }
                }

                if (initLowCache.Count - 1 >= strength && initHighCache.Count - 1 >= strength)
                {
                    if (lowCandidate.Index < highCandidate.Index)
                    {
                        AddLow(dowPivot, lowCandidate.Price, lowCandidate.Index);
                        lastTrend         = TrendDir.Down;
                        calculationEstate = CalculationEstate.HistoricalRealTime;
                    }
                    else if (lowCandidate.Index > highCandidate.Index)
                    {
                        AddHigh(dowPivot, highCandidate.Price, highCandidate.Index);
                        lastTrend         = TrendDir.Up;
                        calculationEstate = CalculationEstate.HistoricalRealTime;
                    }
                    else
                    {
                        Miscellaneous.PrintError(dowPivot, "In the initial calculation of the 'Low' and 'High', they have the same index," +
                                                 " Low index: " + lowCandidate.Index + "    High index: " + highCandidate.Index);
                    }
                }
            }
            #endregion

            #region Calcula dados históricos e de tempo real
            else if (dowPivot.IsFirstTickOfBar && calculationEstate == CalculationEstate.HistoricalRealTime)
            {
                bool isSwingLow  = lows[barsAgoConstant] < lows[1 + barsAgoConstant];
                bool isSwingHigh = highs[barsAgoConstant] > highs[1 + barsAgoConstant];

                if (isSwingLow)
                {
                    for (int i = 1; i < strength + 1; i++)
                    {
                        if (lows[barsAgoConstant] > lows[i + barsAgoConstant])
                        {
                            isSwingLow = false;
                            break;
                        }
                    }
                }

                if (isSwingHigh)
                {
                    for (int i = 1; i < strength + 1; i++)
                    {
                        if (highs[barsAgoConstant] < highs[i + barsAgoConstant])
                        {
                            isSwingHigh = false;
                            break;
                        }
                    }
                }

                #region CRUD
                // Add low
                if (isSwingLow && lastTrend != TrendDir.Down)
                {
                    AddLow(dowPivot, lows[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant);
                    lastLow   = lows[barsAgoConstant];
                    lastTrend = TrendDir.Down;
                }
                // Add high
                else if (isSwingHigh && lastTrend != TrendDir.Up)
                {
                    AddHigh(dowPivot, highs[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant);
                    lastHigh  = highs[barsAgoConstant];
                    lastTrend = TrendDir.Up;
                }
                // Update Low
                else if (isSwingLow && lastTrend == TrendDir.Down && lows[barsAgoConstant] < lastLow)
                {
                    UpdateLow(dowPivot, lows[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant);
                    lastLow = lows[barsAgoConstant];
                }
                // Update High
                else if (isSwingHigh && lastTrend == TrendDir.Up && highs[barsAgoConstant] > lastHigh)
                {
                    UpdateHigh(dowPivot, highs[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant);
                    lastHigh = highs[barsAgoConstant];
                }
                #endregion
            }
            #endregion
        }
コード例 #23
0
        public override void Calculate(DowPivotOld dowPivot)
        {
            // Enter only once per bar
            if (dowPivot.IsFirstTickOfBar)
            {
                bool   isSwingLow              = false;
                bool   isSwingHigh             = false;
                double swingLowCandidateValue  = 0;
                double swingHighCandidateValue = 0;

                lastLowCache.Add(dowPivot.Low[0 + barsAgoConstant]);
                if (lastLowCache.Count > constant)
                {
                    lastLowCache.RemoveAt(0);
                }

                lastHighCache.Add(dowPivot.High[0 + barsAgoConstant]);
                if (lastHighCache.Count > constant)
                {
                    lastHighCache.RemoveAt(0);
                }

                // Low calculations
                if (lastLowCache.Count == constant)
                {
                    isSwingLow             = true;
                    swingLowCandidateValue = (double)lastLowCache[strength];

                    for (int i = 0; i < dowPivot.Strength; i++)
                    {
                        if (((double)lastLowCache[i]).ApproxCompare(swingLowCandidateValue) <= 0)
                        {
                            isSwingLow = false;
                        }
                    }

                    for (int i = strength + 1; i < lastLowCache.Count; i++)
                    {
                        if (((double)lastLowCache[i]).ApproxCompare(swingLowCandidateValue) < 0)
                        {
                            isSwingLow = false;
                        }
                    }
                }

                // High calculations
                if (lastHighCache.Count == constant)
                {
                    isSwingHigh             = true;
                    swingHighCandidateValue = (double)lastHighCache[strength];

                    for (int i = 0; i < strength; i++)
                    {
                        if (((double)lastHighCache[i]).ApproxCompare(swingHighCandidateValue) >= 0)
                        {
                            isSwingHigh = false;
                        }
                    }

                    for (int i = strength + 1; i < lastHighCache.Count; i++)
                    {
                        if (((double)lastHighCache[i]).ApproxCompare(swingHighCandidateValue) > 0)
                        {
                            isSwingHigh = false;
                        }
                    }
                }

                // Add low
                if (isSwingLow && lastTrend != TrendDir.Down)
                {
                    AddLow(dowPivot, swingLowCandidateValue, (dowPivot.CurrentBar - strength) - barsAgoConstant);
                    lastLow   = swingLowCandidateValue;
                    lastTrend = TrendDir.Down;
                }
                // Add high
                if (isSwingHigh && lastTrend != TrendDir.Up)
                {
                    AddHigh(dowPivot, swingHighCandidateValue, (dowPivot.CurrentBar - strength) - barsAgoConstant);
                    lastHigh  = swingHighCandidateValue;
                    lastTrend = TrendDir.Up;
                }
                // Update low
                if (isSwingLow && lastTrend == TrendDir.Down && swingLowCandidateValue < lastLow)
                {
                    UpdateLow(dowPivot, swingLowCandidateValue, (dowPivot.CurrentBar - strength) - barsAgoConstant);
                    lastLow = swingLowCandidateValue;
                }
                // Update high
                if (isSwingHigh && lastTrend == TrendDir.Up && swingHighCandidateValue > lastHigh)
                {
                    UpdateHigh(dowPivot, swingHighCandidateValue, (dowPivot.CurrentBar - strength) - barsAgoConstant);
                    lastHigh = swingHighCandidateValue;
                }
            }
        }
コード例 #24
0
 // Convert number index bar to bars ago
 public static int ConvertBarIndexToBarsAgo(DowPivotOld dowPivot, int barIndex)
 {
     return(((barIndex - dowPivot.CurrentBar) < 0) ? ((barIndex - dowPivot.CurrentBar) * -1) : (barIndex - dowPivot.CurrentBar));
 }
コード例 #25
0
ファイル: ZigZag.cs プロジェクト: jeanalves/DowPivot
 /// <summary>
 /// Used to create the magic
 /// </summary>
 /// <param name="dowPivot"></param>
 public abstract void Calculate(DowPivotOld dowPivot);
コード例 #26
0
 // To debug code
 public static void DrawText(DowPivotOld dowPivot, string text, int barsAgo, double price, int yPixelOff)
 {
     Draw.Text(dowPivot, "Miscellaneous debug " + dowPivot.CurrentBar + " " + text, false, text, barsAgo, price, yPixelOff, Brushes.White,
               new Gui.Tools.SimpleFont("Arial", 11), System.Windows.TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 100);
 }
コード例 #27
0
        public override void Calculate(DowPivotOld dowPivot)
        {
            #region Calcula primeiro ponto
            // Este laço faz o calculo das primeiras barras do gráfico
            if (dowPivot.IsFirstTickOfBar && GetHigh(0) == null && GetLow(0) == null)
            {
                initLowCache.Add(new HighLowAndIndex(dowPivot.Low[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant));
                initHighCache.Add(new HighLowAndIndex(dowPivot.High[barsAgoConstant], dowPivot.CurrentBar - barsAgoConstant));

                HighLowAndIndex lowCandidate  = initLowCache[0];
                HighLowAndIndex highCandidate = initHighCache[0];

                if (initLowCache.Count - 1 >= strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (initLowCache[i].Price < lowCandidate.Price)
                        {
                            lowCandidate = initLowCache[i];
                        }
                    }
                }

                if (initHighCache.Count - 1 >= strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (initHighCache[i].Price > highCandidate.Price)
                        {
                            highCandidate = initHighCache[i];
                        }
                    }
                }

                if (initLowCache.Count - 1 >= strength && initHighCache.Count - 1 >= strength)
                {
                    if (lowCandidate.Index < highCandidate.Index)
                    {
                        AddLow(dowPivot, lowCandidate.Price, lowCandidate.Index);
                        lastTrend         = TrendDir.Down;
                        calculationEstate = CalculationEstate.SecondValue;
                    }
                    else if (lowCandidate.Index > highCandidate.Index)
                    {
                        AddHigh(dowPivot, highCandidate.Price, highCandidate.Index);
                        lastTrend         = TrendDir.Up;
                        calculationEstate = CalculationEstate.SecondValue;
                    }
                    else
                    {
                        Miscellaneous.PrintError(dowPivot, "In the initial calculation of the 'Low' and 'High', they have the same index," +
                                                 " Low index: " + lowCandidate.Index + "    High index: " + highCandidate.Index);
                    }
                }
            }
            #endregion

            #region Calcula dados históricos e de tempo real
            // Enter only once per bar
            else if (dowPivot.IsFirstTickOfBar && (calculationEstate == CalculationEstate.SecondValue || calculationEstate == CalculationEstate.HistoricalRealTime))
            {
                bool isFalling          = true;
                bool isRising           = true;
                bool isOverLowStrength  = false;
                bool isOverHighStrength = false;

                if (lastTrend == TrendDir.Up && calculationEstate == CalculationEstate.SecondValue)
                {
                    isOverLowStrength = (dowPivot.CurrentBar - GetHigh(0).BarIndex) >= strength;
                    calculationEstate = CalculationEstate.HistoricalRealTime;
                }
                else if (lastTrend == TrendDir.Down && calculationEstate == CalculationEstate.SecondValue)
                {
                    isOverHighStrength = (dowPivot.CurrentBar - GetLow(0).BarIndex) >= strength;
                    calculationEstate  = CalculationEstate.HistoricalRealTime;
                }
                else
                {
                    isOverLowStrength  = (dowPivot.CurrentBar - GetHigh(0).BarIndex) >= strength;
                    isOverHighStrength = (dowPivot.CurrentBar - GetLow(0).BarIndex) >= strength;
                }

                lastLowCache.Add(dowPivot.Low[barsAgoConstant]);
                if (lastLowCache.Count > strength)
                {
                    lastLowCache.RemoveAt(0);
                }
                double swingLowCandidateValue = (double)lastLowCache[lastLowCache.Count - 1];

                lastHighCache.Add(dowPivot.High[barsAgoConstant]);
                if (lastHighCache.Count > strength)
                {
                    lastHighCache.RemoveAt(0);
                }
                double swingHighCandidateValue = (double)lastHighCache[lastHighCache.Count - 1];

                // Low calculations
                if (lastLowCache.Count == strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (swingLowCandidateValue > (double)lastLowCache[i])
                        {
                            isFalling = false;
                        }
                    }
                }
                // High calculations
                if (lastHighCache.Count == strength)
                {
                    for (int i = 0; i < strength; i++)
                    {
                        if (swingHighCandidateValue < (double)lastHighCache[i])
                        {
                            isRising = false;
                        }
                    }
                }

                // Add low
                if (isFalling && isOverLowStrength && lastTrend != TrendDir.Down)
                {
                    AddLow(dowPivot, dowPivot.Low[barsAgoConstant], dowPivot.CurrentBar - 1);
                    lastLow   = dowPivot.Low[barsAgoConstant];
                    lastTrend = TrendDir.Down;
                }
                // Add high
                else if (isRising && isOverHighStrength && lastTrend != TrendDir.Up)
                {
                    AddHigh(dowPivot, dowPivot.High[barsAgoConstant], dowPivot.CurrentBar - 1);
                    lastHigh  = dowPivot.High[barsAgoConstant];
                    lastTrend = TrendDir.Up;
                }
                // Update low
                else if (isFalling && lastTrend == TrendDir.Down && dowPivot.Low[barsAgoConstant] < lastLow)
                {
                    UpdateLow(dowPivot, dowPivot.Low[barsAgoConstant], dowPivot.CurrentBar - 1);
                    lastLow = dowPivot.Low[barsAgoConstant];
                }
                // Update high
                else if (isRising && lastTrend == TrendDir.Up && dowPivot.High[barsAgoConstant] > lastHigh)
                {
                    UpdateHigh(dowPivot, dowPivot.High[barsAgoConstant], dowPivot.CurrentBar - 1);
                    lastHigh = dowPivot.High[barsAgoConstant];
                }
            }
            #endregion

            #region Calcula todos os ticks em tempo real
            // Este "if" � executado apenas quando lastTrend � iniciada alterando de "Unknow"
            // para "Up" ou "Down" e em todos os ticks com exce��o do primeiro tick
            else if (!dowPivot.IsFirstTickOfBar && GetLow(0) != null && GetHigh(0) != null &&
                     calculationEstate == CalculationEstate.HistoricalRealTime)
            {
                // Low logic
                if (lastTrend == TrendDir.Down && dowPivot.Low[0] < GetLow(0).Price)
                {
                    UpdateLow(dowPivot, dowPivot.Low[0], dowPivot.CurrentBar);
                }

                // High logic
                if (lastTrend == TrendDir.Up && dowPivot.High[0] > GetHigh(0).Price)
                {
                    UpdateHigh(dowPivot, dowPivot.High[0], dowPivot.CurrentBar);
                }
            }
            #endregion
        }
コード例 #28
0
 public static double GetCloseOrLow(DowPivotOld dowPivot)
 {
     return(dowPivot.UseHighLow ? dowPivot.Low[0] : dowPivot.Close[0]);
 }
コード例 #29
0
ファイル: PivotLogic.cs プロジェクト: jeanalves/DowPivot
        public void Calculate(DowPivotOld dowPivot, ZigZag dowPivotZigZag)
        {
            if (dowPivotZigZag.GetLow(1).Price == 0 ||
                dowPivotZigZag.GetLow(0).Price == 0 ||
                dowPivotZigZag.GetHigh(1).Price == 0 ||
                dowPivotZigZag.GetHigh(0).Price == 0)
            {
                return;
            }

            currentPP = new PivotPoint(dowPivotZigZag.GetLow(1), dowPivotZigZag.GetLow(0), dowPivotZigZag.GetHigh(1), dowPivotZigZag.GetHigh(0));

            isFalling = currentPP.SecondLow.Price < currentPP.FirstLow.Price &&
                        currentPP.SecondHigh.Price < currentPP.FirstHigh.Price;

            isRising = currentPP.SecondLow.Price > currentPP.FirstLow.Price &&
                       currentPP.SecondHigh.Price > currentPP.FirstHigh.Price;

            downFilter = !IsOverMaxPercentPivotRetracement(dowPivot, TrendDir.Down, currentPP) &&
                         !IsOverMinPercentPivotRetracement(dowPivot, TrendDir.Down, currentPP);

            upFilter = !IsOverMaxPercentPivotRetracement(dowPivot, TrendDir.Up, currentPP) &&
                       !IsOverMinPercentPivotRetracement(dowPivot, TrendDir.Up, currentPP);

            // Add low pivot
            if (isFalling && downFilter && dowPivotZigZag.GetCurrentHighLowLeg() == TrendDir.Down && lastTrend != TrendDir.Down)
            {
                low.FirstLow   = new HighLowPoint(currentPP.FirstLow);
                low.SecondLow  = new HighLowPoint(currentPP.SecondLow);
                low.FirstHigh  = new HighLowPoint(currentPP.FirstHigh);
                low.SecondHigh = new HighLowPoint(currentPP.SecondHigh);

                PrintPivots(dowPivot, Situation.AddLow);

                lastTrend = TrendDir.Down;

                isDownLine3LegEnd = false;

                SetPlotBuyOrSell(dowPivot, TrendDir.Down);
                SetStopLossPrice(dowPivot, low.SecondHigh.Price);
                SetProfitTargetPrice(dowPivot, currentPP, TrendDir.Down);
            }
            // Add high pivot
            else if (isRising && upFilter && dowPivotZigZag.GetCurrentHighLowLeg() == TrendDir.Up && lastTrend != TrendDir.Up)
            {
                high.FirstLow   = new HighLowPoint(currentPP.FirstLow);
                high.SecondLow  = new HighLowPoint(currentPP.SecondLow);
                high.FirstHigh  = new HighLowPoint(currentPP.FirstHigh);
                high.SecondHigh = new HighLowPoint(currentPP.SecondHigh);

                PrintPivots(dowPivot, Situation.AddHigh);

                lastTrend = TrendDir.Up;

                isUpLine3LegEnd = false;

                SetPlotBuyOrSell(dowPivot, TrendDir.Up);
                SetStopLossPrice(dowPivot, high.SecondLow.Price);
                SetProfitTargetPrice(dowPivot, currentPP, TrendDir.Up);
            }
            // Update low pivot
            else if (isFalling && currentPP.SecondLow.Price < low.SecondLow.Price && !isDownLine3LegEnd && lastTrend == TrendDir.Down)
            {
                low.SecondLow = new HighLowPoint(currentPP.SecondLow);
                PrintPivots(dowPivot, Situation.UpdateLow);
            }
            // Update high pivot
            else if (isRising && currentPP.SecondHigh.Price > high.SecondHigh.Price && !isUpLine3LegEnd && lastTrend == TrendDir.Up)
            {
                high.SecondHigh = new HighLowPoint(currentPP.SecondHigh);
                PrintPivots(dowPivot, Situation.UpdateHigh);
            }

            if (!isDrawingPivots)
            {
                //lastTrend = TrendDir.Unknown;
            }

            // Help to define the pivot end draw
            if (dowPivotZigZag.GetCurrentHighLowLeg() == TrendDir.Up)
            {
                isDownLine3LegEnd = true;
            }
            else if (dowPivotZigZag.GetCurrentHighLowLeg() == TrendDir.Down)
            {
                isUpLine3LegEnd = true;
            }

            // Help to define if is drawing any pivot
            if (lastTrend == TrendDir.Down && isDownLine3LegEnd)
            {
                isDrawingPivots = false;
            }
            else if (lastTrend == TrendDir.Up && isUpLine3LegEnd)
            {
                isDrawingPivots = false;
            }
            else
            {
                isDrawingPivots = true;
            }
        }
コード例 #30
0
 public PointsCalculation(DowPivotOld dowPivot) : base(dowPivot)
 {
     isFirstLowValue  = true;
     isFirstHighValue = true;
 }