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

Time problem

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

    Time problem

    Hi guys,
    I need some help.. I want to show the current time on chart (not only on time based chart). The point is a nonstop clock which updates itself every single seconds.

    Many thanks,
    Curi

    #2
    Hello,

    You can get the current time of your system by using DateTime.Now

    If you'd like it to update every single second, you'll have to create your own custom trigger event to call that method at the pre-defined interval you would like:



    I'm providing a reference sample which uses the TriggerCustomEvent which should help you get started:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Many thanks for your quick answer!! It sounds good.

      One more simple question: in order to visualize the current time on the chart, the right choice is DrawText methode in MyCustomHandler(object state), isn't it?

      Comment


        #4
        Yes, that should work.

        Please let me know if you have any questions.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Hi Matthew,

          I tried TriggerCustomEvent to solve my problem. But the time on the chart doesn't update every seconds.. only if something happens on the chart.
          I used that indicator what you linked. In that indicator the update works good, we get new time data on output window in every seconds.
          I modified the Print methode to DrawTextFixed:

          Code:
          		private void MyCustomHandler(object state)
          		{
          
                                  //Print("\tTime: " + DateTime.Now);
          			//Print("\tTimer Interval: " + state.ToString() + "ms");
          			
          			DrawTextFixed("tag",DateTime.Now.ToString(),TextPosition.TopLeft);
          		}
          What can I do for the persistent update?

          Comment


            #6
            You'd need to add some logic in your MyCustomHandler to check the last time that the timer updated, and then call the plot method to update via ChartControl.ChartPanel.Invalidate();

            Code:
            		private void MyCustomHandler(object state)
            		{
            			if(DateTime.Now.Subtract(pcTime).Seconds >= 1)
            			{
            				ChartControl.ChartPanel.Invalidate();
            				pcTime = DateTime.Now;
            			}
            			
            			DrawTextFixed("time", pcTime.ToString("HH:mm:ss"), TextPosition.TopRight);
                    
            		}
            I've attached a working copy which should help clarify.
            Attached Files
            MatthewNinjaTrader Product Management

            Comment


              #7
              Thank you very much!!! This is so useful!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cls71, Today, 04:45 AM
              0 responses
              1 view
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Working...
              X