Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NT8 compiler errors CS0029 & CS0021

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

    NT8 compiler errors CS0029 & CS0021

    Hi,
    I'm in the process of converting a NT7 indicator (measure relative volume based on the time of the day) to a NT8 indicator but I'm getting error code CS0029 that is described as "Cannot implicitly convert type "double[]" to "double" and error code CS0021 that is described as "
    Cannot implicitly convert type "int[]" to "int".

    Below is a portion of the code, the errors are called out for the last 2 lines:


    IsSuspendedWhileInactive = true;
    VolAtTime = 0;
    AvgVolAtTime = 0;
    NumberOfOccurences = 0;
    TempVol = 0;
    CVol = 0;
    TempNOC = 0;
    BarCounter = 0;
    AverageVolume = 0;
    CumulativeVolume = 0;

    }
    else if (State == State.Configure)
    {
    AddPlot(new Stroke(Brushes.Plum, 2), PlotStyle.Bar, "CumulativeVolumeDiff");
    IsOverlay = false;
    AvgVolAtTime = new double[4000];
    NumberOfOccurences = new int[4000];
    }

    Any advise on how to fix this?

    Thanks.

    #2
    Hello Clmukab,

    Thanks for your post and welcome to the NinjaTrader forums!

    Above State.Configure you are showing AvgVolAtTime = 0 and NumberOfOcurrances = 0 which implies that they are single variables, then in State.Configure you are now trying to initialize these as arrays and that is why you have the compile errors.

    I suspect you want to use these as arrays so I would suggest creating them at the class level and initializing them in State.DataLoaded (reference: https://ninjatrader.com/support/help...tatechange.htm). If so, you would also need to remove them from State.Defaults

    Here is an example you can test with:

    [I]public class ArrayTest : Indicator
    {
    private double [] NumberOfOccurances;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "ArrayTest";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    NumberOfOccurances = new double [4000];
    for (int i = 0; i < 100; i++)
    {
    NumberOfOccurances[i] = i * 3.141; // just to put some values in the first 100 to print later
    }
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    for (int i = 0; i < 100; i++)
    {
    Print ("i: "+i+" value stored = "+NumberOfOccurances);
    }
    }

    }
    }


    Example of output:
    i: 0 value stored = 0
    i: 1 value stored = 3.141
    i: 2 value stored = 6.282
    i: 3 value stored = 9.423
    i: 4 value stored = 12.564
    i: 5 value stored = 15.705
    i: 6 value stored = 18.846
    i: 7 value stored = 21.987
    i: 8 value stored = 25.128
    i: 9 value stored = 28.269
    i: 10 value stored = 31.41
    i: 11 value stored = 34.551
    i: 12 value stored = 37.692
    i: 13 value stored = 40.833
    i: 14 value stored = 43.974
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rayyyu12, Today, 12:47 AM
    0 responses
    7 views
    0 likes
    Last Post rayyyu12  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    17 responses
    136 views
    0 likes
    Last Post ETFVoyageur  
    Started by ETFVoyageur, Yesterday, 10:13 PM
    1 response
    10 views
    0 likes
    Last Post ETFVoyageur  
    Started by somethingcomplex, Yesterday, 10:36 PM
    0 responses
    10 views
    0 likes
    Last Post somethingcomplex  
    Started by sofortune, 05-10-2024, 10:28 AM
    5 responses
    22 views
    0 likes
    Last Post sofortune  
    Working...
    X