Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with the new indicator

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

    Problem with the new indicator

    I am only a starter and I was trying to create a strategy to generate buy and sell signals when the RSI and price trends are divergent from each other. But there's no action when I backtested it. Can anyone help me to check the code?

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Test"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = true;

    tops = new int[50];


    }





    protected override void OnBarUpdate()
    {

    for(i=n;i>=0;i--)
    {
    if(RSI(14,3)[i+1]-RSI(14,3)[i+2]>=0&&RSI(14,3)[i+1]-RSI(14,3)[i]>=0)
    {
    tops[j]=i+1;
    if(RSI(14,3)[i+1]>RSI(14,3)[date])
    {
    date=tops[j];
    m=j;
    }
    j++;
    }
    }
    if(date == 1)
    {
    for(k=0;k<=m;k++)
    {
    if(Slope(RSI(14,3), tops[k], date)>temp1)
    {
    temp1=Slope(RSI(14,3), tops[k], date);
    date2=tops[k];
    }
    }
    if(Close[date2]>Close[date])
    EnterLong(DefaultQuantity, "");
    }

    else
    {
    temp2=Slope(RSI(14,3), date, tops[m-1]);
    for(l=m-1;l>=0;l--)
    {
    if(Slope(RSI(14,3), date, tops[l])>temp2)
    {
    temp2=Slope(RSI(14,3), date, tops[l]);
    date3=tops[l];
    }
    }
    if(Close[date3]==1&&Close[date3]>Close[date])
    {
    ExitLong();
    }

    }

    Thank you very much!

    #2
    scyche,

    Welcome to the NinjaTrader Support Forums. Please check your Control Center logs for errors. Anything suspicious? If there are no errors you will need to step through your code slowly and find what is actually happening through your loops. http://www.ninjatrader-support2.com/...ead.php?t=3418
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you. I have checked the log. It says:"Error on calling the 'OnBarUpdate' method for strategy 'result':Index was out of range. Must be non-negative and less than the size of the collection."

      But I don't quite understand what does this mean. Would you please interpret that to some kind of simple language to me?

      Thanks again.

      Comment


        #4
        It means you are accessing an index value that does not exist. Likely coming from your loops. You can only access values that currently exist. Please see this tip on making sure you have enough bars for data points: http://www.ninjatrader-support2.com/...ead.php?t=3170
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thank you!

          Now I met a new problem after solving the previous one. In the log, it is said:"Error on calling 'OnBarUpdate' method for strategy 'result':Index was outside the bounds of the array." Would you mind translating this to me? I do appreciate your help!

          Comment


            #6
            Same thing scythe. You can ONLY access values that exist. You need to ensure all your arrays are only accessing valid indexes. Your use of loops can very easily try to access data points that just don't exist.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you very much for your patience!! I got it!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              581 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              338 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X