NexusFi: Find Your Edge


Home Menu

 





Problem with OnMarketData()


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ratfink with 11 posts (7 thanks)
    2. looks_two ketron82 with 9 posts (2 thanks)
    3. looks_3 artemiso with 5 posts (8 thanks)
    4. looks_4 Big Mike with 4 posts (3 thanks)
      Best Posters
    1. looks_one artemiso with 1.6 thanks per post
    2. looks_two Big Mike with 0.8 thanks per post
    3. looks_3 NJAMC with 0.7 thanks per post
    4. looks_4 ratfink with 0.6 thanks per post
    1. trending_up 9,499 views
    2. thumb_up 24 thanks given
    3. group 4 followers
    1. forum 35 posts
    2. attach_file 0 attachments




 
Search this Thread

Problem with OnMarketData()

  #1 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4

My ideas is simply cumulate ask volume and bid vol.
I simply have to compare last price with ask or bid price...and so:
if Last Price==Ask Price --> Volume of last price is ASK
if Last Price==Bid Price --> Volume of last price is BID

and I made this code to begin work but have some problem yet.I made other tests but I cannot solve this problem....with this simple function, in the Output Windows I sometime read that "last price" is not equal at askprice or bid price....and this is strange.

DropZone

Any ideas?


 
Code
protected override void OnMarketData(MarketDataEventArgs e)
			{	
    // Print some data to the Output window
    if (e.MarketDataType == MarketDataType.Last) 
         { 
			Print("### Last = " + e.Price + " " + e.Volume +  " Bid Price= " + GetCurrentBid() + "  Ask Price= " + GetCurrentAsk());
			
		
		 }	

			
			
	     
//	else if (e.MarketDataType == MarketDataType.Ask)
//		{
//        Print("Ask = " + e.Price + " " + e.Volume);
//	  
//		}	
//	else if (e.MarketDataType == MarketDataType.Bid)
//		{
//	    Print("Bid = " + e.Price + " " + e.Volume);
//	    
//	    }
	

	
			}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
ZombieSqueeze
Platforms and Indicators
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Deepmoney LLM
Elite Quantitative GenAI/LLM
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425



ketron82 View Post
My ideas is simply cumulate ask volume and bid vol.
I simply have to compare last price with ask or bid price...and so:
if Last Price==Ask Price --> Volume of last price is ASK
if Last Price==Bid Price --> Volume of last price is BID

and I made this code to begin work but have some problem yet.I made other tests but I cannot solve this problem....with this simple function, in the Output Windows I sometime read that "last price" is not equal at askprice or bid price....and this is strange.

DropZone

Any ideas?

You can have many Ask/Bid changes in between getting a Last (actual trade) price so you need to store latest Bid and Ask values in local variables, plus as you say the trade price can be above or below (or in-between (i.e. unclassifiable or neutral)) so your tests should be 'price >= askPrice' or 'price <= bidPrice', and not just ==.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4

Ok...I am comparing MarketDelta Time and Sales with output windows of mi indicator in ninja and same datafeed IQfeed.
I will post now a screenshot of the results

Reply With Quote
  #5 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4

DropZone

This is the screenshot where I compare MarketDelta (iqfeed) and Ninja (iqfeed).
I think that there is some problem using getcurrentask() or getcurrentbid() in onmarketdata() function....I make a conceptual error but I haven't found a correct logical working of onmarketdata()

How is a best way to use onmarketdata() ?

I made other test without getcurrentask and getcurrentbid but using

else if (e.MarketDataType == MarketDataType.Ask)

but something go wrong however.

Any ideas?

Reply With Quote
  #6 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4


ratfink View Post
You can have many Ask/Bid changes in between getting a Last (actual trade) price so you need to store latest Bid and Ask values in local variables, plus as you say the trade price can be above or below (or in-between (i.e. unclassifiable or neutral)) so your tests should be 'price >= askPrice' or 'price <= bidPrice', and not just ==.

Ok many many thanks...I saw what you told me....like in this screenshot DropZone

but How can I capture the ASK and BID (price) corresponding to the lastprice?

Tnx again

Reply With Quote
Thanked by:
  #7 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


ketron82 View Post
DropZone

This is the screenshot where I compare MarketDelta (iqfeed) and Ninja (iqfeed).
I think that there is some problem using getcurrentask() or getcurrentbid() in onmarketdata() function....I make a conceptual error but I haven't found a correct logical working of onmarketdata()

How is a best way to use onmarketdata() ?

I made other test without getcurrentask and getcurrentbid but using

else if (e.MarketDataType == MarketDataType.Ask)

but something go wrong however.

Any ideas?

What I do:

 
Code
static private double askPrice = 0;
static private double bidPrice = 0;
static private double upVol = 0;
static private double downVol = 0;
static private double neutralVol = 0;

protected override void OnMarketData(MarketDataEventArgs e)
{
    if (e.MarketDataType == MarketDataType.Ask)
    {
        askPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType == MarketDataType.Bid)
    {
        bidPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0)
        return;

    if (e.Price >= askPrice) 
    {
	upVol += e.Volume;
    }
    else  if (e.Price <= bidPrice)
    {
        downVol += e.Volume;
    }
    else
    {
        neutralVol += e.Volume;
    }
}

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4

OK....I will test now...good idea....I'm trying to understand the logic....many thanks for now.
I will post the results and screenshot for other interested users.


ratfink View Post
What I do:

 
Code
static private double askPrice = 0;
static private double bidPrice = 0;
static private double upVol = 0;
static private double downVol = 0;
static private double neutralVol = 0;

protected override void OnMarketData(MarketDataEventArgs e)
{
    if (e.MarketDataType == MarketDataType.Ask)
    {
        askPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType == MarketDataType.Bid)
    {
        bidPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0)
        return;

    if (e.Price >= askPrice) 
    {
	upVol += e.Volume;
    }
    else  if (e.Price <= bidPrice)
    {
        downVol += e.Volume;
    }
    else
    {
        neutralVol += e.Volume;
    }
}


Reply With Quote
  #9 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4

DropZone

Many many thanks.....your code seems to work well but I'm still trying to understand the different logical condition in onmarketdata() function.
You used "return;" in ask and bid call.....and so...good idea.
I will tell more

Many many thanks for now


ratfink View Post
What I do:

 
Code
static private double askPrice = 0;
static private double bidPrice = 0;
static private double upVol = 0;
static private double downVol = 0;
static private double neutralVol = 0;

protected override void OnMarketData(MarketDataEventArgs e)
{
    if (e.MarketDataType == MarketDataType.Ask)
    {
        askPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType == MarketDataType.Bid)
    {
        bidPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0)
        return;

    if (e.Price >= askPrice) 
    {
	upVol += e.Volume;
    }
    else  if (e.Price <= bidPrice)
    {
        downVol += e.Volume;
    }
    else
    {
        neutralVol += e.Volume;
    }
}


Reply With Quote
Thanked by:
  #10 (permalink)
ketron82
Rome Italy
 
Posts: 27 since Feb 2012
Thanks Given: 7
Thanks Received: 4


Many thanks also to ratfink user that have tanked me

Now I would proceed step by step.

I would now create a "Class" for store ask and bid that have the same last price although not ranked.

Have you an idea yet?

I am testing some example....I will post in the next minutes.

Reply With Quote




Last Updated on March 28, 2015


© 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