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

Strategy performance issues

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

    Strategy performance issues

    Hello

    I have a code finding flat parts of an indicator, which then makes List with. My question is, for the best script performance, should I use the first code, or the second?

    Thank you


    Code:
    // Variant 1
    if (Math.Abs(DMI1[1] - DMI1[2]) < 0.0001)
    {                                       
          FlatDMI.Add(DMI1[1]);

    Code:
    // Variant 2
    if (!FlatInd && Math.Abs(DMI1[1] - DMI1[2]) < 0.0001)
    {      
          flat =  DMI1[1]                                
          FlatDMI.Add(flat);

    #2
    Hello itrader46,

    Creating a new variable which needs memory, assigning it a value which takes an operation, and then using this will take an unperceivable amount of more work.
    Using the value that already exists would use less work.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      I take it Variant 1 is better, then?

      I thought so myself, but just wanted to check, as my code got longer every day and I am now in a process of eliminating bits I don't actually need.

      The code below is from Ninja Best Practices -> Referencing indicator methods, with mySma initialised in State.Historical.

      With my DMI1 being initialised in OnStateChange() -> State.DataLoaded, would that make any difference?

      Code:
      private SMA mySma;
      
      protected override void OnStateChange()
      {
        // when the indicator begins processing
        // save an instance of the SMA indicator with the desired input  
        if (State == State.Historical)
        {
          mySma = SMA(20);
        }

      Comment


        #4
        Hello itrader46,

        Assigning the instance of an indicator to a variable is often useful to access the indicator at a later time.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea.
          Do you mind reading and addressing the issues my previous post?
          Thank you

          Comment


            #6
            Hello itrader46,

            No, calling an indicator after the data is ready in DataLoaded will not make a difference.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            53 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            33 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            5 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            19 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            6 views
            0 likes
            Last Post cre8able  
            Working...
            X