PDA

View Full Version : Fire Event to call OnBarUpdate manually


Rollins
10-17-2007, 12:28 AM
Hi, I am trying to implement my own data series, and i guess OnBarUpdate won't be called without firing an event. There's no instrument set, because I want to calculate values for higher time frames. Most certainly it won't work, but i'll give it a try. Thanks

NinjaTrader_Josh
10-17-2007, 01:16 AM
OnBarUpdate is only called when loading some historical data or on incoming real time ticks.

Rollins
10-17-2007, 01:28 AM
The way i interpret your post is that, OnBarUpdate is not called by an event, but is invoked in the code? Is there any way to tell an indicator that there is new data available?

NinjaTrader_Josh
10-17-2007, 01:32 AM
Sorry to mislead you. The method is invoked by the event of incoming data whether the data is historical or real-time data.

If you could please elaborate more on what you mean by "no instrument set" perhaps I can help think about possible workarounds to achieve what exactly you are trying to accomplish.

Rollins
10-17-2007, 01:45 AM
The problem is that i have an indicator which uses several time frames. If i'd use a normal DataSeries the count would be as much as the chosen time frame. That's why i constructed my own DataSeries with a null indicator and the data stored in a list, and update them with a new value when n-bars have been printed. So far the indicators aren't complaining but since there is no data and get/set can't be overriden, it's just hidden, they will sooner or later. I think it simply can't be done with a DataSeries, so i am intending to writing methods instead of using pre-defined indicators and feeding them the data manually. My C# and NT experience is pretty limited, any suggestions would be appreciated. Thanks

NinjaTrader_Josh
10-17-2007, 01:57 AM
Mm. Perhaps you could just use a NinjaScript strategy instead? You could just load up a strategy onto your chart and in your strategy just code it like an indicator instead of a strategy. In a strategy you can sync the DataSeries to whatever time frame you need the data from. Please see this reference sample: http://www.ninjatrader-support.com/vb/showthread.php?t=3572

Alternatively, have you considered writing out the data/calculations to a txt file and then just reading the data and using various time frames in that fashion? You might have issues with read/write operating on the same file object at the same time though so your mileage may vary with this approach. Here are reference samples related to this endeavor:
http://www.ninjatrader-support.com/vb/showthread.php?t=3475
http://www.ninjatrader-support.com/vb/showthread.php?t=3476

Perhaps you could mess around with how Gumphrie did multi-timed framed indicators on this one here:
http://www.ninjatrader-support.com/vb/showpost.php?p=15367&postcount=43

Hope that gives you some ideas.

Rollins
10-17-2007, 02:06 AM
Thank you very much Josh for writing all this. I'll post the results if i can get my indicator to work. Right now the strategy seems to the easiest to accomplish what i have in mind, but can't say for sure.

NinjaTrader_Josh
10-17-2007, 02:07 AM
My pleasure. Good luck.

Rollins
10-17-2007, 09:01 AM
Unfortunately the strategy doesn't allow me to draw anything on the chart(maybe it does, but that is what i think ).

Gumphrie didn't use NT indicators in his multi time frame approach, so he didn't have to deal with the DataSeries problem.

I opted for reimplementing the indicators MIN, MAX, SUM, EMA, SMA, RSI, CCI, MACD and Stochastics so they could work without the DataSeries.

The results have been barely tested but the values matched the ones of the original.

The whole indicator can be found here. (http://www.ninjatrader-support.com/vb/showpost.php?p=17872&postcount=1)

NinjaTrader_Josh
10-18-2007, 12:19 AM
Hi Rollins,

I thought you might find some interest in this property: Update() (http://www.ninjatrader-support.com/HelpGuideV6/Update.html)
I have never used it before, but it seems like it might be fitting for your needs.

Rollins
10-18-2007, 01:29 AM
Great stuff, appreciate it! Too bad that I didn't know this when I coded the indicator. This stuff might come in handy somewhen.

KBJ
10-20-2007, 03:28 PM
Is that a typo in the Update() help description (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Update)?

It currently says,

tripleValue = 0;

private double
protected override void OnBarUpdate()
I'm wondering if it should really say something like this:

private double tripleValue = 0;

protected override void OnBarUpdate()
Thanks.

NinjaTrader_Josh
10-20-2007, 03:39 PM
You are right. Thank you for catching this.

astrolobe
11-25-2007, 07:56 PM
If we code a strategy like an indicator, how do we get it to plot the indicator on the chart?
I tried using the indicator code to create the plot:
Add(new Plot(penMotionLine,PlotStyle.Line, "tradingML")); but it would not compile. I assume it is because the strategy does not inherit any of the indicator methods. If this is so, is there a way to plot the indicator from within the strategy?

NinjaTrader_Josh
11-25-2007, 09:42 PM
You can add indicators to the strategy by doing something like
Add(SMA(5));
http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Add1

astrolobe
11-25-2007, 10:50 PM
I have done that in other circumstances, but that does not work if I need to process two time frames to build the indicator. So I am trying to create an indicator using the strategy class, which allows multi-time frame processing. Now I am at the point using the strategy class where I have processed the two time frames, but I need to plot the values on the chart like an indicator.

NinjaTrader_Josh
11-25-2007, 10:53 PM
Unfortunately it cannot be done that simply because of the distinctions between a strategy and an indicator. What you can try is maybe using Draw() methods to draw out a line bar by bar. This is not an official approach nor is it supported. Just an idea I am throwing out there that you can try.