Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleCustomEvents and timer

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

    #16
    Andreas after an MSDN search I realize you threw me an undocumented NT bone. Danke! MaxProcessedEvents is native to NT.

    How much have you played with it? My Visual Studio is on another machine so I can't hack at it, but if I knew it is going to stop processing if, say, (I'm making this up) ProcessedEvents[0] >=100, I can add my own error checks and handling.

    Edit: I've got this in OnBarUpdate():

    PHP Code:
    if (Historical) return;
    if (
    BarsPeriod.Value != || BarsPeriod.Id != PeriodType.Second) return; 
    So Historical data is out, but I am looking at things every second.
    Last edited by MXASJ; 05-25-2010, 08:31 AM.

    Comment


      #17
      Please note we are still investigating this and will get back to you at a later point in time. Thank you for your patience.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by MXASJ View Post
        Thanks Andreas,

        Good thought. But where I am now is... I know the exception gets thrown and I can reproduce it , but how can I handle it? try/catch doesn't seem to do it.

        The strat logic effectively halts but the strat remains green and enabled in the Strategies tab, which I don't want.
        Try to incorporate some logic to ensure that many TriggerCustomEvent on the same bar will not happen.
        You have this exception on or around 4:15 EST because market halts at that time but your timer keeps "ticking" while market is not moving - CurrentBar is the same.

        Also you can try to increase your MaxProcessedEvents to bigger number - say 10000

        Comment


          #19
          Development has confirmed roonius' analysis of the situation.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Thanks everyone for the input.

            I get that error only if the timer is active. It is enabled by a bool in the strategy. I'll be playing around some more and intend to try/test the following:
            1. On that exception, does all OnBarUpdate logic stop or only the CustomEvent logic. Again #1 issue is how to be alterted and handle the exception when/if it occurs.
            2. Would System.Timers work, and can it work in another thread or do I have to marshall stuff. I'm sure there is a reason the timer in System.Windows.Forms is used in the example... but I need to try an alternative.
            3. Drop the timer altogether and use a conditional statement based on DateTime.Now using the seconds/milliseconds properties and some kind of flag.

            I'm not too keen on increasing the 100 event threshold as that may lead to unexpected behavior.

            When I find a solution, I'll post back!

            Comment


              #21
              the problem lies with TriggerCustomEvents. if one bypass the same and code it directly then the problem does not arise. for example i have built a external form which have a form_Resize event.

              Code:
              frm.Resize += new System.EventHandler(frm_Resize);
              now the below code fails (after sometime) with the error msg:- More than 100 subsequent user events

              Code:
              [COLOR=Red]private void frm_Resize(object sender,EventArgs e)
                      {
                            TriggerCustomEvent(new CustomEvent(frmResize),0,e);
                      }
                      private void frmResize(object state)
                      {
                         //resize the datagridview
                          dgv.Width = frm.Width;
                          dgv.Height = frm.Height - 76;
                      }[/COLOR]
              however as i said if the TriggerCustomEvent is ignored and the method is passed directly then it works ok.

              Code:
              [COLOR=SeaGreen]private void frm_Resize(object sender,EventArgs e)
                      {
                         //resize the datagridview
                          dgv.Width = frm.Width;
                          dgv.Height = frm.Height - 76;
                      }[/COLOR]

              again the form_Load event fails to trigger in the TriggerCustomEvents. no issues however when called directly.

              apologies for not providing with the cs file.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by marco231, Yesterday, 11:32 PM
              1 response
              4 views
              0 likes
              Last Post marco231  
              Started by sofortune, Yesterday, 10:55 PM
              0 responses
              3 views
              0 likes
              Last Post sofortune  
              Started by sofortune, Yesterday, 10:19 PM
              0 responses
              9 views
              0 likes
              Last Post sofortune  
              Started by sofortune, Yesterday, 10:10 PM
              0 responses
              7 views
              0 likes
              Last Post sofortune  
              Started by sofortune, Yesterday, 09:49 PM
              0 responses
              4 views
              0 likes
              Last Post sofortune  
              Working...
              X