/// <summary> /// Initializes a new instance of the <see cref="NormalizedAverageTrueRange"/> class using the specified name and period. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the NATR</param> public NormalizedAverageTrueRange(string name, int period) : base(name) { _period = period; _tr = new TrueRange(name + "_TR"); _atr = new AverageTrueRange(name + "_ATR", period, MovingAverageType.Simple); }
/// <summary> /// Initializes a new instance of the <see cref="NormalizedAverageTrueRange"/> class using the specified name and period. /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the NATR</param> public NormalizedAverageTrueRange(string name, int period) : base(name) { _period = period; _tr = new TrueRange(name + "_TR"); _atr = new AverageTrueRange(name + "_ATR", period, MovingAverageType.Simple); }
/// <summary> /// Resets this indicator to its initial state /// </summary> public override void Reset() { AverageTrueRange.Reset(); MiddleBand.Reset(); UpperBand.Reset(); LowerBand.Reset(); base.Reset(); }
/// <summary> /// Creates a new SuperTrend indicator using the specified name, period, multiplier and moving average type /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The smoothing period used by average true range</param> /// <param name="multiplier">The coefficient used in calculations of basic upper and lower bands</param> /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param> public SuperTrend(string name, int period, decimal multiplier, MovingAverageType movingAverageType = MovingAverageType.Wilders) : base(name) { _averageTrueRange = new AverageTrueRange(period, movingAverageType); _multiplier = multiplier; _period = period; _prevSuper = -1; }
public RandomWalkIndexHigh(string name, int period) : base(name) { _period = period; _sqrtPeriod = (decimal)Math.Sqrt(_period); _low = new Delay(name + "_Low", _period); _atr = new AverageTrueRange(name + "_ATR", _period); }
/// <summary> /// Computes the next value for this indicator from the given state. /// </summary> /// <param name="input">The TradeBar to this indicator on this time step</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(IBaseDataBar input) { AverageTrueRange.Update(input); var typicalPrice = (input.High + input.Low + input.Close) / 3m; MiddleBand.Update(input.Time, typicalPrice); // poke the upper/lower bands, they actually don't use the input, they compute // based on the ATR and the middle band LowerBand.Update(input); UpperBand.Update(input); return(MiddleBand); }
/// <summary> /// Computes the next value for this indicator from the given state. /// </summary> /// <param name="input">The TradeBar to this indicator on this time step</param> /// <returns>A new value for this indicator</returns> protected override decimal ComputeNextValue(TradeBar input) { AverageTrueRange.Update(input); var typicalPrice = (input.High + input.Low + input.Close) / 3m; MiddleBand.Update(input.Time, typicalPrice); Console.WriteLine(input.Time.ToString("yyyymmdd") + "\t" + typicalPrice.SmartRounding() + "\t" + MiddleBand.Current.Value.SmartRounding()); // poke the upper/lower bands, they actually don't use the input, they compute // based on the ATR and the middle band LowerBand.Update(input); UpperBand.Update(input); return(MiddleBand); }
public void TrueRangePropertyIsReadyAfterOneSample() { var atr = new AverageTrueRange(14, MovingAverageType.Simple); Assert.IsFalse(atr.TrueRange.IsReady); atr.Update(new TradeBar { Time = DateTime.Today, Open = 1m, High = 3m, Low = .5m, Close = 2.75m, Volume = 1234567890 }); Assert.IsTrue(atr.TrueRange.IsReady); }
public void ResetsProperly() { var atr = new AverageTrueRange(14, MovingAverageType.Simple); atr.Update(new TradeBar { Time = DateTime.Today, Open = 1m, High = 3m, Low = .5m, Close = 2.75m, Volume = 1234567890 }); atr.Reset(); TestHelper.AssertIndicatorIsInDefaultState(atr); TestHelper.AssertIndicatorIsInDefaultState(atr.TrueRange); }
public void ComparesAgainstExternalData() { var atr = new AverageTrueRange(14, MovingAverageType.Simple); TestHelper.TestIndicator(atr, "spy_atr.txt", "Average True Range 14"); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { // initialize algorithm level parameters SetStartDate(2013, 10, 07); SetEndDate(2013, 10, 11); //SetStartDate(2014, 01, 01); //SetEndDate(2014, 06, 01); SetCash(100000); // leverage tradier $1 traders SetBrokerageModel(BrokerageName.TradierBrokerage); // request high resolution equity data AddSecurity(SecurityType.Equity, Symbol, Resolution.Second); // save off our security so we can reference it quickly later Security = Securities[Symbol]; // Set our max leverage Security.SetLeverage(MaximumLeverage); // define our longer term indicators ADX14 = ADX(Symbol, 28, Resolution.Hour); STD14 = STD(Symbol, 14, Resolution.Daily); ATR14 = ATR(Symbol, 14, resolution: Resolution.Daily); PSARMin = new ParabolicStopAndReverse(Symbol, afStart: 0.0001m, afIncrement: 0.0001m); // smooth our ATR over a week, we'll use this to determine if recent volatilty warrants entrance var oneWeekInMarketHours = (int)(5*6.5); SmoothedATR14 = new ExponentialMovingAverage("Smoothed_" + ATR14.Name, oneWeekInMarketHours).Of(ATR14); // smooth our STD over a week as well SmoothedSTD14 = new ExponentialMovingAverage("Smoothed_"+STD14.Name, oneWeekInMarketHours).Of(STD14); // initialize our charts var chart = new Chart(Symbol); chart.AddSeries(new Series(ADX14.Name)); chart.AddSeries(new Series("Enter", SeriesType.Scatter)); chart.AddSeries(new Series("Exit", SeriesType.Scatter)); chart.AddSeries(new Series(PSARMin.Name, SeriesType.Scatter)); AddChart(chart); var history = History(Symbol, 20, Resolution.Daily); foreach (var bar in history) { ADX14.Update(bar); ATR14.Update(bar); STD14.Update(bar.EndTime, bar.Close); } // schedule an event to run every day at five minutes after our Symbol's market open Schedule.Event("MarketOpenSpan") .EveryDay(Symbol) .AfterMarketOpen(Symbol, minutesAfterOpen: OpeningSpanInMinutes) .Run(MarketOpeningSpanHandler); Schedule.Event("MarketOpen") .EveryDay(Symbol) .AfterMarketOpen(Symbol, minutesAfterOpen: -1) .Run(() => PSARMin.Reset()); }