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

TriggerCustomEvent

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

    TriggerCustomEvent

    Hi,

    for a program, implemented as indicator, I read data from a file during live session and store it in an internal data structure. This data structure is also accessed by the incoming tick data (OnBarUpdate). To avoid conflicts, I implemented NT's TriggerCustomEvent() to handle file reading. Works fine so far, but it has changed the error handling behaviour (try-catch). Therefore my question, how does TriggerCustomEvent() execute the code handed over to it?

    a) Schedules the code execution and gives back program control immediately to the user code.
    b) Schedules the code execution and block the user code until the code is executed.

    I would suspect a), because that would explain the current error handling behaviour.

    Regards
    Ralph

    #2
    No (b). The call blocks.

    Comment


      #3
      Ok.

      - TriggerCustomEvent() schedules the user code.
      - NT executes the user code eventually.
      - User code throws an exception.
      - The exception is caught by NT and reported to the control center's log tab and actually the catch-wrapper around TriggerCustomEvent() in the user code is never triggered.

      Is that correct?

      Regards
      Ralph

      Comment


        #4
        Not sure I follow. If you try/catch your coding bugs then NT would never catch any exception.

        I suggest starting with a simple as possible scenario to understand how the TriggerCustomEvent works.

        Comment


          #5
          Understand what you mean. Here is the correct explanation: The user code, we are talking about parses a text file. Syntax errors in the text file are "reported" by the user code by throwing an exception. But the exception is not caught by the code below, but is reported by NT in the log-tab.

          Here is the related code
          Code:
          [SIZE=2][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/FONT][SIZE=2][SIZE=2][FONT=Courier New] EventHandlerLoadMPs(Object sender, EventArgs eventArgs)[/FONT]
          [FONT=Courier New]{[/FONT]
          [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][FONT=Courier New] (LoadConfig.ShowDialog() == DialogResult.OK)[/FONT]
          [FONT=Courier New] {[/FONT]
          [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]  try[/FONT]
          [/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][FONT=Courier New]  {[/FONT]
          [/SIZE][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]   using[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (StreamReader loadStream = [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/FONT][SIZE=2][SIZE=2][FONT=Courier New] StreamReader (LoadConfig.OpenFile()))[/FONT]
          [FONT=Courier New]   {[/FONT]
          [FONT=Courier New]    profileInst.TriggerCustomEvent(LoadMPs, loadStream);[/FONT]
          [/SIZE][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]     // Load(loadStream);
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][FONT=Courier New]    }[/FONT]
          [FONT=Courier New]  }[/FONT]
          [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][FONT=Courier New] (Exception ex)[/FONT]
          [FONT=Courier New]  {[/FONT]
          [FONT=Courier New]   MessageBox.Show(ex.Message, [/FONT][/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Configuration read error"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
          [FONT=Courier New]  }[/FONT]
          [FONT=Courier New] }[/FONT]
          [FONT=Courier New]}[/FONT]
          [/SIZE][/FONT][/SIZE][/FONT]

          Comment


            #6
            Ralph,

            The error would have occurred somewhere in your custom event no? Could you not catch it in there?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Yes Josh, I think your proposal is a clean solution. I'll pull the try-catch and the using-section into my custom code. That way it is executed alltogether, whenever NT fires the scheduled user code.

              Regards
              Ralph

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by quicksandatl, Today, 11:11 AM
              2 responses
              6 views
              0 likes
              Last Post quicksandatl  
              Started by GwFutures1988, 10-15-2023, 12:13 AM
              12 responses
              517 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by DawnTreader, Yesterday, 05:58 PM
              3 responses
              15 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by OllieFeraher, Today, 11:14 AM
              3 responses
              5 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by aman jain, 10-01-2020, 09:25 PM
              3 responses
              293 views
              0 likes
              Last Post Legiboka  
              Working...
              X