Announcement

Collapse
No announcement yet.

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 -

    http://www.ninjatrader.com/support/f...ead.php?t=3572

    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 DTSSTS, Yesterday, 07:11 PM
        2 responses
        32 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by ntbone, Yesterday, 11:42 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by mr_trade, 11-26-2020, 05:01 PM
        5 responses
        59 views
        0 likes
        Last Post mr_trade  
        Started by evanp90, 01-14-2021, 07:03 PM
        4 responses
        33 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by fernlicht, Today, 04:01 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jason  
        Working...
        X