Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Timer wrong activity

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

    Timer wrong activity

    Hi,
    Taking this official example:
    https://ninjatrader.com/support/help...barsperiod.htm

    I am setting a timer in my indicator code, but this doesnt work.
    No error on the compilation, and "MyCondition" are working


    What I am doing bad?

    Thank you




    PHP Code:
            private System.Windows.Forms.Timer alertTimer = new System.Windows.Forms.Timer();
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults) {
    
    
                }
                else if (State == State.Configure) {
    
                    alertTimer.Tick += new EventHandler(alertTimerFunction);
                    alertTimer.Interval = 1000;
                }
                else if (State == State.Configure) { }
                else if (State == State.Terminated) {
    
                    alertTimer.Stop();
                    alertTimer.Tick -= new EventHandler(alertTimerFunction);
                }
            }
    
    
    
    private void alertTimerFunction(Object myObject, EventArgs myEventArgs){
        if (CurrentBar > 0){
            TriggerCustomEvent(alertTimerEject, Close[0]);
        }
    }
    private void alertTimerEject(object nada){
        Print("alertTimerFunction " + DateTime.Now);
    }
    
    
    
    
    protected override void OnBarUpdate(){
            if(myCondition){
                  Print("My condition works");
                  alertTimer.Start();  
             }
    } 
    
    Last edited by ninjo; 11-12-2018, 11:39 AM.

    #2
    Hello ninjo,

    Thank you for the post.

    What is the action you are doing in the timers alertTimerFunction? that was not displayed in the sample.

    I would be unsure what is happening without seeing the alertTimerFunction method.

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse, excuse me, i forgot part of the code.

      I edited the code and added the lost functions.
      Its a simple example that are printing in the output window.

      Thank you.

      Comment


        #4
        Hello ninjo,

        Thank you for the reply.

        I would be unsure why what you provided is not working by looking at it.

        I tested the sample from our help guide here: https://ninjatrader.com/support/help...gerCustomEvent

        And see this working on my end, I have attached that sample as a zip. Can you try applying this to a chart and check the output window?

        I look forward to being of further assistance.
        Attached Files

        Comment


          #5
          All right Jesse,
          Works if the timer Starts in the State.Configure section

          Comment

          Latest Posts

          Collapse

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