Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate not getting called

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

    OnBarUpdate not getting called

    Hi
    I am new to Ninjatrader and program trading, I was trying to create a simply indicator to test my concept. So I had created a c# dll using .net framework 4.5, really a normal one, no other third party code inside.
    And I added this dll to ninjatrader editor reference and compiled without issue.

    Here is the code, really simply, create custom object and print the high value :

    Code:
    protected override void OnBarUpdate()
    		{
    //			Add your custom indicator logic here.
    			XTrading.Comp.Bar b = new XTrading.Comp.Bar(
    				Time[0],
    				(decimal)Open[0],
    				(decimal)Close[0],
    				(decimal)High[0],
    				(decimal)Low[0],
    				(int)Volume[0]
    				);
    
                Print(b.High);
    		}
    After I added the indicator to the chart with my historical data, I found that there is nothing output to the output window, even in the debug mode with VS2017 pro, putting a breakpoint at the entry of OnBarUpdate method, still nothing happen.

    Could anyone give me some advise whats goes wrong?

    #2
    Hello,

    Thank you for the post and welcome to the NinjaTrader forum.

    If this dll and your indicator compiled and you can see the indicator in NinjaTrader it might not be the cause of the issue. I have included a very minimal dll with its source code, along with the script I used to test it.
    I placed this DLL inside of Documents\NinjaTrader 8\bin\Custom, then added the dll to the references, then I reset NinjaTrader.

    You will be able to see prints from the output window coming from that dll in my test script.

    Note* This was a manual zip and the Class1.cs file is the source code of the MathLibrary.dll, so it does not need to be inside of your NinjaTrader folder. Manually unzip the folder, place the MathLibrary.dll in Documents\NinjaTrader 8\bin\Custom and place TestDLL.cs in Documents\NinjaTrader 8\bin\Custom\Indicators, then add the MathLibrary.dll reference.

    After ensuring your dll is set up like I described above, can you think of anything else that might be wrong? Can you print a string literal from OnBarUpdate()? (Print("MyString"))

    Are you sure that your custom class is being built properly?


    Are there any errors in your log tab of the Control Center?

    I look forward to your reply.
    Attached Files
    Last edited by NinjaTrader_ChrisL; 12-07-2017, 12:03 PM.

    Comment


      #3
      Hi Chris

      Thanks for your help, its working now. I am not sure if the root cause was I put the dll under NinjaTrader 8\bin instead of bin\Custom.

      BTW, does NinjaTrader platform support c# event?
      Like :
      foo.warning += new DelegateName(methodName);

      private void methodName(){...}

      Comment


        #4
        Hello,

        Thank you for the follow-up.

        An event handler would fall into the realm of general C# development and is definitely possible to do, I will provide some examples but this is out of the scope of support we provide.

        Please see this post that demonstrates the use of C# event handlers and NinjaTrader's TriggerCustomEvent() function:


        https://ninjatrader.com/support/help...ustomevent.htm - TriggerCustomEvent()

        TriggerCustomEvent() is only used to ensure you access the most up to date price data from an event method that does not sync all data series.

        I also made a post about making a static event handler using the MySharedMethods example.

        https://ninjatrader.com/support/foru...d.php?t=105654 - Static event for shared static class

        https://ninjatrader.com/support/foru...04&postcount=2 - Original MySharedMethods code

        Please let me know if you have any questions about the material.
        Last edited by NinjaTrader_ChrisL; 12-07-2017, 01:09 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        637 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X