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

Referencing past values of a definition

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

    Referencing past values of a definition

    Hello,

    I am new to C# and I am working to convert my code from my previous coding language into Ninjatrader.
    What I could do in my original code was I could reference previous values of definitions.
    For instance, I could make the strategy calculate a current value based upon a previous value of that value.

    Here is my code as of now:
    Note that I am trying to use [1] to reference the previous value of that definition.
    However, the code is not compiling and I cannot reference these values.

    Any help is appreciated, thank you!

    Code:
    if (myCCI > 0)
    {
    MT1 = (Math.Max(MT1[1], Median[0] - ATRCCI));
    }
    else
    {
    MT1 = (Math.Min(MT1[1], Median[0] + ATRCCI));
    }
    
    // Alignment of two different indicators
    if ((Close[0]> Stade) & (Close[0] > MT1))
    {
    double State2 = (StateUp);
    }
    else if ((Close[0] < Stade) & (Close[0] < MT1))
    {
    double State2 = StateDn;
    }
    else
    double State2 = State2[1];
    
    if (Math.Max(State2 != State2[1]))
    Math.Max(newState = bar);
    else
    Math.Max(newState = 0);

    #2
    Hello ArcticBiscuit,

    Thanks for your post.

    I see that you are trying to access the previous value held by a double variable.

    Double variables are only able to hold a single value at a time and any previous values will be overwritten when a new value is assigned to the double variable. This means that you would only be able to access the current value that is assigned to the double variable.

    If you would like to access previous values held by the double variable, you would need to change it to be a Series<double> variable. Then, you could access the current value assigned to the Series<double> or previous values that were held by that variable.

    For example, if you have a Series<double> variable called mySeriesDouble, you could access the current value by calling mySeriesDouble[0]. To access the previously held value, you would call mySeriesDouble[1].

    See this help guide page for more information about Series<double> variables and sample code: https://ninjatrader.com/support/help...t8/seriest.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by ArcticBiscuit View Post
      Hello,

      I am new to C# and I am working to convert my code from my previous coding language into Ninjatrader.
      What I could do in my original code was I could reference previous values of definitions.
      For instance, I could make the strategy calculate a current value based upon a previous value of that value.

      Here is my code as of now:
      Note that I am trying to use [1] to reference the previous value of that definition.
      However, the code is not compiling and I cannot reference these values.

      Any help is appreciated, thank you!

      Code:
      if (myCCI > 0)
      {
      MT1[B][COLOR=#e74c3c][0][/COLOR][/B] = (Math.Max(MT1[1], Median[0] - ATRCCI));
      }
      else
      {
      MT1[B][COLOR=#e74c3c][0][/COLOR][/B] = (Math.Min(MT1[1], Median[0] + ATRCCI));
      }
      
      // Alignment of two different indicators
      if ((Close[0]> Stade) & (Close[0] > MT1[COLOR=#e74c3c][B][0][/B][/COLOR]))
      {
      double State2 = (StateUp);
      }
      else if ((Close[0] < Stade) & (Close[0] < MT1[COLOR=#e74c3c][B][0][/B][/COLOR]))
      {
      double State2 = StateDn;
      }
      else
      double State2 = State2[1];
      
      if (Math.Max(State2 != State2[1]))
      Math.Max(newState = bar);
      else
      Math.Max(newState = 0);
      Make sure that MT1 is a Series<double> and you're all set.

      Looks like you were missing using the 'MT1[0]' slot position.
      You need the indexing '[0]' suffix to do that, see above.

      Last edited by bltdavid; 07-26-2022, 09:54 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      98 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      160 views
      0 likes
      Last Post loganjarosz123  
      Working...
      X