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 Perr0Grande, Today, 08:16 PM
            0 responses
            2 views
            0 likes
            Last Post Perr0Grande  
            Started by elderan, Today, 08:03 PM
            0 responses
            3 views
            0 likes
            Last Post elderan
            by elderan
             
            Started by algospoke, Today, 06:40 PM
            0 responses
            10 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            9 views
            0 likes
            Last Post maybeimnotrader  
            Started by quantismo, Today, 05:13 PM
            0 responses
            7 views
            0 likes
            Last Post quantismo  
            Working...
            X