• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Jorge.andres.o, Today, 08:22 PM
        0 responses
        5 views
        0 likes
        Last Post Jorge.andres.o  
        Started by mtamaku, Today, 06:54 PM
        0 responses
        8 views
        0 likes
        Last Post mtamaku
        by mtamaku
         
        Started by Lumbeezl, Today, 06:32 PM
        0 responses
        5 views
        0 likes
        Last Post Lumbeezl  
        Started by ozziyhtomit, Today, 05:24 PM
        0 responses
        3 views
        0 likes
        Last Post ozziyhtomit  
        Started by AnotherWorkingHomeless, Today, 08:45 AM
        0 responses
        23 views
        0 likes
        Last Post AnotherWorkingHomeless  
        Working...
        X