protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Last) { if (e.Volume >= BlockAlertTradeSize) { if (e.Price == e.Ask) priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AtAsk, BlockAlert = true }); else if (e.Price == e.Bid) priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AtBid, BlockAlert = true }); else if (e.Price > e.Ask) priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AboveAsk, BlockAlert = true }); else if (e.Price > e.Bid && e.Price < e.Ask) priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.Between, BlockAlert = true }); else if (e.Price < e.Bid) priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.BelowBid, BlockAlert = true }); }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Below bid / above ask T&S
Collapse
X
-
Below bid / above ask T&S
I am trying to replicate the T&S window in a superdom column, but I am not getting the results I expect. In the screenshot you can see that the T&S shows above ask trades, but my superdom column doesn't show the same thing. Is that code different somehow?
Code:Tags: None
-
Hello habibalex, thanks for writing in.
The T&S windows is essentially an OnMarketData() method wrapped in a GUI, so the data you are seeing from T&S should match any OnMarketData method of the same instrument.
As far as getting your custom column to match, this would require deeper dive into the custom column script by printing all of the values that OnMarketData is producing and comparing them against the T&S window to see where it diverges.
Please let me know if I can assist any furher.Chris L.NinjaTrader Customer Service
-
Hi habibalex,
I was thinking about building (is still on my backlog list) the logic to identify when transactions occurred above the ask or below the ask and was going to first try the basic logic constructs seen in this inexact but slightly related post ....
https://ninjatrader.com/support/foru...87#post1128387
Code:protected override void OnMarketData(MarketDataEventArgs marketDataUpdate) { if (marketDataUpdate.MarketDataType == MarketDataType.Last) { prevPrice = currentPrice; currentPrice = marketDataUpdate.Price; } Print("prevPrice: " + prevPrice); Print("currentPrice: " + currentPrice); Print(""); if (prevPrice > currentPrice) { Print("Previous price is greater than current price."); } else if (prevPrice < currentPrice) { Print("Previous price is less than current price"); } else if (prevPrice == currentPrice) { Print("Previous price is equal to current price."); } }
Comment
-
In case anyone stumbled upon this, the e.Ask and e.Bid prices will always be at whatever trade price occurred last or (which is good to see what side the trade occurred on for delta). If you want to get the last level 1 bid or ask update, use the if(marketDataType == MarketDataType.Bid) or Ask. These updates occur after the trades have finished.
The NT8 T&S uses this to get trades above / below the bid/ask for highlighting
- Likes 2
Comment
-
Originally posted by habibalex View PostIn case anyone stumbled upon this, the e.Ask and e.Bid prices will always be at whatever trade price occurred last or (which is good to see what side the trade occurred on for delta). If you want to get the last level 1 bid or ask update, use the if(marketDataType == MarketDataType.Bid) or Ask. These updates occur after the trades have finished.
The NT8 T&S uses this to get trades above / below the bid/ask for highlighting
Anyone have any ideas how to do this? Or alternatively, can anyone point me in the right direction?
Code:protected override void OnMarketData(MarketDataEventArgs marketDataUpdate) { //get prices if (marketDataUpdate.MarketDataType == MarketDataType.Bid) {//current bid currentBid = marketDataUpdate.Bid; } else if (marketDataUpdate.MarketDataType == MarketDataType.Ask) {//current ask currentAsk = marketDataUpdate.Bid; } else if (marketDataUpdate.MarketDataType == MarketDataType.Last) {//current price currentPrice = marketDataUpdate.Last; } //compare them and print them if (currentPrice > currentAsk) { Print("Aggressive buy at: " + currentPrice); } else if (currentPrice < currentBid) { Print("Aggressive sell at: " + currentPrice); } }
Comment
-
Hello WalterSkinner,
Thank you for your note.
Are you seeing these results in real time or are you evaluating historical data? OnMarketData() is a real-time data stream, and although it can be called historically with Tick Replay the value will only be the last market data, and not the bid or ask market data. If needed for historical data, you can add an ask or bid series and compare those prices:
There is a Time and Sales SuperDOM column available in the user app share that seems to have a feature that will show if a trade is at, above, or below the ask or bid. You could review the script posted in the app share with your own to see the similarities and differences.
This indicator is publicly available on our NinjaTrader Ecosystem website:
Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:
Note — To import NinjaScripts you will need the original .zip file.
To Import:- Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
- From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
- Select the downloaded .zip file
- NinjaTrader will then confirm if the import has been successful.
Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
Once installed, you may add the indicator to a chart by:- Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK
Here is a short video demonstration of the import process:
Please let me know if I can be of further assistance.
The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
Emily C.NinjaTrader Customer Service
- Likes 1
Comment
-
- Likes 1
Comment
-
Nice indicator but why does it only work in real time and not on Playback - I have never been able to get T&S data to follow what happens in the T&S box ie Prints Below the Bid but my code says at Bid, same for Above Ask. Yet the NT T&S clearly show the trade at being above or below respectively.
It's very confusing as to what to do / how to get prints to match the T&S window.Last edited by Mindset; 05-07-2023, 04:04 AM.
Comment
-
Originally posted by Mindset View PostNice indicator but why does it only work in real time and not on Playback - I have never been able to get T&S data to follow what happens in the T&S box ie Prints Below the Bid but my code says at Bid, same for Above Ask. Yet the NT T&S clearly show the trade at being above or below respectively.
It's very confusing as to what to do / how to get prints to match the T&S window.
Comment
-
Hi Bruce
I can accept it doesn't necessarily get it right in replay - though with tick data it really ought to - but I have tested in real market conditions in real time and it doesn't pick it up.
I am working on what Habibablex wrote about testing for the updated price type?
I mean it seems simple enough in code to ask what is the current lets say ask and if the trade is above that fire off an event. V v for the bid.
Comment
-
Save off the inside Bid / inside ask by testing for if e.MarketDataType == MarketDataType.Bid / Ask and save those off as variables (insideBid / insideAsk).
Then in (e.MarketDataType == MarketDataType.Last) if it's e.Price <= e.Bid && < insideBid it'll be "outside". Use e.Price >= e.Ask && insideAsk for the other side.
That should work in replay also.
- Likes 1
Comment
-
Hi
thanks for this. I can save the insideBid/Ask but
not getting the above ask / below bid condition right.
My code( just using the above ask condition) is
protected override void OnMarketData(MarketDataEventArgs e)
{
if ( e.MarketDataType == MarketDataType.Bid)
insideBid = (double)e.Bid;
if ( e.MarketDataType == MarketDataType.Ask)
insideAsk = (double)e.Ask;
double currentPrice = (double)e.Last;
if(e.MarketDataType == MarketDataType.Last)
{
if(e.Price> insideAsk)
Draw.TextFixed(this,"ggg",DateTime.Now.ToString("H H:mm:ss")+"Above Ask",TextPosition.Center);
}
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cyberpete76, 03-27-2023, 12:29 AM
|
7 responses
267 views
1 like
|
Last Post
by slightly
Today, 01:47 AM
|
||
Started by renewsaltwater, Today, 01:15 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 01:15 AM | ||
Started by slightly, Today, 12:49 AM
|
0 responses
4 views
0 likes
|
Last Post
by slightly
Today, 12:49 AM
|
||
Started by sdauteuil, 09-23-2021, 10:16 AM
|
4 responses
1,210 views
0 likes
|
Last Post Yesterday, 11:41 PM | ||
Started by agclub, 04-21-2024, 08:57 PM
|
5 responses
39 views
0 likes
|
Last Post
by agclub
Yesterday, 09:47 PM
|
Comment