Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninjascript 8 - Strategy error

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

    Ninjascript 8 - Strategy error

    Dear all, hope you are fine.
    I have a rare error that cant find what is going on.
    I have this code:

    protected override void OnBarUpdate()
    {

    dibujarCuatroHoras();
    }


    private void dibujarCuatroHoras(){

    int limiteIzquierdo;
    int limiteDerecho;
    double maximo = 0;
    double minimo = 0;
    bool encontre = false;

    if(ToTime(Time[0]) == 040000)
    {
    maximo = High[0];
    minimo = Low[0];
    limiteDerecho = 0;

    for(int x = 0 ; x < 100 && !encontre; x++)
    {
    if(maximo < High[x]){maximo = High[x];}
    if(minimo > Low[x]){minimo = Low[x];}

    if(ToTime(Time[x])==000000)
    {
    encontre = true;
    dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    }

    }
    }
    if(ToTime(Time[0]) == 080000)
    {
    maximo = High[0];
    minimo = Low[0];
    limiteDerecho = 0;

    for(int x = 0 ; x < 100 && !encontre; x++)
    {
    if(maximo < High[x]){maximo = High[x];}
    if(minimo > Low[x]){minimo = Low[x];}

    if(ToTime(Time[x])==040000)
    {
    encontre = true;
    dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    }

    }
    }
    if(ToTime(Time[0]) == 120000)
    {
    maximo = High[0];
    minimo = Low[0];
    limiteDerecho = 0;

    for(int x = 0 ; x < 100 && !encontre; x++)
    {
    if(maximo < High[x]){maximo = High[x];}
    if(minimo > Low[x]){minimo = Low[x];}

    if(ToTime(Time[x])==080000)
    {
    encontre = true;
    dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    }

    }
    }
    if(ToTime(Time[0]) == 160000)
    {
    maximo = High[0];
    minimo = Low[0];
    limiteDerecho = 0;

    for(int x = 0 ; x < 100 && !encontre; x++)
    {
    if(maximo < High[x]){maximo = High[x];}
    if(minimo > Low[x]){minimo = Low[x];}

    if(ToTime(Time[x])==120000)
    {
    encontre = true;
    dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    }

    }
    }

    // if(ToTime(Time[0]) == 200000)
    // {
    // maximo = High[0];
    // minimo = Low[0];
    // limiteDerecho = 0;

    // for(int x = 0 ; x < 100 && !encontre; x++)
    // {
    // if(maximo < High[x]){maximo = High[x];}
    // if(minimo > Low[x]){minimo = Low[x];}

    // if(ToTime(Time[x])==160000)
    // {
    // encontre = true;
    // dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    // }

    // }
    // }

    if(ToTime(Time[0]) == 000000)
    {
    maximo = High[0];
    minimo = Low[0];
    limiteDerecho = 0;

    for(int x = 0 ; x < 100 && !encontre; x++)
    {
    if(maximo < High[x]){maximo = High[x];}
    if(minimo > Low[x]){minimo = Low[x];}

    if(ToTime(Time[x])==200000)
    {
    encontre = true;
    dibujar(x,0,maximo,minimo, Brushes.Blue, Brushes.White);
    }

    }
    }






    }

    private void dibujar(int limiteIzquierdo, int limiteDerecho, double maximo, double minimo, SolidColorBrush borde
    , SolidColorBrush relleno){

    int id = contadorCuadros;
    contadorCuadros++;

    Draw.Rectangle(this, id.ToString(), true /*IsAutoScale*/, limiteIzquierdo /*startBarsAgo*/,
    minimo /*startY*/, limiteDerecho /*endBarsAgo*/,maximo/*endY*/, borde /*Brushes.Blue*/,
    relleno /*Brushes.Aqua*/ /*areaBrush*/, 40);

    Print(maximo+" - "+ minimo + " LimiteDerecho: " + limiteDerecho+ " Limite Izquierdo: " + limiteIzquierdo);

    }

    This code works perfectly, but because is commented the block where time range handled is between 200000 and 1600000.
    That block throws me an error : You are accessing an index with a value that is invalid.
    Is hard to see the error because all blocks are equals and works, the think is whit the range 200000 to 160000.
    Please, could you help me?

    #2
    Hello, thanks for posting.

    You can use Visual Studio debugging to find the exact line that is causing the error. Turn on Debug mode, launch the Visual Studio project then attach Visual Studio to the NinjaTrader.exe process. After this, run the script so the error happens and it will break at the line causing the problem:



    Best regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X