Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            45 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            21 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            31 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            50 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Working...
            X