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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Today, 06:40 PM
        0 responses
        2 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        167 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Working...
        X