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

NT8 Indicator Definition can cripple exec speed

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

    NT8 Indicator Definition can cripple exec speed

    Hello Support,

    I’ve uploaded 2 simple strategies.

    1st strategy is, MyCustomStrategy80 uses a custom indicator (SQBBandWidthRatio) defined at the Class level, assigned at State.Dataloaded in the OnStateChange() event.

    2nd strategy is MyCustomStrategy85 is a copy of MyStrategy80 BUT, the indicator is defined in-flight in the OnBarUpdate() event

    Both strategies do the same trades, BUT their indicator is defined and assigned differently. Both scripts compile and executed properly.

    I’ve also inserted a simple Print statement after every new bar in both scripts. This Print statement provides C# Timespan in milliseconds between each bar.

    MyCustomStrategy80 execution was quick and normal with the following bar Prints
    9ms 1/2/2017 6:45:00 PM: NEW Processing bar
    0ms 1/2/2017 7:00:00 PM: NEW Processing bar
    0ms 1/2/2017 7:15:00 PM: NEW Processing bar
    0ms 1/2/2017 7:30:00 PM: NEW Processing bar
    0ms 1/2/2017 7:45:00 PM: NEW Processing bar
    ...
    0ms 1/31/2017 4:00:00 PM: NEW Processing bar
    0ms 1/31/2017 4:15:00 PM: NEW Processing bar
    0ms 1/31/2017 4:45:00 PM: NEW Processing bar
    MyCustomStrategy85 execution was slow and abnormal with the following bar Prints
    25ms 1/2/2017 6:45:00 PM: NEW Processing bar
    23ms 1/2/2017 7:00:00 PM: NEW Processing bar
    4ms 1/2/2017 7:15:00 PM: NEW Processing bar
    4ms 1/2/2017 7:30:00 PM: NEW Processing bar
    5ms 1/2/2017 7:45:00 PM: NEW Processing bar
    ...
    19ms 1/31/2017 4:00:00 PM: NEW Processing bar
    19ms 1/31/2017 4:15:00 PM: NEW Processing bar
    21ms 1/31/2017 4:45:00 PM: NEW Processing bar
    I’ve tried this same test using the standard NT8 RSI indicator. Both Scripts executed NORMALLY.

    My question is, what needs to be defined to a custom indicator so that it can be defined in-flight at OnBarUpdate() event of a strategy so that the execution speed of the strategy returns back to normal with sub-millisecond time between bars ?

    I’m converting my trading strategies to NT8 and they all define indicators in-flight / in-line with the OnBarUpdate() event, and they are all have this execution speed problem.

    I wrote these test scripts for NT Support to replicate the error I see and to provide support.

    Can you please take a look at the scripts and custom indicator and let me know what I need to define to the custom indicator so that execution of MyCustomStrategy85 will be quick and normal like MyCustomStrategy80.

    Please let me know


    Thank you
    Attached Files
    Last edited by rayko; 10-23-2017, 01:11 PM. Reason: Title Change

    #2
    Hello rayko,

    Thanks for the post.

    I am running tests on my end in real time and the two strategies are printing very close to each other. Please see my screenshots for comparison Output 1 is Strategy 80 and Output 2 is Strategy 85. I have both of these Strategies set to 'On Each Tick'. Other than the backtest data, the strategies run with the same time complexity in real time.

    Please confirm how are you testing these scripts so I can test in the same way. From all of my test, both in the Strategy Analyzer and running in real-time, this script is running nominally.

    I look forward to your reply.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello ChrisL,

      I am running them in Backtest using System Analyzer.

      If you look back to the first msg of this thread, you'll see I've uploaded a screen scrape of SA so you can see the parms I used.

      Please let me know

      Thank you

      Comment


        #4
        Hello rayko,

        Thanks for the reply.

        It would be faster if you instantiate your indicator once at the class level like in Strategy 80.

        If you are looking to time the OnBarUpdate() function, I would suggest using the StopWatch class instead of DateTime.Now. Please see my example below, "..." denotes that I have left out code:

        Code:
        public class StopwatchIndicator : Strategy{
        
        private Stopwatch stopWatch;
        
        protected override void OnStateChange()
        		{
        			if (State == State.SetDefaults){
                                        ...
                                        stopWatch = new Stopwatch();
                                }
        
                         }
        
        protected override void OnBarUpdate()
        		{
                                stopWatch.Start();
        			
        			double value = SQBBandWidthRatio(60, 0.3)[0];
        			
        			stopWatch.Stop();
        			
        			 TimeSpan ts = stopWatch.Elapsed;
        			
        			string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                ts.Hours, ts.Minutes, ts.Seconds,
                                ts.Milliseconds / 10);
        			
        			Print("Time to call indicator: " + elapsedTime);
        			
        			stopWatch.Reset();
        			
        		}
        
        ...
        
        }
        Please let me know if you are able to see the difference after implementing this.

        Here is a publicly available link to the Stopwatch class:
        Provides a set of methods and properties that you can use to accurately measure elapsed time.


        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello ChrisL,

          I apologize if I wasn't clear with my question.

          My question is, what do I need to define to the custom indicator SQBBandWidthRatio so that execution of MyCustomStrategy85 will be quick and normal using System Analyzer in Backtest mode like it is in NT7?

          MyCustomStrategy85 uses indicator SQBBandWidthRatio the same way I've have them defined in the NT7 strategies I'm converting.

          NT7 processes bars taking less than 0 milliseconds with indicators defined inflight/inline

          But with the example I provided, NT8 processes bars 100x slower using the same inflight/inline indicator definitions.

          When converting strategies from NT7 to NT8, my understanding is the ninjascript code should Not have to change all indicator definitions to the Class level.

          So
          my question is what must me done to indicator SQBBandWidthRatio so the NT8 execution speed of MyCustomStrategy85 matches that of NT7.

          If the indicator is not the subject of change, then what must change in the strategy so that the NT8
          execution speed of MyCustomStrategy85 match that of NT7.

          Please let me know

          Thank you

          Comment


            #6
            Hello rayko,

            Thanks for the reply.

            What needs to be done to the strategy is initializing the Indicator you are using at the class level. If you make explicit calls to the indicator in OnBarUpdate(), it will be less efficient on memory. Please run a backtest on the modified version of your strategy that I have attached.

            Please let us know if we may be of any further assistance.
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by TraderBCL, Today, 04:38 AM
            2 responses
            6 views
            0 likes
            Last Post TraderBCL  
            Started by martin70, 03-24-2023, 04:58 AM
            14 responses
            105 views
            0 likes
            Last Post martin70  
            Started by Radano, 06-10-2021, 01:40 AM
            19 responses
            606 views
            0 likes
            Last Post Radano
            by Radano
             
            Started by KenneGaray, Today, 03:48 AM
            0 responses
            4 views
            0 likes
            Last Post KenneGaray  
            Started by thanajo, 05-04-2021, 02:11 AM
            4 responses
            471 views
            0 likes
            Last Post tradingnasdaqprueba  
            Working...
            X