Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Help multi-instruments to access OnMarketData(MarketDataEventArgs e) for live Ask/Bid
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):
I realise this may be a very naive question and also potentially quite broad.
What do you look for to determine the current type of market environment (choppy / trending / mean reversion)?
I guess it could be PA, different indicators and …
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.
Can you help answer these questions from other members on NexusFi?
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
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.
}
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.
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;
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
@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.