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

Error defining resistances and supports

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

    Error defining resistances and supports

    I was trying to retrieve custom resistances and supports from a chart with this code:

    Code:
    int range=200;
    for(int i=0; i<range; i++){
    if(SMA(1)[i]>techo){ //calculo techo con RANGO=X
    techo=SMA(1)[i];
    }
    if(SMA(1)[i]<suelo){ //calculo suelo con RANGO=X
    suelo=SMA(1)[i];
    }
    }
    I'm gettint this error: Error al llamar ' OnBarUpdate' método en barra 0: Está accediendo a un índice con un valor que es inválido ya que es fuera de rango, It says that I'm trying to access an index out of range.

    My thinking was iterating a few bars before and store the max an min value. I don't know if there's a function that already does that, I didn't see anything in the documentation, if not how can i get rid off this error? Why is there a restriction in range when in the chart I have plenty off bars to get info from?

    #2
    Hello juanram,

    Thanks for your post and welcome to the Ninjatrader forums!

    The error message is advising that your script is trying to access a barsago that does not exist at the time that your code started processing the historical data. The script will start on the first bar of historical data and according to your code will try to access up to 200 bars before that which would not exist. You will need to delay processing your code until you have 200 bars sequenced by the script. You can use the system bar counter CurrentBar as a way to check how many bars your script has processed and "return" if less than 200 and then process your code when it is greater than 200.

    Please see the example in the help guide here: https://ninjatrader.com/support/help...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      So if I'm understanding it correctly, in the image below, when the script starts running at the bar highlighted in red, from there to the right would be the new bars that were proccessed as they come? How could I acces the bars that are on the left side but were previous from the start of the script?

      Comment


        #4
        Hello juanram,

        Thanks for your reply.

        The script will processing on the very first bar in the data series of the chart. If the chart is loading 5 days of data, then the script will start on the first bar 5 days ago and will process each historical bar in sequence up to the live edge of the chart. This is why you would need to have your script not process the first 200 bars as you are looking back 200 bars when your script is allow to run.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,605 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X