• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    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/foru...45&postcount=3

        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 E-Viper87, Today, 02:50 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by diddyp1990, Today, 01:28 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Paul  
        Started by dariuszszyc, Today, 09:08 AM
        8 responses
        32 views
        0 likes
        Last Post Nicolas
        by Nicolas
         
        Started by pman777, Today, 12:08 PM
        2 responses
        6 views
        0 likes
        Last Post pman777
        by pman777
         
        Started by Sadat, Today, 09:09 AM
        5 responses
        22 views
        0 likes
        Last Post NinjaTrader_JoshG  
        Working...
        X