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

Can't stop timer

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

    Can't stop timer

    Hello,

    I have a timer in my NT8 strategy that was working perfectly in NT7 but not in NT8. When terminatig the strategy the code is not stopped. Even if I restart NT8

    --------------using declarations--------------------
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Diagnostics;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Forms;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    -------------end---------------------

    ------------- timer set-----------
    else if (State == State.Configure)
    {
    myTimer.Tick += new EventHandler(TimerEventProcessor);
    myTimer.Interval = TimerInterval;
    myTimer.Start();
    TimerStarted = true;
    }
    ----------end--------------------

    --------event processor------
    private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
    {
    // Code goes here
    }
    --------end--------------
    ------stop timer----------
    else if (State == State.Terminated)
    {
    myTimer.Dispose();

    }
    -------------end--------------

    #2
    Solved.

    An advice, Instead of starting the timer in State.Configure, move it to another place. In Configure the code is executed at start even without executing the strategy. I do not understand why.

    In your help guide you should change your sample code.

    Comment


      #3
      Hello guillembm,

      Thank you for your post.

      The TriggerCustomEvent() example in the Help Guide (https://ninjatrader.com/support/help...ustomevent.htm) is intended to demonstrate the timer start when the user selects 'Apply' or 'OK' as you can see from the use of the State Configure. You would need to configure your strategy or any NinjaScript object accordingly to it's application and when you want the object to start functions such as an internal timer.

      A working knowledge of the States themselves would be recommended in this case. Please visit the following links on States and NinjaScript Lifecycle for further insight into this matter:

      Please let me know if you have any questions.

      Comment


        #4
        Hi guillembrm,
        Look at this thread to avoid future problems with timers (tip: boolean variable is important).

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, 04-18-2024, 08:38 AM
        9 responses
        40 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by techgetgame, Yesterday, 11:42 PM
        0 responses
        9 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,615 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Yesterday, 05:56 PM
        0 responses
        10 views
        0 likes
        Last Post jaybedreamin  
        Working...
        X