• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 dtl-saw, Yesterday, 08:44 PM
            0 responses
            12 views
            0 likes
            Last Post dtl-saw
            by dtl-saw
             
            Started by ballboy11, Yesterday, 04:29 PM
            0 responses
            10 views
            0 likes
            Last Post ballboy11  
            Started by zacharydw00, Yesterday, 02:29 PM
            2 responses
            30 views
            0 likes
            Last Post zacharydw00  
            Started by timcjpfx, Yesterday, 06:22 AM
            4 responses
            27 views
            0 likes
            Last Post timcjpfx  
            Started by welson, Yesterday, 08:26 AM
            2 responses
            18 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Working...
            X