Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CS0021 Cannot apply indexing with []......

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    CS0021 Cannot apply indexing with []......

    Plagued by CS0021 Cannot apply indexing with [] to an expression of type 'method group'

    Snippet from the top of my code. The last 2 lines at the bottom in red before the //break\\ throw up the CS0021 error. The lines after the break in red throw up CS0021. Help please! :-)


    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript.DrawingTools;
    using System.Windows.Media;

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class EnhancedQuadStochasticStrategy : Strategy
    {
    // Declare Stochastics indicators
    private Stochastics stoch1;
    private Stochastics stoch2;
    private Stochastics stoch3;
    private Stochastics stoch4;

    // Trend/volume indicators
    private VWAP vwap;
    private EMA ema9;
    private EMA ema20;
    private ADX adx;
    private SMA volumeSMA;

    // Configurable parameters
    private int volumeSMAPeriod = 20;
    private int adxThreshold = 25;
    private int confirmationBars = 2;

    // Visual/sound settings
    private SolidColorBrush buyArrowColor = Brushes.Lime;
    private SolidColorBrush sellArrowColor = Brushes.Red;
    private string longSound = "Alert2.wav";
    private string shortSound = "Alert3.wav";

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Enhanced Quad Stochastic Strategy with Fakeout Filters";
    Name = "EnhancedQuadStochasticStrategy";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    BarsRequiredToTrade = 20;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    else if (State == State.DataLoaded)
    {
    stoch1 = Stochastics(5, 3, 3);
    stoch2 = Stochastics(14, 3, 3);
    stoch3 = Stochastics(21, 5, 5);
    stoch4 = Stochastics(50, 10, 10);
    vwap = VWAP(BarsArray[1]);
    ema9 = EMA(9);
    ema20 = EMA(20);
    adx = ADX(14);
    volumeSMA = SMA(Volume, volumeSMAPeriod);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 50) return;

    // Skip first 15 mins and last 30 mins of session
    if (Times[0][0].TimeOfDay.TotalMinutes < 15 * 60 + 30 ||
    Times[0][0].TimeOfDay.TotalMinutes > 16 * 60 - 30) return;

    // Long entry conditions (using Values[0] for %K, Values[1] for %D)
    bool isLongSignal =
    stoch1.Values[0][0] > stoch1.Values[1][0] &&
    stoch2.Values[0][0] > stoch2.Values[1][0] &&
    stoch3.Values[0][0] > stoch3.Values[1][0] &&
    stoch4.Values[0][0] > stoch4.Values[1][0] &&
    stoch1.Values[0][0] < 20 && stoch2.Values[0][0] < 20 && stoch3.Values[0][0] < 20 && stoch4.Values[0][0] < 20 &&
    Close[0] > ema9[0] && ema9[0] > ema20[0] &&
    Close[0] > vwap.VWAP[0] &&
    adx.ADX[0] > adxThreshold &&



    /////////////// BREAK \\\\\\\\\\\\\\

    if (isLong && (Close[i] < ema9[i] || Close[i] < vwap.VWAP[i]))
    return false;
    if (!isLong && (Close[i] > ema9[i] || Close[i] > vwap.VWAP[i]))
    return false;​

    #2
    Hello thatsfresh,

    If you would like assistance with a compile error, please provide the full error message. Ctrl + c to copy the selected error, Ctrl + v to paste into your post.
    Or provide a screenshot of the error with the Error column fully expanded with the affected line noted in the error visible in the NinjaScript Editor.
    This should include the full error message as well as a line number.

    The ADX adds a plot but does not explicitly add a public Series<double> ADX.

    This means the ADX would be called without specifying ADX as property to use the default plot.

    Change:
    adx.ADX[0]

    To
    adx[0]

    The VWAP may be a custom indicator you have imported as this does not appear to the the OrderFlowVWAP included with NinjaTrader.

    You will want to check that this custom indicator explicitly declares a public Series<double> VWAP. Otherwise you will likely want to call this without specifying VWAP as a property to use the default plot.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      I am now able to compile. The lines in RED in my original post are the ones I was having issues with. Before and after below. Thanks for your help!!

      ** BEFORE **

      Close[0] > vwap.VWAP[0] &&
      adx.ADX[0] > adxThreshold &&


      if (isLong && (Close[i] < ema9[i] || Close[i] < vwap.VWAP[i]))
      return false;
      if (!isLong && (Close[i] > ema9[i] || Close[i] > vwap.VWAP[i]))​
      return false;
      }​​

      ** AFTER **

      Close[0] < vwap[0] &&
      adx[0] > adxThreshold &&


      if (isLong && (Close[i] < ema9[i] || Close[i] < vwap[i]))
      return false;
      if (!isLong && (Close[i] > ema9[i] || Close[i] > vwap[i]))
      return false;
      }​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      557 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X