Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 12-07-2017, 04:06 AM   #1
Miles_L
Junior Member
 
Join Date: Jun 2017
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Default 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?
Miles_L is offline  
Reply With Quote
Old 12-07-2017, 09:11 AM   #2
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 369
Thanks: 11
Thanked 63 times in 63 posts
Default

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
File Type: zip TestDLL.zip (3.1 KB, 1 views)
Last edited by NinjaTrader_ChrisL; 12-07-2017 at 12:03 PM.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 12-07-2017, 11:38 AM   #3
Miles_L
Junior Member
 
Join Date: Jun 2017
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Default

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(){...}
Miles_L is offline  
Reply With Quote
Old 12-07-2017, 01:07 PM   #4
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 369
Thanks: 11
Thanked 63 times in 63 posts
Default

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 at 01:09 PM.
NinjaTrader_ChrisL is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialise being called twice and OnBarUpdate not being called atall venkatesh Strategy Development 2 03-22-2014 06:53 AM
OnBarUpdate() not called corrado Strategy Development 3 04-28-2013 02:16 PM
OnBarUpdate is not getting called saltminer Strategy Development 10 12-20-2012 08:52 AM
If OnBarUpdate is NEVER called... sledge Platform Technical Support 7 05-23-2012 05:23 AM
OnBarUpdate() - never seems to be called? altrader Platform Technical Support 5 03-10-2008 07:09 AM


All times are GMT -6. The time now is 02:57 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.