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

myTimer @ 30 seconds

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

    myTimer @ 30 seconds

    I've built up a Timer from the posts here, and set it for 30 seconds.

    I tested it on ES last night on 30 second ES chart, and it was hitting every 30 seconds...and doing it's business.

    Well, today, I put the indicator, with a 30 second timer, on a 1 minute chart, and then it only fired every one minute!!! LOL



    OnBarUpdate was in charge of plotting my lines every 1 minute...

    Code:
    		// Initiate our Timer object with an interval of 1000ms (1 second)
             	MyTimer.Interval=30000; //30 seconds
             	MyTimer.Enabled=true;
    Which called TimerEventProcessor, which calls MyCustomHandler..and then Sets the dataseries.....

    Oh smacks....

    that might be why.. the dataseries might be tied to the OnBarUpdate still...

    so is anyone else aware of this?

    So I was setting every 30 seconds probably, but the dataseries.Set would simply over write what was there previously, since it didn't advance from an OnBarUpdate call of 1 minute.

    My chart is set today to 30 seconds, so I expect 1080 or so data points.

    I'm pretty sure only 4 other people here would understand what's going on.

    #2
    Correct sledge, the series would be tied / synched to the primary bars index per default. You can change that though and sync to an added series as well -

    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


    However you would need to keep in mind, the bars update would not be strictly time based, but event based in OnBarUpdate(), so if no new tick for example is seen to close a particular bar > it would stay open until that tick is seen.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by sledge View Post
      I've built up a Timer from the posts here, and set it for 30 seconds.

      I tested it on ES last night on 30 second ES chart, and it was hitting every 30 seconds...and doing it's business.

      Well, today, I put the indicator, with a 30 second timer, on a 1 minute chart, and then it only fired every one minute!!! LOL



      OnBarUpdate was in charge of plotting my lines every 1 minute...

      Code:
              // Initiate our Timer object with an interval of 1000ms (1 second)
                   MyTimer.Interval=30000; //30 seconds
                   MyTimer.Enabled=true;
      Which called TimerEventProcessor, which calls MyCustomHandler..and then Sets the dataseries.....

      Oh smacks....

      that might be why.. the dataseries might be tied to the OnBarUpdate still...

      so is anyone else aware of this?

      So I was setting every 30 seconds probably, but the dataseries.Set would simply over write what was there previously, since it didn't advance from an OnBarUpdate call of 1 minute.

      My chart is set today to 30 seconds, so I expect 1080 or so data points.

      I'm pretty sure only 4 other people here would understand what's going on.
      Depends. Are you calling your timer from OBU?

      Comment


        #4
        Originally posted by koganam View Post
        Depends. Are you calling your timer from OBU?
        Nope.

        Another thing to note - before I had OnTermination to Dispose(), TimerEventProcessor was firing for each 'dead object'...but only 1 call was getting through to MyCustomHandler.

        I put in object count to make sure I only have 1 object floating around.

        So yeah - setting the timeout < the timeframe of the chart doesn't work. It'll only hit at the timeframe of the chart.


        Code:
        		private System.Timers.Timer MyTimer = new System.Timers.Timer();
        		public static int obj_ct = 0;
        					
        		protected override void OnStartUp()
                {
        			MyTimer.Elapsed+=new ElapsedEventHandler(TimerEventProcessor);
        
        			// Initiate our Timer object with an interval of 1000ms (1 second)
                 	MyTimer.Interval=30000; //30 seconds
                 	MyTimer.Enabled=true; 			//myTimer.Start();
        			
        			obj_ct ++;
        			
        			Print ( "NT OnStartUp() - MyTimer.Enabled obj_ct=" + obj_ct );
                }
        
        
        		private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
        		{
        		    // Do not process your code here but instead 
        			// call the TriggerCustomEvent()
        		    // method and process your code in the 
        			// MyCustomHandler method
        		    TriggerCustomEvent(MyCustomHandler, 0, "MyTimer");
        			//Print ( "Finished TimerEventProcessor obj_ct=" + obj_ct);
        			
        		}
        
        		private void MyCustomHandler(object state)
        		{
        			
        			// DO STUFF HERE
        
                }
        		// Important to clean up our resources
        		protected override void OnTermination()
        		{
        			// Cleans up our Timer object
        			Print ( "NT OnTermination() MyTimer.Dispose obj_ct=" + obj_ct );
        			MyTimer.Dispose();
        		}
                protected override void OnBarUpdate()
                {
        			if (Historical) return;
        
        			Series1.Set ( highprice );
                    Series2.Set ( lowprice );
        			
        		}
        		protected override void OnMarketData(MarketDataEventArgs e)
        		{
        			if (e.MarketDataType==MarketDataType.Last )
        			{
        				this.lastprice = e.Price;
        		
        			}	
        		}

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        4 views
        0 likes
        Last Post AveryFlynn  
        Started by RubenCazorla, 08-30-2022, 06:36 AM
        3 responses
        79 views
        0 likes
        Last Post PaulMohn  
        Started by f.saeidi, Yesterday, 12:14 PM
        9 responses
        25 views
        0 likes
        Last Post f.saeidi  
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        5 views
        0 likes
        Last Post FrancisMorro  
        Working...
        X