Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid
Updated: Views / Replies:1,059 / 6
Created: by chrisflow Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid

  #1 (permalink)
Elite Member
New Orleans, LA
 
Futures Experience: Intermediate
Platform: xtrader ADL, NinjaTrader7
Favorite Futures: Guitar and CL
 
chrisflow's Avatar
 
Posts: 15 since Feb 2010
Thanks: 54 given, 4 received

Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid

Hi,

Trying to modify "BidAskSpread.zip" in order to get the spread between TWO instruments bids & asks (calendar spread). No luck.

Why? I know there are "spread" indicators out there that show spread based on the "last trade" price. But I'm looking for one that indicates the spread based on the current bid-ask between calendar months. i.e., I want the difference between the CL June Bid vs the CL December Bid, as well as the CL June Ask vs the CL Dec Ask. I've found that the bid/asks between these two do vary, but quickly. An indicator would help to use in strategy development to place the trade. Again, I don't want the "last trade" price of the spread because the Dec trade often happens on a delay due to thin market. Run-of-the-mill spread indicators using "last trade" suffer from illusory spreads due to the trades not occurring simultaneously, where last trade is way behind the current bid-asks.

I uploaded a photo of my DOM showing that the later month CL contract last price (in yellow) is behind the current bid-ask. Most spread indicators look at the in the 2nd pic on the right (SpreadCandlesticks) isn't useful when the last price is outside of the current bid-ask - it would have me buy at the last price, a price that is no longer current with the bid-ask.

The code in "BidAskSpread.zip" shows live bid/ask on the chart using OnMarketData(MarketDataEventsArgs e):

protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketData.Ask == null || e.MarketData.Bid == null)
return;
double ask=e.MarketData.Ask.Price;
double bid=e.MarketData.Bid.Price;
}


Question is: How to I access OnMarketData for instrument #1 vs instrument #2?? How to I add the second instrument??

ShowBidAsk.zip
https://futures.io/attachments/57963d1324574599

Thanks all!

PS I realize that a better solution to this is a colocated platform such as CQG spreader. I'm just testing proof of concept here for myself. Latency is probably too large to capitalize on spreads using any other type of remote PC/ modem connection.

Attached Thumbnails
Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid-bidask.jpg   Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid-bidask2.jpg  

Last edited by chrisflow; May 24th, 2013 at 11:39 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Market Wizard
Bangkok
 
Futures Experience: Intermediate
Platform: MultiCharts.NET, S5, Ninj
Broker/Data: AMP, S5, IB
Favorite Futures: ES
 
DionysusToast's Avatar
 
Posts: 2,672 since Nov 2010
Thanks: 777 given, 8,742 received
Forum Reputation: Legendary


Good question - I am note sure it can be don, the event handler presumes the first instrument on the chart and there's no subscribe method to subscribe to more.

How about you have 2 charts, one for each instrument and use global variables to store the bid/asks from both.

Then on one script you can just grab the global variable that the other one set....

If you have any questions about the products or services provided, please send me a Private Message or use the futures.io "Ask Me Anything" thread
Reply With Quote
 
  #4 (permalink)
Elite Member
New Orleans, LA
 
Futures Experience: Intermediate
Platform: xtrader ADL, NinjaTrader7
Favorite Futures: Guitar and CL
 
chrisflow's Avatar
 
Posts: 15 since Feb 2010
Thanks: 54 given, 4 received

global variables

Thanks! Interesting solution.

But how can the indicator that pulls the global variable pull it with each change of the bid-ask? The receiving indicator may only pull every time it has an OnBarUpdate(), thus missing tons of live bid-asks. Am I right to say this?


NT website forum had this to say:

protected override void OnMarketData(MarketDataEventArgs e)
{
if (BarsInProgress == 0)
//Handle primary series bid/ask here.

if (BarsInProgress == 1)
//Handle secondary series bid/ask here.
}

from:
http://www.ninjatrader.com/support/forum/showthread.php?t=42866&highlight=onmarketdata+instruments



BUT I tried that and I'm getting an error that my var "does not exist in current context"

I've added a second instrument, and used "BarsInProgress" to parse out the bid-asks. Can you tell what is wrong? It works if I remove the "if(BarsInProgress ==0)", but that defeats the ability to get the bid-asks of each instrument separately.


protected override void Initialize()
{
Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketData.Ask == null || e.MarketData.Bid == null)
return;

if (BarsInProgress == 0) {
double aAsk=e.MarketData.Ask.Price;
double aBid=e.MarketData.Bid.Price;
}

SpreadHigh.Set( Qty1* aAsk ); // throws error "The name 'aAsk" does not exists in the current context"
SpreadLow.Set( Qty1* aBid ); // throws error "The name 'aBid" does not exists in the current context"


Edit: found solution..
if (BarsInProgress == 0) {
double aAsk = e.MarketData.Ask.Price;
double aBid = e.MarketData.Bid.Price;

SpreadHigh.Set( Qty1* aAsk );
SpreadLow.Set( Qty1* aBid );
}


Last edited by chrisflow; May 25th, 2013 at 01:45 AM.
Reply With Quote
 
  #5 (permalink)
Market Wizard
Bangkok
 
Futures Experience: Intermediate
Platform: MultiCharts.NET, S5, Ninj
Broker/Data: AMP, S5, IB
Favorite Futures: ES
 
DionysusToast's Avatar
 
Posts: 2,672 since Nov 2010
Thanks: 777 given, 8,742 received
Forum Reputation: Legendary

OnMarketData fires every tick, so it would store the bid/ask often enough as long as you set the global var in there.

In terms of getting it, you could grab it on the other indicator in the OnMarketData method or you could have a timer that fires every 20ms to compare the latest of the values.

I've never tried to use OnMarketData with 2 instruments on 1 chart. Like I say - 2 charts, 2 scripts, each with an OnMarketData that posts to global variables both scripts can access.

If you have any questions about the products or services provided, please send me a Private Message or use the futures.io "Ask Me Anything" thread
Reply With Quote
 
  #6 (permalink)
Elite Member
Northern Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: FDAX, CL
 
vvhg's Avatar
 
Posts: 1,583 since Mar 2011
Thanks: 1,016 given, 2,807 received


DionysusToast View Post
Good question - I am note sure it can be don, the event handler presumes the first instrument on the chart and there's no subscribe method to subscribe to more.

How about you have 2 charts, one for each instrument and use global variables to store the bid/asks from both.

Then on one script you can just grab the global variable that the other one set....

@DionysusToast, I guess you are certain that OnMarketData only fires for the primary DataSeries?

If so global vars seems the way to go, but I would write an EventHandler to them that I could subscribe to in the other indicator. That way I get all updates instantly with no overhead checking periodically.

Vvhg

Hic Rhodos, hic salta.
Reply With Quote
 
  #7 (permalink)
Market Wizard
Bangkok
 
Futures Experience: Intermediate
Platform: MultiCharts.NET, S5, Ninj
Broker/Data: AMP, S5, IB
Favorite Futures: ES
 
DionysusToast's Avatar
 
Posts: 2,672 since Nov 2010
Thanks: 777 given, 8,742 received
Forum Reputation: Legendary


vvhg View Post
@DionysusToast, I guess you are certain that OnMarketData only fires for the primary DataSeries?

If so global vars seems the way to go, but I would write an EventHandler to them that I could subscribe to in the other indicator. That way I get all updates instantly with no overhead checking periodically.

Vvhg

I'm not certain - I've just never used it on 2 series.

If you have any questions about the products or services provided, please send me a Private Message or use the futures.io "Ask Me Anything" thread
Reply With Quote

Reply



futures io > > > > > Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
OnMarketData Problem humy65 NinjaTrader Programming 3 October 16th, 2012 11:17 AM
NT Multi Timeframe and multi indicator review eurostoxx NinjaTrader 3 August 29th, 2011 01:07 PM
NASDAQ, ICE Bid for NYSE; Trump Deutsche Bourse Bid Quick Summary News and Current Events 0 April 1st, 2011 09:10 AM
BUG for OnMarketData timmyb NinjaTrader Programming 12 February 5th, 2011 10:32 PM
Quickie: How to access multi-plot indicator's values SEPARATELY?? chrisflow NinjaTrader Programming 10 June 2nd, 2010 02:32 PM


All times are GMT -4. The time now is 07:50 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-15 in 0.11 seconds with 20 queries on phoenix via your IP 54.163.61.66