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

Optimizing NT7-script-strategies

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

    Optimizing NT7-script-strategies

    Hello,

    I have a lot of lines in my NT7-script-strategies because I do handle all orders with customized buttons.

    Is it possible to have all the codes eg "private void btncloseall_Click(object s, EventArgs e)" if(.......................) in a section so that its only "used" by NT when clicking a button. I assume when ""private void..." is on same "level" as onbarupdate then NT has to read it all the time(?) Maybe this is a wrong assumption, and I´m happy if this is not a problem for the CPU.

    Can all the "private void..." code concerning the buttons be in a proper section (eg like onorderupdate or onexecution) so that its only used when clicking a button and does not slow down NT7? My NT is frozen very often and I assume this has to do with the many lines in the code.

    Thank you!
    Tony

    #2
    Hello,

    Thank you for the post.

    You are correct that adding more code will inherently make the file larger and may cause longer load time as there is obviously more logic being executed. The button logic would only be executed when you click a button though. NinjaTrader is not going to read the file from top to bottom and execute everything all at once. It does read the file and then events call methods depending on the event.

    The amount of logic and complexity of that logic will ultimately control performance, once the code has loaded the size of the file doesn't necessarily matter as much as the logic
    that is executed.

    If you want to clean the file up or make it more readable/reduce its size, you can take advantage of C# structure. One example would be to make a class with your custom methods in it and then utilize that class. A second class can be placed in a second file

    A partial class may be more beneficial as it would be derived from the base type allowing for NinjaScript functions to work.

    You could see the UserDefinedMethods file for an example of a partial class. You can also search the internet for "C# partial class examples" for further reading.

    If you are having freezing my suggestion is always to reduce the code to find the reason for the freezing and then address that specifically.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. An accurate question concerning reducing lines in the NT7 script please:
      lets assume with an entry we have 3x2 positions (total 6 contracts long).
      So I have assigned to move stop by conditions or buttonclick with
      SetProfitTarget(A, ....)
      SetProfitTarget(B, ....)
      SetProfitTarget(C, ....)

      and with other conditonset true change the stop
      SetStopLoss(A,...)
      SetStopLoss(B,...)
      SetStopLoss(C,...)


      What if there are only 2 contracts C in the trade because A and B is off already (with Target or Stop). Would a command as shown here above with SetStopLoss or SetProfittarger for A, B and C cause issues becaue A and B are flat already? Or would this cause a new entry limit?

      Thank you!
      Tony
      Last edited by tonynt; 09-29-2017, 09:33 AM. Reason: translation error, clearifying

      Comment


        #4
        Hello,

        Thank you for the reply.

        Using the managed approach, if there is no entry with the signal name your Set method is referencing, it would not be submitted. A Set method would need to be paired with a signal name for this to occur, using the overload set with no signal name would assume you meant the position and would exit if there is a position held.

        When using the managed approach and its logic come into question, I would highly suggest that you test the situation from your end using a test script. As you have the tools to determine the answer to this question, it would always be suggested to do the tests from the logic you will end up using. If this is happening from button presses, I would suggest testing that situation from your end so you know it works as expected for you. There are cases where you can confuse the managed approach, using buttons may induce these situations more frequently than not using buttons and allowing the event-driven script to control the logic. Because this is a more complex approach you will need to test your logic thoroughly from your platform.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          ok, thank you for your reply. Another question please: instead of having a NT7-script-strategy with eg 3.000 lines would it be better to have 2 scripts each 1.500 lines. Or is there no difference for NT to read and execute and slow down?

          Thank you
          Tony

          Comment


            #6
            Hello,

            It would likely be best to retain a single file, it is not recommended to split a NinjaScript strategy into two separate strategies. If you are instead referring to just splitting the logic and using C# structures, that would be fine to use multiple files as you are still only running 1 strategy. Splitting a file will not directly help with slowness, again once the file has been loaded your logic will control how the platform reacts in reagrd to speed.

            If you are having slowness or freezing I would suggest to try and isolate that to correct it opposed to looking for other options to correct it. Slow logic can really only be fixed by correcting the logic, trying other approaches like splitting the file or trying to clean it up will not work if the logic is slow to begin with. There can also be a hardware factor, if you have extremely complex logic and your hardware cannot handle the calculations being used, you may need better hardware to avoid slowness.

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Yesterday, 09:43 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            5 responses
            551 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rtwave, 04-12-2024, 09:30 AM
            5 responses
            37 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by funk10101, Today, 12:02 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by GLFX005, Today, 03:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X