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 CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    32 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    195 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    356 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    277 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X