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

Help on Ninjascript

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

    #16
    Originally posted by NinjaTrader_PatrickH View Post
    Hello nemesis45,

    Thank you for your response.

    Can you provide a copy of the strategy using the custom method in OnStartUp() and the use of OnTermination() that is not working?
    Please find the cs file attached.

    It's the same code but with all declarations inside of OnStartUp()
    The OnTermination() contains
    protected override void OnTermination()
    {
    secondtimer.Stop();
    secondtimer.Dispose();
    // Cleans up our Timer object

    }

    but the timer continues to get fired randomly even after i call Dispose()
    Attached Files

    Comment


      #17
      Hi,

      Edit: The timer i am using is firing twice instead of once every 10 seconds.
      Do you have any idea what could cause this? I will check the rest of the code, once i get the timer to work.

      I fixed the code for the timer , copying what you have provided in your sample references
      it uses
      System.Windows.Forms; instead of System.Timers

      The timer is firing correctly at every 10 seconds. But the issue is that it is firing twice and not once.

      I have attached the cs file.

      One thing which i notice is that, if i initialise my variables in OnStartup(),
      it gives an error, works if i initialise them in Initialise() , could you please share their internal working. It should not be a problem if they are only being called once at start of strategy.

      Also, The timer is being initialise in OnStartUp(), even in your reference code for generating lvl2 orderbook

      Also, my NinjaTrader is crashing quite often, using the code for the timer
      Attached Files
      Last edited by nemesis45; 04-16-2014, 07:35 AM.

      Comment


        #18
        ok, i did a dumb piece of programming and now my NT keeps on crashing.

        Added an instance of strategy in the strategy itself.
        was trying to use Print, without a local instance of strategy.

        Any idea how to get my NT running again?

        So far reinstalling hasnt worked. Could you please reply soon.

        nvm got it, could you please help with the code debug.
        Last edited by nemesis45; 04-16-2014, 10:40 AM.

        Comment


          #19
          Hello nemesis45,

          I apologize for the delay. I am still testing this on my end to find out why we are getting two prints for the same second from the Timer. I noticed the date of the print is 1/1/1800 so it is not correctly pulling the time for that first print.

          Comment


            #20
            Originally posted by nemesis45 View Post
            Hi,


            The timer is firing correctly at every 10 seconds. But the issue is that it is firing twice and not once.

            I have attached the cs file.


            Also, my NinjaTrader is crashing quite often, using the code for the timer
            You should use a static variable to count instances being created and removed. It is helpful in counting to make sure you are dealing with only 1 instance and not more than that. I remember having issues and restarting NT helped clear them out.


            I wrote something similar, but used the recommended code in the HELP manual.
            Code:
            #using System.timers;
            ...
            ...System.Timers.Timer
            If this is all you are using the link list for, you might want to switch to an NT DataSeries.
            That's what I did to store prices in memory and write out after close.

            Comment


              #21
              Originally posted by NinjaTrader_PatrickH View Post
              Hello nemesis45,

              I apologize for the delay. I am still testing this on my end to find out why we are getting two prints for the same second from the Timer. I noticed the date of the print is 1/1/1800 so it is not correctly pulling the time for that first print.
              Thanks for the reply. I did not notice the date of the print as 1/1/1800, is that from the eventhandler argument e? or from datetime.now? datetime.now is printing the correct date of course for me. Is that the error the first time or every 10 seconds.

              Could you please tell me if there are any other errors you notice. will help me debug.

              Comment


                #22
                Originally posted by sledge View Post
                You should use a static variable to count instances being created and removed. It is helpful in counting to make sure you are dealing with only 1 instance and not more than that. I remember having issues and restarting NT helped clear them out.


                I wrote something similar, but used the recommended code in the HELP manual.
                Code:
                #using System.timers;
                ...
                ...System.Timers.Timer
                If this is all you are using the link list for, you might want to switch to an NT DataSeries.
                That's what I did to store prices in memory and write out after close.
                I am having accessing problems accessing static objects from custom methods in the first place. will give it a try once i can get what is wrong here. Assuming you mean checking for datetime and not run the code if the time stamp is same.

                I have copied the code directly from NT reference sample.
                I am actually using the LinkedList to pass and store other custom objects. that script wasnt working so i wrote a less bulky sample script to find out what was wrong.

                Comment


                  #23
                  Thanks Patrick i got it working now.

                  Comment


                    #24
                    Custom Linked List object

                    Edit: nvm i see you have a reference code for the same. ill get it working from there.
                    Last edited by nemesis45; 04-17-2014, 10:46 AM.

                    Comment


                      #25
                      Hello nemesis45,

                      My apologizes it took so long to get back to you on this. Let me know if you find any other anomalies while testing this timer out.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,603 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X