Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to index[] a variable in a formula?

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

    How to index[] a variable in a formula?

    Hi!
    Is there anyway to index[] a variable?
    Like you can index data series High[0], High[-1] etc.
    By creating new data series it works for positive index value in "do loop"
    But negative index value in "do loop" crashes ninjatrader
    Your response will be appreciated

    #2
    Hello baqer110,

    Thank you for your post.

    It is possible and should not crash NinjaTrader. Can you provide the example that crashed NinjaTrader in a do loop?

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello baqer110,

      Thank you for your post.

      It is possible and should not crash NinjaTrader. Can you provide the example that crashed NinjaTrader in a do loop?
      Hi!
      thanks a lot
      Again it relates to High /Low as per our previous thread
      In the example below the first do loop works well.
      But the 2nd do loop, which I have blocked, if I unblock it NT crashes. No error during compilation

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// shows medium term High
      /// </summary>
      [Description("shows medium term High")]
      public class FactoralMTH : Indicator
      {
      #region Variables
      // Wizard generated variables
      // User defined variables (add any user defined variables below)
      private DataSeries mydataseries;
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {

      Overlay = true;
      mydataseries = new DataSeries(this);
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (CurrentBar < 10 )
      return;
      double a = 0;
      double b = 0;

      if(High[0] > High[1] && High[0] > High[2] && High[0] > High[-1] && High[0] > High[-2])
      a = High[0];


      DrawArrowDown(a.ToString(), true, 0, High[0] + TickSize, Color.Red);//short term high

      if (Low[0] < Low[1] && Low[0] < Low[2] && Low[0] < Low[-1] && Low[0] < Low[-2])
      b = Low[0];

      DrawArrowUp(b.ToString(), true, 0, Low[0] - TickSize, Color.Green);//short term low


      mydataseries.Set(a);

      if (CurrentBar < 100)
      return;

      int count = 0;// for medium term high
      do // this loop works fine and gives left side short term High
      {
      count = count + 1;
      }
      while (mydataseries[count] == 0 );

      int count1 = 0;
      int myno = 0;
      /*do// this loop does not work even though ensured to be finite(no complitation error but NT crashes) - //this is for right side short term high
      {
      myno = myno + 1;
      count1 = count1 - 1;
      }
      while (mydataseries[count1] == 0 && myno <= 50) ;*/

      if (mydataseries[0] > mydataseries[count] && mydataseries[0] > mydataseries[-count1])//no problem with this

      DrawText(mydataseries[0].ToString(),"MTH", 0, High[0] + 8, Color.Red);

      }

      #region Properties
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
      [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
      public DataSeries Plot0
      {
      get { return Values[0]; }
      }

      #endregion
      }
      }

      Comment


        #4
        In the do loop it looks to see if the value of count1 is 0, yet this value is being decremented from 0 immediately. I am not 100% sure why this causes an issue however, I am able to resolve it simply by removing the check for equals 0. For example:
        Code:
        			int count1 = 0;	
        			int myno = 0;	
        			do// this loop does not work even though ensured to be finite(no complitation error but NT crashes) - //this is for right side short term high 
        			{
        			myno = myno + 1;
        			count1 = count1 - 1;
        			}
        			// mydataseries[count1] == 0 && 
        			while (myno <= 50) ;

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          In the do loop it looks to see if the value of count1 is 0, yet this value is being decremented from 0 immediately. I am not 100% sure why this causes an issue however, I am able to resolve it simply by removing the check for equals 0. For example:
          Code:
          			int count1 = 0;	
          			int myno = 0;	
          			do// this loop does not work even though ensured to be finite(no complitation error but NT crashes) - //this is for right side short term high 
          			{
          			myno = myno + 1;
          			count1 = count1 - 1;
          			}
          			// mydataseries[count1] == 0 && 
          			while (myno <= 50) ;
          Hi!
          If you take out (mydataseries == 0) is as good as take out loop
          Conclusion is that NT charting platform can not handle negative indexing in loop. This is a lacuna if you don't like to call it a bug. I never had any problem with negative indexing in any other charting platform.
          As I had pointed out in other thread, it even causes problem in conditional statement 'if' when used at very beginning.

          Comment


            #6
            You are correct in that a negative index cannot be used, and that is why the do while fails.
            However, you can loop with negatives as long as you do not use the negative for an index in a Data Series.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            26 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by bmartz, 03-12-2024, 06:12 AM
            3 responses
            29 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by Aviram Y, Today, 05:29 AM
            2 responses
            9 views
            0 likes
            Last Post Aviram Y  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X