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,519 views
    2. thumb_up 14 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Programming Indicators Using OnMarketData in NT7!!!

  #1 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787

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?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 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
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787


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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts