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

Limited use of variables

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

    Limited use of variables

    I’ve been trying to use double variables in my code but when I use more than about 20 at once they don’t seem to work. The code will still compile. But they do not seem to get referenced when the code is run.

    #2
    Could you provide more specific details since I unfortunately do not follow.
    RayNinjaTrader Customer Service

    Comment


      #3
      code exampe that works

      // Condition set 1
      if (
      Close[0]==Close[0]
      )
      {

      PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");



      double gh1 =Highs[2][1];
      double gh2 =Highs[2][2];
      double gh3 =Highs[2][3];
      double gh4 =Highs[2][4];
      double gh5 =Highs[2][5];
      double gh6 =Highs[2][6];
      double gh7 =Highs[2][7];
      double gh8 =Highs[2][8];
      double gh9 =Highs[2][9];

      double gh10 =Highs[2][10];
      double gh11 =Highs[2][11];
      double gh12 =Highs[2][12];
      double gh13 =Highs[2][13];
      double gh14 =Highs[2][14];
      double gh15 =Highs[2][15];
      double gh16 =Highs[2][16];
      double gh17 =Highs[2][17];
      double gh18 =Highs[2][18];
      double gh19 =Highs[2][19];
      double gh20 =Highs[2][20];


      }

      exampe that does not work


      // Condition set 1
      if (
      Close[0]==Close[0]
      )
      {

      PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");



      double gh1 =Highs[2][1];
      double gh2 =Highs[2][2];
      double gh3 =Highs[2][3];
      double gh4 =Highs[2][4];
      double gh5 =Highs[2][5];
      double gh6 =Highs[2][6];
      double gh7 =Highs[2][7];
      double gh8 =Highs[2][8];
      double gh9 =Highs[2][9];

      double gh10 =Highs[2][10];
      double gh11 =Highs[2][11];
      double gh12 =Highs[2][12];
      double gh13 =Highs[2][13];
      double gh14 =Highs[2][14];
      double gh15 =Highs[2][15];
      double gh16 =Highs[2][16];
      double gh17 =Highs[2][17];
      double gh18 =Highs[2][18];
      double gh19 =Highs[2][19];
      double gh20 =Highs[2][20];
      double gh21 =Highs[2][21];

      }

      Comment


        #4
        Run time errors of a strategy are generally written to the Log tab of the Control Center window. I suspect in the log tab you have an error that says something like "Index out of range".

        The problem is that you are accessing 21 bars back. In a strategy, the default "Minimum bars required" is 20. This means the strategy will not call OnBarUpdate() until 20 bars have been seen. In the case of the second example, you are accessing 21st bar which does not exist.

        - You can change the min bars required when running a strategy to 21 or
        - Read this post - http://www.ninjatrader-support.com/v...ead.php?t=3170
        RayNinjaTrader Customer Service

        Comment


          #5
          Ok that does make the code work, but it can be a problem on a multi time frame chart if I want to reference a lot of bars on a low time frame chart and a smaller number of bars back on a bigger time frame as a setting to enable the smaller time frame may cause problems with the higher time frame. Is there a way to around this?

          Also is it possible to use the LowestBar and HighestBar commands where the reference begins from a point in the past for example if I want to find the highest high for 50 bar bars but starting the search from a bar 100 bars ago instead of the current bar?

          Comment


            #6
            I see, there is no way around at this time.

            There is no method signature to get the HighestBar but starting x bars back. What you could do to work around this is create an internal IntSeries object (call it highestBarSeries etc...) and on each OnBarUpdate() call store a value such as:

            highestBarSeries.Set(HighestBar(High, 50));

            Then you could reference this series such as:

            Print("The highest high bar of the past 50 bars starting 100 bars ago is " + highestBarSeries[100]);

            Something like that in concept.
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            4 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            40 views
            0 likes
            Last Post alifarahani  
            Started by Waxavi, Today, 02:10 AM
            1 response
            18 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Kaledus, Today, 01:29 PM
            5 responses
            15 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X