![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2010
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Hello all,
I'd like to develop an execution algorithm that takes into account recent trades and whether they occurred at the bid or at the ask. I'm wondering if I can record the most recent Bid and Ask during the OnMarketData() method (using GetCurrentBid() and GetCurrentAsk()) and whenever the OnBarUpdate() method runs (with CalculateOnBarClose==false), compare the most recent Close[0] with the most recent Bid & Ask and look for a match. My question is if OnBarUpdate() is called at the start of every bar, even if there was no trade, and, if so, which method should I use to find the price at which the last trade occurred? All the best, Ken |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hello Kaydgee,
There won't be a bar without having a trade. OnBarUpdate() is called for every trade. You may want to work with last price value of OnMarketData() though, to align the values you're seeking to compare. You're then capturing the values all within the same event. http://www.ninjatrader-support.com/H...arketData.html
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Jun 2010
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
As for capturing all data in OnMarketData(), would something like the below section of code work? Code:
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Last)
{
double lastPrice = e.Price;
if (lastPrice == currentBid) Print("Last trade at bid");
else if (lastPrice == currentAsk) Print("Last trade at ask");
else Print("Last trade at neither bid nor ask");
}
else if (e.MarketDataType == MarketDataType.Ask) double currentAsk = e.Price;
else if (e.MarketDataType == MarketDataType.Bid) double currentBid = e.Price;
}
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Yes, that looks like a good approach, although would probably need to declare your variables so they're available outside of their else if blocks.
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tick Filter + Bid/Ask | cgeorgan | Automated Trading | 1 | 07-28-2010 08:55 AM |
| Adding Bid / Ask tick data to an indicator | mrlogik | Version 7 Beta General Questions & Bug Reports | 4 | 07-27-2010 01:40 PM |
| MB Trading Connection - No Last But Getting Bid and Ask | jirkoo | Miscellaneous Support | 13 | 03-24-2009 06:47 AM |
| Logging in/logging out | spacebalts67 | Miscellaneous Support | 3 | 03-09-2009 03:17 PM |
| LMT orders ... BUY / SELL @ LAST / ASK / BID in automated trading. | mkundi | Automated Trading | 4 | 04-04-2006 10:12 PM |