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

Indicator not working...

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

    Indicator not working...

    I have the following error message and I do not understand why :

    Object reference not set to an instance of an object
    May someone give me any clues at least to understand what I did wrong ?

    Here is the script :

    #region Variables
    // Wizard generated variables
    private int period = 20; // Default setting for Period
    private int rcoeff = 5; // Default setting for Rcoeff
    private double rerror = 0.7; // Default setting for Rerror
    private int span = 3; // Default setting for Span
    // User defined variables (add any user defined variables below)
    private DataSeries Cvalue;
    private DataSeries Hvalue;
    private DataSeries Lvalue;
    private double Range = 0.0;
    private double Delta = 0.0;
    private bool Firstcalc = true;
    private int j = 1;
    private int i = 0;
    private int k = 0;
    private int[] Var1;
    private int[] Var3;
    private int[] Var4;
    private double[,] Var2;
    private double HlevelBreak = 0.0;
    private double LlevelBreak = 0.0;
    #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()
    {

    CalculateOnBarClose = true;
    Overlay = true;
    Cvalue = new DataSeries (this);
    Lvalue = new DataSeries (this);
    Hvalue = new DataSeries (this);
    int[] Var1 = new int[500];
    double[,] Var2 = new double[500,3];
    int[] Var3 = new int[500];
    int[] Var4 = new int[500];
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (CurrentBar < period)
    return;

    Cvalue.Set(SMA(Close,period)[0]);
    Hvalue.Set(SMA(High,period)[0]);
    Lvalue.Set(SMA(Low,period)[0]);
    Range = Hvalue[0]-Lvalue[0];
    Delta = Range*0.3*rcoeff;

    if (Firstcalc == false)
    {
    if (CrossAbove(High,Cvalue,1) || CrossBelow(Low,Cvalue,1) || (High[0]>=Cvalue[0] && Low[0]<=Cvalue[0]))
    {
    Var1[j]=Count;
    Var2[j,0]=Hvalue[0];
    Var2[j,1]=Cvalue[0];
    Var2[j,2]=Lvalue[0];
    }
    }

    Firstcalc=false;

    HlevelBreak = Var2[j,1]+Delta;
    LlevelBreak = Var2[j,1]-Delta;

    if (CrossAbove(Close,HlevelBreak,1) || CrossBelow(Close,LlevelBreak,1))
    {
    for (int i=0; i<j ;i++)
    {
    if (Math.Abs(Var2[j,1]-Var2[i,1]) <= rerror*Range)
    {
    Var1[i]=0;
    Var2[i,0]=0.0;
    Var2[i,1]=0.0;
    Var2[i,2]=0.0;
    Var3[i]=-9;
    Var4[i]=0;
    }
    }
    j++;
    }

    for (int i = 0 ; i<(j+1) ; i++)
    {
    if ((Count-Var1[i]>10) && (CrossAbove(Cvalue,Hvalue,1) || CrossBelow (Cvalue,Lvalue,1)))
    {
    Var4[i]=Var4[i]+1;
    if (Var4[i] >= span)
    {
    Var1[i]=0;
    Var2[i,0]=0.0;
    Var2[i,1]=0.0;
    Var2[i,2]=0.0;
    Var3[i]=-9;
    Var4[i]=0;
    }
    }
    }

    for (int i= 0; i<(j+1); i++)
    {
    if (Var3[i]== -9)
    {
    for (int k = i ; k < (j+2) ; k++)
    {
    Var1[k]=Var1[k+1];
    Var2[k,0]=Var2[k+1,0];
    Var2[k,1]=Var2[k+1,1];
    Var2[k,2]=Var2[k+1,2];
    Var3[k]=Var3[k+1];
    Var4[k]=Var4[k+1];
    }
    if (j >=1) { j--;}
    }
    }

    for (int i= 0; i<(j+1); i++)
    {
    if (Var2[i,1]>0)
    {
    DrawDot("pivot"+i,false,0,Var2[i,1],Color.Yellow);
    }
    }
    Last edited by baba123; 04-11-2010, 08:35 PM.

    #2
    baba123, likely issues with accessing an array value not present - you would need to debug your code to check where this occurs -



    BertrandNinjaTrader Customer Service

    Comment


      #3
      After reviewing my code I wonder if the use of ArrayList method would be better ?
      Basically, I would like to use some kind of multidimentional dynamic Array which could contain several type of datas (int & double).

      Comment


        #4
        Good idea, an ArrayList would be dynamic in size and thus perhaps easier to code with than a static sized Array.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Is it possible to create a multidimensional ArrayList ?
          How do you declare that in the variable & initialize fields?

          Comment


            #6
            Unfortunately this is not supported by us as it's more general C# related, however there has been a number of threads already on this on the forums which should help you get going - http://www.ninjatrader-support2.com/...ad.php?t=24801
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DynamicTest, Today, 11:18 PM
            0 responses
            3 views
            0 likes
            Last Post DynamicTest  
            Started by dcriador, Today, 01:43 AM
            3 responses
            19 views
            0 likes
            Last Post dcriador  
            Started by smartromain, Today, 10:50 PM
            0 responses
            5 views
            0 likes
            Last Post smartromain  
            Started by popecapllc, 08-09-2023, 07:42 PM
            10 responses
            1,366 views
            0 likes
            Last Post BartMan
            by BartMan
             
            Started by jbays87, Today, 09:46 PM
            0 responses
            6 views
            0 likes
            Last Post jbays87
            by jbays87
             
            Working...
            X