NexusFi: Find Your Edge


Home Menu

 





Programming Indicators Using OnMarketData in NT7!!!


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one RJay with 3 posts (13 thanks)
    2. looks_two Big Mike with 1 posts (0 thanks)
    3. looks_3 Trader.Jon with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,917 views
    2. thumb_up 14 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789

Hi All,

If you have been following along, you know that ...

In NT 6.5, OnBarUpdate and OnMarketData along with FirstTickOfBar and CurrentBar all get along nicely!!

In NT7, all that has changed.

OnBarUpdate and OnMarketData are no longer synchronized!!!

FirstTickOfBar and CurrentBar do not do the job they once did in 6.5.

In NT7, FirstTickOfBar and CurrentBar should be renamed to SecondTickOfBar and CurrentBarMostOfTheTime!!!

When I asked NT to allow access to FirstTickOfBar and CurrentBar directly from OnMarketData in NT7 instead of gleaning updates from OnBarUpdate, They said no.

This is a huge problem for any indicators using data from OnMarketData. Data from the first tick of every bar is slipping through the crack and is not being processed by the indicator.

I asked NT if there was any way to access bar data directly from OnMarketData??

They responded that it wasn't their job to write my programs for me!!!

My attempts to create code to access bar data from the indicator failed.

I then posted a "hold current tick till next tick" code to process the first tick of each bar when the second tick arrived as a possible solution.

This solution was overly complicated, and was not completely accurate 100 percent of the time.


Now Fast forward to the weekend of 12/12/2010.

A programmer with a similar problem posted code at the NT forum requesting help.

In his code, he was directly accessing bar data from inside the indicator program.

I dropped everything I was working on to look into this!!!

Yea, it turns out that NT had existing code to access bar data and had chosen not to share this with me!!!!

After several hours of testing I made a breakthrough. I am now able to query the current bar status, of the chart, from inside OnMarketData, prior to processing incoming data from the data feed for every tick.


It looks like this:


protected override void OnMarketData(MarketDataEventArgs e)

{


if(Bars.Count != activeBar)


{


TotalVolLast = 0;

activeBar = Bars.Count;

}


if ((e.MarketDataType == MarketDataType.Last)) TotalVolLast+= e.Volume;


Values[0].Set(TotalVolLast);


double volume = Volume[0];


}



Pretty simple!!!! Huh!!! So easy a caveman can do it!!!!


Next, I found that bad plot data was outputting from OnBarUpdate and was overriding the correct plot output from OnMarketData.

What's causing this??? Your guess is as good as mine!!!!

This sort of sucked, so I removed that code from OnBarUpdate.

Since there is no historic data to load and CurrentBar and FirstTickOfBar are of no use, and having problems plotting from OnBarUpdate, UnBarUpdate now looks like this in all my volume indicators.


protected override void OnBarUpdate()

{


}



Yea, so much for OnBarUpdate!!!

Now all my volume indicators totals matched the VOL indicator on that chart!!!


I opened a second identical chart, with just a few of my indicators.

Indicators on the second chart did not match the same indicators on the first chart. Missing data again!!!!

These "missing data results" were the same when plotting from either OnMarketData or OnBarUpdate.

Eventually found that this specific problem was related to how and when the chart updates.

By default, a chart with no indicators updates every time there is a price change.

If any indicator on the chart references Volume[0] in its calculations, NT now updates that chart when ever there is a change in Volume[0] as well as a change in price.

So if you are using just OnMarketData as your volume source, NT restricts that chart to price changes only.

If you scroll back up to the OnMarketData capture, you will see the following code.


double volume = Volume[0];


I have added this line of code to every one of my volume indicators so that they update more frequently and display all data correctly.



Finally, I posted NT7 versions of my released volume indicators yesterday in the elite download area.

They have all the updates talked about here.


Enjoy,


RJay


P.S. Special thanks to HNWtrader for posting the breakthrough code at the NT forum and to eDanny for helping test the new code against all NT chart types!!!


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
South Korea Suspends Bithumb for Six Months Over AML Fai …
Cryptocurrency
Zytrade: Devin Brady, CEO - Ask Me Anything (AMA)
Brokers
Tradeify 3.0 Overhauls Futures Prop Firm Model -- One-Ti …
Funded Trading Evaluation Firms
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
Post-Summit Scorecard: $36M in May 15 Bets Settle Near-Z …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #3 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


Greetings, and thanks for bringing this forward!

Just to clarify, (ie ForEx) if I am not using volume in my strategies, this is NOT something I need to adapt within my code?

Thanks,
Jon


Reply With Quote
Thanked by:
  #4 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789


Trader.Jon View Post
Greetings, and thanks for bringing this forward!

Just to clarify, (ie ForEx) if I am not using volume in my strategies, this is NOT something I need to adapt within my code?

Thanks,
Jon

This does not effect price based code.


Started this thread Reply With Quote
Thanked by:




Last Updated on December 16, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts