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

Windows Notification, DLL dynamic loading

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

    Windows Notification, DLL dynamic loading

    Edit: Windows notification service implemenation is in post #3

    Hi,
    since I'd like raise a windows notification, I'd need to load some additional DLLs but don't want to copy them to the NT folder.
    While not a NT question per se, maybe somebody has experience.

    Basically I'd only need Windows.UI and Windows.Data.Xml.Dom.

    I've experimented with System.Reflection.Assembly but neither Load, LoadFile nor LoadFrom succeeded. Maybe because I'm not loading the correct Windows.UI.dll, I've tried Windows\SysWOW64 and Windows\assembly. Could also be that NT uses a different .NET version.

    Assembly Examples:
    https://stackoverflow.com/questions/...ime-in-c-sharp

    If this is not possible, I've already got a working solution based on a share service writing a message to a file and a powershell raising the notification.
    I'll post whatever solution works best.

    Windows notification code example:
    https://docs.microsoft.com/en-us/pre...2768(v%3Dvs.85)
    Last edited by MojoJojo; 02-29-2020, 08:54 AM.

    #2
    Hello MojoJojo,

    Thanks for your post.

    Dynamically loading DLL's would be outside of the scope of support we can offer.

    I would suggest adding the DLL in the bin/Custom folder, adding a reference, and making sure that works before attempting to load the DLL dynamically. NinjaTrader 8 is built for .NET 4.5 so I would recommend using .NET 4.5 compatible DLLs.

    I'll leave this thread open for any community members that would like to share their input.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      thanks for your suggestion, unfortunately I found out that the DLLs for raising notifications are native and not assemblies.
      While I am sure there is some way of calling the libraries dynamically, e.g. PowerShell can do it by reading the definitions from winmd files, there isn't much documentation on the web for doing this at runtime. I don't think P/Invoke is sufficient.

      However calling an embedded powershell script works fine, it's not very efficient nor beautiful but does the job, the code is attached.

      Windows notification service setup

      To trigger notifications, the imported share service needs to be configured.
      https://ninjatrader.com/support/help...ng_content.htm
      The application name parameter needs to be correctly set, otherwise the notifications are ignored, Windows PowerShell or NinjaTrader 8 should be fine, if unsure you can pick a reasonable value from the output of a powershell script run in a command line.

      Code:
      powershell -command Get-StartApps
      With live data, the a notification can be raised with

      Code:
      Share("WindowsNotification", String.Format("Indicator alert {0} {1}", new object[]{Instrument.FullName, Bars.GetClose(CurrentBar)}));
      Of course use at your own risk, I'm not liable for anything resulting from the use of the code, not even your profits .

      Version: 1.0.0.3 escapes XML special characters in the script for security reasons, otherwise no change

      Edit: the most efficient method would likely be to write a intermediary dll handling the notification call and invoke it with DLLImport or reflection in NT, depending on if the dll is written in C# or C++
      Attached Files
      Last edited by MojoJojo; 03-02-2020, 02:00 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Today, 10:35 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      40 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X