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!
See more
See less

Partner 728x90

Collapse

Bid/Ask update

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bid/Ask update

    Hello, I am using Bid / Ask indicator, I downloaded from somewhere:

    Code:
    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Globalization;
    #endregion
    // Written by Ben L.  [email protected]
    // Feel free to ask for enhancements!
    // May God bless you and your business.
    // small mods by Mindset Dec 2010// configurable colors,thickness,length and code adjustments
    
    
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Puts horizontal lines at the bid & ask prices
        /// </summary>
        [Description("Puts a horizontal line at the bid & ask price")]
        public class ShowBidAsk : Indicator
        {
            #region Variables
    		private bool displayText=true;
    	
    		private Color 		 AskColor 	  = Color.Blue;
    		private Color 		 BidColor 	  = Color.Red;
    		private int 		 endbarsago   = -12;//6.5 drawlines can't plot into future
    		private int 		 startbarsago = -3;
    		private int 		 Thickness	  = 1;
    
            #endregion
    
      
            protected override void Initialize()
            {
                  Overlay = true;
            }
    
    
            protected override void OnBarUpdate()
            { }
    
    
            protected override void OnMarketData(MarketDataEventArgs e)
            {
    
    			double a=e.MarketData.Ask.Price;
    			double b=e.MarketData.Bid.Price;
    			double TValue = Instrument.MasterInstrument.PointValue * TickSize;
    			double SpreadCost = (a-b)/TickSize * TValue;
    			/*removed currency symbol - some users don't trade $ denom instruments so it could be misleading.
    			You can convert whatever symbols currency into your own trading currency but it's way too complicated
    			for this small piece of code.
    			*/
    			string v = "Bid/Ask Spread:\n"+SpreadCost.ToString("0.00");
    			
    			
    			if(displayText)
    				DrawTextFixed("text",v,TextPosition.TopLeft);//You can move this to any position you wish.
    
    			
    			{
    				
    			if ( e.MarketDataType == MarketDataType.Ask)
    			{
    				base.DrawLine("ask",false,startbarsago,e.Price,endbarsago,e.Price,AskColor,DashStyle.Solid,Thickness);
    		
    			}
    			else if (e.MarketDataType == MarketDataType.Bid)
    			{
    				base.DrawLine("bid",false,startbarsago,e.Price,endbarsago,e.Price,BidColor,DashStyle.Solid,Thickness);
    			}
    			}
    			
            }
    				#region Blank out Label
    		public override string ToString()
    		{
    			return "BidAsk";//To make blank change to "";
    		}	
    	#endregion
    
            #region Properties
            [Description("Display Text")]
            [GridCategory("Parameters")]
    		[Gui.Design.DisplayName ("a.Display Text")]
            public bool DisplayText
            {
                get { return displayText; }
                set { displayText = value; }
            }
    
    		[XmlIgnore()]
    		[Description("Bid Color")]
         	[Gui.Design.DisplayName ("e.Bid Color")]
    	    [GridCategory("Parameters")]
            public Color bidColor
            {
                get { return BidColor; }
                set { BidColor = value; }
            }
    		
    		[Browsable(false)]
    		public string bidColorSerialize
    		{
    			get { return Gui.Design.SerializableColor.ToString(BidColor); }
    			set {BidColor = Gui.Design.SerializableColor.FromString(value); }
    		}	
    		
    		
    		[XmlIgnore()]
    		[Description("Ask Color")]
         	[Gui.Design.DisplayName ("f.Ask Color")]
    	    [GridCategory("Parameters")]
            public Color askColor
            {
                get { return AskColor; }
                set { AskColor = value; }
            }
    		
    		[Browsable(false)]
    		public string askColorSerialize
    		{
    			get { return Gui.Design.SerializableColor.ToString(AskColor); }
    			set {AskColor = Gui.Design.SerializableColor.FromString(value); }
    		}	
    		
        	[Description("Negative nos extends line further into the future.")]
            [GridCategory("Parameters")]
    		[Gui.Design.DisplayName ("c EndBarNo")]
            public int Endbarsago
            {
                get { return endbarsago; }
                set { endbarsago = value; }
            }
    		
    		
    		[Description("Negative nos pushes line start to the right.")]
            [GridCategory("Parameters")]
    		[Gui.Design.DisplayName ("b.StartBarNo")]
            public int Startbarsago
            {
                get { return startbarsago; }
                set { startbarsago = value; }
            }
    		
    		[GridCategory("Parameters")]
    		[Description("Thickness of line")]
    		[NinjaTrader.Gui.Design.DisplayName("d.Line thickness")]
    		public int thickness
    		{
    			get { return Thickness; }
                set { Thickness = value; }
    		}
    		
    
    		
            #endregion
        }
    }
    When eSignal is the datafeed, it seems like OnMarketData does not execute that accurately. I notice ChartTrader is always accurate, never a hiccup, so I look to that as my reference. However, this indicator does not receive all the updates ChartTrader does, there are no other indicators on the chart, except bar counter. Update speed is 0.1 sec.

    I also have CQG, Bid/Ask is a lot more accurate there (in sync with ChartTrader), however, it may be due to CQG sending out more/faster updates ?

    chris

    #2
    Hi Chris, do you see for all instruments / expiries you tested on? It could be one feed is delivering more ticks and being less filtered, so the indicator result would better align and thus differences coming from the chart display update interval would be less pronounced perhaps.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello, while i think it is interesting that there are differences that large between datafeeds, the fact of the matter seems to be that, the chartTrader is being updated before the actual chart is. OnMarketData is not the first event, or chartTrader has some kind of priority over indicator updates on the chart.

      eSignal lag: 4 secs.
      cqg lag: 1 secs

      chris

      Comment


        #4
        Originally posted by cmaxb View Post
        Hello, while i think it is interesting that there are differences that large between datafeeds, the fact of the matter seems to be that, the chartTrader is being updated before the actual chart is. OnMarketData is not the first event, or chartTrader has some kind of priority over indicator updates on the chart.

        eSignal lag: 4 secs.
        cqg lag: 1 secs

        chris
        Hi Chris,

        Here are some of my observations.

        OnmarketData updates every tick.

        ChartTrader updates once a second.

        Charts without indicators using Volume series update every time there is a trade at a price different from the prior trade.

        Charts with indicators using Volume series update every time there is a trade. But not faster than the chart update governor setting.

        These observations were made using zen-fire data.

        I reserve the right to be wrong. these tests were run over a year ago.

        RJay
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        18 views
        0 likes
        Last Post traderqz  
        Started by algospoke, 04-17-2024, 06:40 PM
        5 responses
        48 views
        0 likes
        Last Post algospoke  
        Working...
        X