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

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 kaywai, Today, 06:26 AM
              1 response
              3 views
              0 likes
              Last Post kaywai
              by kaywai
               
              Started by ct, 05-07-2023, 12:31 PM
              6 responses
              202 views
              0 likes
              Last Post wisconsinpat  
              Started by kevinenergy, 02-17-2023, 12:42 PM
              118 responses
              2,779 views
              1 like
              Last Post kevinenergy  
              Started by briansaul, Today, 05:31 AM
              0 responses
              9 views
              0 likes
              Last Post briansaul  
              Started by traderqz, Yesterday, 12:06 AM
              11 responses
              28 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X