Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Loop MarketDataEvents

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

    Loop MarketDataEvents

    Hi, is it possible to loop through marketdata events / updates? for example if I wanted to loop through the marketdata events which happened between bar 10 and 20 when currentbar is 30, how whould i do that?
    one additional question: is it possible to force recalculation of an indicator programmatically?

    Regards and thanks

    #2
    Hello keepsimple,

    With NinjaTrader 8, OnMarketData will trigger historically if Tick replay is enabled for that data series.

    However, there is not a data series created for the market data. This means that if you want to be able to call this information back in time, then you would need to store each market data to a variable or collection like an array.

    So as each OnMarketData event comes in, save this to a collection and you can call this from your collection at any time.


    Also, to trigger an indicator to recalculate you can either run a loop for every bar and set all of the historical values to your liking, or you can trigger the historical data to be reloaded.
    ReloadAllHistoricalData();
    Last edited by NinjaTrader_ChelseaB; 06-30-2015, 08:24 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,

      solved that, could you please give me a headsup, on how to get the bar number of a mouse clicked bar.

      Regards and thanks

      Comment


        #4
        Hello keepsimple,

        From the mouse down or mouse up override use GetSlotByX and use the x of the mouse pointer.

        The approach for this may be different depending on what type of class you are working in.

        private void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
        Print(GetSlotByX(e.GetPosition(ChartPanel as IInputElement).X));
        }

        or

        public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
        {
        Print(GetSlotByX(dataPoint.GetPoint(chartControl, chartPanel, chartScale).X));
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea,

          will work with that, if I have additional questions, I will post back.

          Regards

          Comment


            #6
            Hi Chelsea,

            sorry, but cant get this to work, are you sure GetSlotByX is correct, cant find that in the help guide and when i insert the code it wont compile, get an error message:
            The name 'GetSlotByX' does not exist in the current context


            Regards

            Comment


              #7
              Hello keepsimple,

              I made a mistake with that. Should be GetSlotIndexByX().

              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Sorry,
                for bothering you again, but I am still getting the same error message.
                I inserted the code in indicator code, am I missing something here?

                Regards

                Comment


                  #9
                  Sorry for the confusion, need to specify the ChartControl class:

                  ChartControl.GetSlotIndexByX(1);
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Sorry cant get that working, could you please give me short snippet of code which capures the mouse clicked bar, and returns the barindex of that bar.

                    thanks

                    Comment


                      #11
                      Originally posted by keepsimple View Post
                      Sorry cant get that working, could you please give me short snippet of code which capures the mouse clicked bar, and returns the barindex of that bar.

                      thanks
                      There was an issue in Beta 2 which prevented the mouse down left click event from being detected... the below will work in Beta 3 due out later this week. For now you can use the right click event which should work.

                      Code:
                      protected override void OnStateChange()
                      {
                      	if (State == State.SetDefaults)
                      	{
                      		Name	= "BarsData";				
                      		IsOverlay	= true;
                      	}			
                      	
                      	else if (State == State.Historical)
                      	{			
                      		// subscribe to chart panel mouse down event
                      		ChartPanel.MouseDown += OnMouseDown;
                      	}
                      	
                      	else if (State == State.Terminated)
                      	{
                      		ChartPanel.MouseDown -= OnMouseDown;	
                      	}			
                      }	
                      
                      private void OnMouseDown(object sender, MouseButtonEventArgs e)
                      {
                      	// print the nearest slot index by the mouse down point.x
                      	Print(ChartControl.GetSlotIndexByX((int)ChartControl.MouseDownPoint.X));		
                      }
                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        Thanks, will work with that, if I have any additional question, i will post back.

                        Comment


                          #13
                          Hi Matthew,
                          I worked with the attached code, which does pretty much what I want, but there is still an issue, it compiles, but when I add the indicator to a chart I get the following error message: Error on calling "OnStateChange" method: Object reference not set to an instance of an object.

                          Regards

                          Comment


                            #14
                            That was a pretty dirty example, for completeness you should check if ChartPanel != null in both States.

                            Code:
                            	else if (State == State.Historical)
                            	{			
                            		// subscribe to chart panel mouse down event
                                        if(ChartPanel != null)
                            		ChartPanel.MouseDown += OnMouseDown;
                            	}
                            	
                            	else if (State == State.Terminated)
                            	{
                                        if(ChartPanel != null)
                            		ChartPanel.MouseDown -= OnMouseDown;	
                            	}
                            MatthewNinjaTrader Product Management

                            Comment


                              #15
                              Thanks,
                              thought so, just wasnt sure.

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              149 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X