Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Timer events

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

    Timer events

    Greetings,
    Is it possible triggering custom events ?

    I'd like triggering one event every second for displaying the current time.
    I used System.Timers.Timer but doesn't work. Only displays when receives ticks.


    Thanks very much.




    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    ///<summary>
    /// Contador de cuenta atrás
    ///</summary>
    [Description("Contador de cuenta atrás")]
    publicclass ZiTimer : Indicator
    {
    #region Variables

    private Timer aTimer = new
    Timer();
    privatebool bInit = true;
    #endregion

    privatevoid OnTimedEvent(object source, ElapsedEventArgs e){
    DrawTextFixed("Timer", DateTime.Now.ToLongTimeString(), TextPosition.TopLeft );}




    protectedoverridevoid OnBarUpdate(){
    if ( bInit ){
    aTimer.Elapsed +=
    new ElapsedEventHandler(OnTimedEvent);
    aTimer.Interval =
    1000;
    aTimer.Enabled =
    true;
    GC.KeepAlive(aTimer);
    bInit =
    false;}

    }

    }




    #2
    This is beyond what we can provide support for. However, here are some hints:
    - we usually start timers by timer.Start()
    - you should use System.Windows.Form.Timer and not System.Timers.Timer, since the former throws the timer event in the main thread which makes sure you indicator/strategy works as expected
    - no need to register the timer at the garbage collector
    - NT6.5: please press F1 and scan help guide for TriggerCustomEvent

    Comment


      #3
      Thanks Dierk,

      but TriggerCustomEvent only works with ticks.
      If I want to trigger one event more fast that one tick, doesn't work.

      Greetings.

      Comment


        #4
        I'm trying with System.Windows.Forms.Timer but it doesn´t work neither.
        Only works if receives ticks data.


        Thanks very much.




        using System.Windows.Forms;

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {

        ///<summary>
        /// Contador de cuenta atrás
        ///</summary>
        [Description("Contador de cuenta atrás")]
        publicclass ZiTimer : Indicator
        {
        #region Variables
        privatebool bInit = true;
        private Timer myTimer = new System.Windows.Forms.Timer();
        #endregion



        privatevoid TimerEventProcessor(Object myObject, EventArgs myEventArgs) {
        TriggerCustomEvent(MyCustomHandler,
        this);}

        privatevoid MyCustomHandler(object state){
        DrawTextFixed(
        "Timer", DateTime.Now.ToLongTimeString(), TextPosition.TopLeft );}




        protectedoverridevoid OnBarUpdate(){
        if ( Historical ) return;

        if ( bInit ){
        myTimer.Tick +=
        new EventHandler(TimerEventProcessor);
        myTimer.Interval =
        1000;
        myTimer.Enabled =
        true;
        myTimer.Start();
        bInit = false;
        }


        }


        Comment


          #5
          We will provide a sample shortly.

          Comment


            #6
            Originally posted by NinjaTrader_Dierk View Post
            We will provide a sample shortly.
            Thanks very much, Dierk
            I can't wait

            Comment


              #7
              Great, will take a little while since the whole team has been in NYC for the show over the last weekend.

              Comment


                #8
                Hello Dierk,
                excuse me for my wearisome insistence, but could you help me with this problem ?
                Thanks very much

                Comment


                  #9
                  Sorry for the delay, this issue is not forgotten. We will post something within the next few days.

                  Comment


                    #10
                    I am wrapping up a project that relies on a timer event to take a snapshot of Level 2 values each second. I started with the System.Windows.Form.Timer but since I wanted to capture data from OnMarketDepth() and not the OnBarClose() method, I ended up using the System.Timers.Timer without using a TriggerCustomEvent. The point being it would be useful to see a reference example(s) that can be used across different update methods and not necessarily tied to an incoming tick.

                    Regards,

                    Whitmark
                    Last edited by whitmark; 03-03-2008, 11:25 AM.
                    whitmark
                    NinjaTrader Ecosystem Vendor - Whitmark Development

                    Comment


                      #11
                      You can use the TriggerCustomEvent across the board. The timer event is just a sample.

                      Comment


                        #12
                        Please take a look at this reference sample: http://www.ninjatrader-support.com/v...0463#post30463
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Josh, your reference sample was very relevant and helpful to put the finishing touches on what I was working on.

                          Regards,

                          Whitmark
                          whitmark
                          NinjaTrader Ecosystem Vendor - Whitmark Development

                          Comment


                            #14
                            Thanks very much Josh, but this solution doesn't work if I want to plot one drawstring, e.g.

                            If NT doesn´t receive ticks, doesn´t plotting.

                            Is there any way for calling to the Plot method inside one Timer.

                            Greetings.

                            Comment


                              #15
                              Not sure I follow: You can call any NinjaScript method you'd like on the event handler (Draw... methods, order methods, anything). Why would you want to deal with the Plot method?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              571 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              330 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              549 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              549 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X