It works fine when I apply it to a chart.
However, when I include it in a strategy, the ADX value never updates. It stays set at 50 per the Print statements.
I tried adding an Update() call into this indicator's getter.
I even added a adx.Update() call before accessing the ads.Value[0].
But to no avail. It still returns 50 all the time.
What gives? Here's part of the code.
Wayne
public class AvgTrend : Indicator { #region Variables // Wizard generated variables private int avgLength = 90; // Default setting for AvgLength private int adxLength = 45; // Default setting for ADXLength private int adxMinimum = 10; // Default setting for ADXMinimum private ADX adx = null; private SMA sma = null; private int signal = 0; private TEMA tema = null; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { adx = ADX(adxLength); sma = SMA(avgLength); tema = TEMA(14); Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Signal")); CalculateOnBarClose = true; Overlay = false; PriceTypeSupported = false; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if( CurrentBar > 1) { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. adx.Update(); if( adx.Value[0] > adxMinimum) { Print(Time[0] + ": adx.Value[0] = " + adx.Value[0] + ", adxMinimum = " + adxMinimum + ", adxLength " + adxLength); if( tema.Value[0] > sma.Value[0]) { signal = 1; if( signal != Signal[1]) { Print( Time[0] + ": Changed to long"); } } if( tema.Value[0] < sma.Value[0]) { signal = -1; if( signal != Signal[1]) { Print( Time[0] + ": Changed to short"); } } } else { signal = 0; if( signal != Signal[1]) { Print( Time[0] + ": Changed to flat"); } } Signal.Set(signal); } }
Comment