Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing intrabar data from chart style

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

    Accessing intrabar data from chart style

    Is there a way to access intrabar (tick) data from within Chart Style? To give a simplified example if I would like to show average tick price within the bar.

    I know I can easily do it as an indicator but this example is purposefully simplified and real life chart style would benefit from being able to access intrabar tick collection.

    Alternatively is there a way I can expose this additional data from custom bar type so that it will be picked up by custom chart style?

    #2
    There is nothing we can currently support in this area.

    The best I can give you is an incomplete solution, as our ChartStyles are completely agnostic to the bars/instruments they are running on before the object is rendered and do not support dynamic properties. I'm not certain why you would need tick data for this process, and would think that perhaps what you're trying to do would be better suited for an indicator or bar type.

    But with that said, any NinjaScript type has access to a BarsRequest. The problem you're going to run into, is the ChartStyle has no way to know what instrument it is running against as previously stated. You may be able to set up some static resource somehow to provide this info to your custom chart style, although I have not explored that option. We could not support any issues that arise from attempting to get that value through some other resource (e.g., such as trying to use the chartBars through OnRender)

    Code:
    protected override void OnStateChange()
    {
    	if (State == State.Active)
    	{
    		// check chart style has actually been applied to a chart
    		if (RenderTarget == null)
    			return;
    			
    		// create a new bars request to the desired instrument... theres no reliable way to know what instrument is applied though.
    		// You'll need to maybe make some static resource (maybe from your barstype??)
    
    		BarsRequest barsRequest = new BarsRequest(Instrument.GetInstrument("AAPL"), 50);
    
    		// you can parametrize a bar type to your own custom bartype by casting the barsperiodtype enum value
    		barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Tick, Value = 1 };
    
    		barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
    		{
    			// !!! don't forget to add some error code/message handling !!!
    			// http://ninjatrader.com/support/helpGuides/nt8/en-us/barsrequest.htm
    			for (int i = 0; i < bars.Bars.Count; i++)
    			{
    				// Output the bars
    				NinjaTrader.Code.Output.Process(string.Format("Time: {0} Open: {1} High: {2} Low: {3} Close: {4} Volume: {5}",
    				                                bars.Bars.GetTime(i),
    				                                bars.Bars.GetOpen(i),
    				                                bars.Bars.GetHigh(i),
    				                                bars.Bars.GetLow(i),
    				                                bars.Bars.GetClose(i),
    				                                bars.Bars.GetVolume(i)), PrintTo.OutputTab1);
    			}
    
    		}));
    
    		barsRequest = null;
    	}
    }
    If you can submit the use case for getting tick data/instrument information to a ChartStyle, I'll be glad to put that on our list to review at a later time when we can accommodate such a change if it makes sense at that time.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks Matthew, I will try this.

      At the moment I am simply exploring the possibilities and deciding on the approach to take. There is a thin line between a chart style and an indicator as they both represent/draw the price data. So the question arises eg. why Volume Ladder should be an indicator and not a chart style.
      On the other hand if we define chart style as dealing ONLY with OHLC data then the distinction is quite clear. But then what should be the most efficient way of let's say drawing your own bars (from an indicator) and stopping NT from drawing from Chart Style. At the moment I set the color of the bars to transparent - is there any performance penalty for that?

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by funk10101, Today, 09:43 PM
      0 responses
      6 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Started by yertle, Today, 08:38 AM
      6 responses
      26 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      24 views
      0 likes
      Last Post algospoke  
      Working...
      X