Announcement

Collapse
No announcement yet.

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 cmoran13, Yesterday, 01:02 PM
        0 responses
        23 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        16 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        94 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        147 views
        2 likes
        Last Post CaptainJack  
        Working...
        X