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 daniel_weber8, Today, 01:21 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Started by jungsoohuh, Today, 12:07 PM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by SharonSS, Today, 11:54 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by crystalet, Today, 11:20 AM
            3 responses
            17 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by SuperDude123, Today, 09:23 AM
            1 response
            34 views
            0 likes
            Last Post NinjaTrader_JustinD  
            Working...
            X