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

Indicators run prematurely

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

    Indicators run prematurely

    Indicators start running just by bringing up the indicators dialog. Here's a test case: Using the indicator code below, open the output window, start a new chart, right click and select 'indicators...', once the indicators window appears, start watching the output window. Close the indicators window and bring it up again, watch the output window again. It seems the Initialize() method of indicators/strategies are being called every time the indicators window is opened.


    #region Variables
    System.Windows.Forms.Timer xtimer; //### System Timer
    int counter=0;
    #endregion

    protected override void Initialize()
    {
    //### Setup Timer
    if ( xtimer == null ) {
    xtimer = new System.Windows.Forms.Timer();
    xtimer.Interval = 1000; //### Default 1 sec interval
    xtimer.Tick += new EventHandler(timer_wakeup);
    xtimer.Enabled = true;
    }

    }

    protected override void OnBarUpdate()
    {
    }

    private void timer_wakeup(object sender, EventArgs e) {
    Print("Timer wakeup " +(counter++));
    }

    public override void Dispose()
    {
    //### Remove timer
    xtimer.Interval = 1000000;
    xtimer.Stop();
    xtimer.Enabled = false;
    xtimer.Dispose();
    xtimer = null;;

    base.Dispose();
    Print("Disposed on exit");
    }
    Last edited by monpere; 06-04-2008, 05:54 AM.

    #2
    >> Indicators start running just by bringing up the indicators dialog.
    Incorrect. Only Initialize() is called. If you have code in Initialize() which should not be executing then best move this code to OnBarUpdate().

    Comment


      #3
      Yes. As I said, seems Initialize() is being called when the indicators dialog is displayed. My question is, why on earth would you run Iinitialize() on every indicator and every strategy when a dialog box is popped up? Is this by design? This is a very weird programming architecture to me. This means if I have 500 indicators with timers in the Inintialize(), just bringing up a dialog window will start all 500 timers? and if in my normal working with NT throughout the day, I bring up the dialog box 10 more times I will have 5000 timers running for indicators that I am not even using ???? Does this seem like a plausible architecture? There has to be a better/proper way to architect the indicator/dialog code !!!! No code should ever be run until I hit the 'Ok' button !!!!

      Originally posted by NinjaTrader_Dierk View Post
      >> Indicators start running just by bringing up the indicators dialog.
      Incorrect. Only Initialize() is called. If you have code in Initialize() which should be executing then best move this code to OnBarUpdate().

      Comment


        #4
        >> why on earth would you run Iinitialize() on every indicator
        That's how indicators are initialized.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X