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

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 myObjectEventArgs myEventArgs){
        if (
    CurrentBar 0){
            
    TriggerCustomEvent(alertTimerEjectClose[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.

    JesseNinjaTrader Customer Service

    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
        JesseNinjaTrader Customer Service

        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 algospoke, 04-17-2024, 06:40 PM
          6 responses
          49 views
          0 likes
          Last Post algospoke  
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          61 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          10 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          21 views
          0 likes
          Last Post traderqz  
          Working...
          X