/// <summary> /// Sets the extrema price of the thrust Fibonacci retracement /// </summary> /// <param name="chart">The chart object that contains the retracement.</param> /// <param name="side">The direction of the entry signal associated with the retracement.</param> /// <param name="focusIndex">The chart index of the retracement focus bar.</param> /// <returns></returns> protected virtual Thrust SetThrustRetracementExtrema(Chart chart, Thrust thrust) { int focusIndex = GetFocusIndex(chart, thrust); FibonacciRetracement retracement = thrust.Study as FibonacciRetracement; double?extremaPrice = null; // only if the chart has post-focus frames int i = focusIndex + 1; if (i < chart.Frames.Count) { // initialize if (thrust.Side == MACC.Constants.SignalSide.Buy) { extremaPrice = chart.Frames[focusIndex].Bar.highMid; } else { extremaPrice = chart.Frames[focusIndex].Bar.lowMid; } // discover for (; i < chart.Frames.Count; i++) { if (thrust.Side == MACC.Constants.SignalSide.Buy) { extremaPrice = Math.Min(extremaPrice.Value, chart.Frames[i].Bar.lowMid); } else { extremaPrice = Math.Max(extremaPrice.Value, chart.Frames[i].Bar.highMid); } } } retracement.ExtremaPrice = extremaPrice; if (retracement.ExtremaChanged()) { retracement.ExtremaIndex = i; } return(thrust); }
protected virtual Thrust SetThrustTakeProfitZoneReached(Chart chart, Thrust thrust) { FibonacciRetracement retracement = thrust.Study as FibonacciRetracement; #region did price reach the takeProfit zone? if (thrust.FillZoneReached()) { double? searchTakeProfitPrice = null; List <Frame> searchFrames = null; if (!thrust.TakeProfitZoneReached()) { searchTakeProfitPrice = thrust.TakeProfitPrice.Value; searchFrames = chart.Frames.Skip(thrust.FillZoneReachedIndex.Value + 1).ToList(); } else { if (retracement.ExtremaChanged()) { int multiplier = thrust.Side == MACC.Constants.SignalSide.Buy ? 1 : -1; double r382Price = retracement.LevelPrice(FibonacciLevel.R382); searchTakeProfitPrice = r382Price + (0.618 * Math.Abs(retracement.FocusPrice - r382Price) * multiplier); searchFrames = chart.Frames.Skip(retracement.ExtremaIndex.Value + 1).ToList(); } } Frame takeProfitZoneReachedFrame = searchFrames.FirstOrDefault(frame => { double extremaToTakeProfitZoneDelta = _takeProfitZoneReachedCoefficient * Math.Abs(searchTakeProfitPrice.Value - retracement.ExtremaPrice.Value); bool takeProfitZoneReached = false; if (thrust.Direction == EPatternDirection.Up) { takeProfitZoneReached = (frame.Bar.highMid >= retracement.ExtremaPrice.Value + extremaToTakeProfitZoneDelta); } else { takeProfitZoneReached = (frame.Bar.lowMid <= retracement.ExtremaPrice.Value - extremaToTakeProfitZoneDelta); } if (takeProfitZoneReached) { thrust.TakeProfitZoneReachedIndex = chart.Frames.IndexOf(frame); thrust.TakeProfitZoneReachedFocusPrice = thrust.FocusPrice; return(true); } return(false); }); } #endregion // is it a breakout? if (thrust.TakeProfitZoneReached()) { double breakoutDelta = thrust.SignalPrice * _focusBreakoutCoefficient * _minThrustPercentRange; if (thrust.Direction == EPatternDirection.Up) { thrust.Breakout = thrust.FocusPrice >= thrust.TakeProfitZoneReachedFocusPrice.Value + breakoutDelta; } else { thrust.Breakout = thrust.FocusPrice <= thrust.TakeProfitZoneReachedFocusPrice.Value - breakoutDelta; } if (thrust.Breakout) { thrust.FillZoneReachedIndex = null; thrust.TakeProfitZoneReachedIndex = null; thrust.TakeProfitZoneReachedFocusPrice = null; } } return(thrust); }