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

Acsses OnMarketData with multi instruments.

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

    Acsses OnMarketData with multi instruments.

    Hello Ninjas

    I have a problem please help me!
    I am building a indicator multi-instruments.
    In the middle of the code I call the BuySellVolume Indicator
    But it is not returning anything.
    I know this indicator uses "onMarketData".
    Is it possible to access inidicators that using onmarketdata in multi-instrument indicators?
    If yes, please show me how.

    Thanks

    #2
    Hello. Thank you for the note.

    The Calculation mode of the indicator that uses BuySellVolume must be set to Calculate.OnEachTick. If the indicator initially relied on Calculate.OnBarClose logic, you can still simulate that logic by using IsFirstTickOfBar. Additionally, BuySellVolume will not produce values while calculating on historical data unless Tick Replay is enabled.

    https://ninjatrader.com/support/help...ick_replay.htm - Tick Replay

    For a detailed explanation of how to separate logic, please see this forum post.



    I have also attached an example that successfully pulls data from the BuySellVolume indicator.

    For instructions on importing, see here:


    Please let us know if we may be of any further assistance.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      First: thank tou for response... very good explanation.

      I'm working on this line of reasoning.
      I do not know what I'm doing wrong. I created a series with objects and I'm trying to access it in another indicator.

      root indicator:
      HTML Code:
      public class SampleIndicatorOMD : Indicator
      	{
      		private int activeBar = 0;
      		
      		public struct InfoFP
      		{
      			public long bidsSum;
      			public long bidFilt;
      			public long asksSum;
      			public long askFilt;
      			public long candleVolTotal;
      		}
      		private InfoFP infoFP;
      		public Series<InfoFP> Out01;
      
      		
      		
      		protected override void OnStateChange()
      		{
      			if (State == State.SetDefaults)
      			{
      				Description									= @"Enter the description for your new custom Indicator here.";
      				Name										= "SampleIndicatorOMD";
      				Calculate									= Calculate.OnEachTick;
      				IsOverlay									= true;
      				DisplayInDataBox							= false;
      				DrawOnPricePanel							= false;
      				DrawHorizontalGridLines						= false;
      				DrawVerticalGridLines						= false;
      				PaintPriceMarkers							= false;
      				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Overlay;
      				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
      				//See Help Guide for additional information.
      				IsSuspendedWhileInactive					= false;
      				BarsRequiredToPlot = 0;
      				
      			}
      			else if (State == State.Configure)
      			{
      			}
      			else if (State == State.DataLoaded)
      			{				
      				Out01 = new Series<InfoFP>(this);
      			}
      		}
      
      		protected override void OnMarketData(MarketDataEventArgs e)
      		{
      		    if (e.MarketDataType == MarketDataType.Last)
      			{
      				if (e.Price >= e.Ask)
      				{
      					long volumeAsk = e.Volume;
      					long volumeBid = 0;
      					infoFP.asksSum = infoFP.asksSum + volumeAsk;
      				}
      				if (e.Price <= e.Bid)
      				{
      					long volumeBid = e.Volume;
      					long volumeAsk = 0;
      					infoFP.bidsSum = infoFP.bidsSum + volumeBid;
      				}
      				//===========================================
      				infoFP.candleVolTotal = infoFP.candleVolTotal + e.Volume;
      
      			}
      		}
      		protected override void OnBarUpdate()
      		{
      			if (CurrentBar != activeBar)
      			{
      				Out01[1] = infoFP;
      
      				infoFP.bidsSum = 0;
      				infoFP.bidFilt = 0;
      				infoFP.asksSum = 0;
      				infoFP.askFilt = 0;
      				infoFP.candleVolTotal = 0;
      				activeBar = CurrentBar;
      			}
      			Out01[0] = infoFP;
      		}
      
      	}

      I want to access the series Out01 in the indicator that follows:


      HTML Code:
       namespace NinjaTrader.NinjaScript.Indicators
      {
      	public class SampleCallIndiccatorOMD : Indicator
      	{
      		SampleIndicatorOMD SIOMD;
      		
      		protected override void OnStateChange()
      		{
      			if (State == State.SetDefaults)
      			{
      				Description									= @"Enter the description for your new custom Indicator here.";
      				Name										= "SampleCallIndiccatorOMD";
      				Calculate									= Calculate.OnEachTick;
      				IsOverlay									= true;
      				DisplayInDataBox							= true;
      				DrawOnPricePanel							= true;
      				DrawHorizontalGridLines						= true;
      				DrawVerticalGridLines						= true;
      				PaintPriceMarkers							= true;
      				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
      				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
      				//See Help Guide for additional information.
      				IsSuspendedWhileInactive					= false;
      				BarsRequiredToPlot = 0;
      			}
      			else if (State == State.Configure)
      			{
      				AddDataSeries("ES ##-##", Data.BarsPeriodType.Range, 10, Data.MarketDataType.Last);
      				
      				SIOMD = SampleIndicatorOMD();
      			}
      			else if (State == State.DataLoaded)
      			{
      			}
      		}
      
      		protected override void OnBarUpdate()
      		{
      
      
      			Print("============== New ================== "+(CurrentBars[BarsInProgress]).ToString());
      			Print(BarsArray[BarsInProgress].Instrument.FullName);
      			Print("SIOMD.Out01.Count "+SIOMD.Out01.Count);
      			Print(SIOMD.Out01[0].asksSum);
      				
      
      		}
      	}
      }
      OUTPUT:
      "ES ##-##
      0
      Indicator 'SampleCallIndiccatorOMD': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

      I am unable to access out01 on the indicator "SampleCallIndiccatorOMD".
      Please help me.
      Last edited by MarceloF; 02-12-2018, 08:50 PM.

      Comment


        #4
        Hello. Thank you for the reply.

        In OnBarUpdate, you must check to make sure that the CurrentBars value is enough to start processing your script. When you apply a script to a chart, it will start at the leftmost bar, i.e. CurrentBars[0] == 0 and run through all of the historical bars until it reaches real time data.

        In the root indicator, you are accessing this:

        Code:
        Out01[1] = infoFP;
        This will not work if you request it when CurrentBar == 0

        Adding a check for this in both scripts will make it work.

        Root indicator:

        Code:
        protected override void OnBarUpdate()
        {
        	if(CurrentBar < 1) return;
                ...
        }
        The indicator that is accessing root indicator:

        Code:
        protected override void OnBarUpdate()
        {
        	if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                ...
        }
        Please see this help guide page on CurrentBars for an additional example:


        Please let us know if you have any questions.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Barry Milan, Yesterday, 10:35 PM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        12 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        8 views
        0 likes
        Last Post nandhumca  
        Working...
        X