Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Navigating a chart directly to a specific trade or date/time

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

    #16
    Make an indicator. Add the using declaration
    Code:
    Using System.Reflection
    Add a DateTimePicker to the ToolStrip w/ something like this

    Code:
    picker.Name = "date";
    picker.ValueChanged += updateDate;
    
    ch = new ToolStripTextBox("date");
    ch.Text = lastDate.ToString("yyyy-MM-dd");
    ch.Name = "date";
    ch.TextChanged += updateDate;
    strip.Items.Add(ch);
    Code:
    private void updateDate(Object sender, EventArgs e){
    	//lastDate = picker.Value;
    	try{
    		ToolStripTextBox t = (ToolStripTextBox) sender;
    		lastDate = DateTime.ParseExact(t.Text, "yyyy-MM-dd",
    										System.Globalization.CultureInfo.InvariantCulture);
    
    		runOverall();
    		ChartControl.ChartPanel.Refresh();
    	}catch (Exception ex){
    		
    	}
    	GoTo(lastDate);
    				
    }
    		
    public void GoTo( DateTime time)
    {
    	MethodInfo miGoTo = typeof(NinjaTrader.Gui.Chart.ChartControl).GetMethod( "GoTo", BindingFlags.InvokeMethod | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase );
    
    	if( miGoTo != null )
    	{
    		object[] args = { time };
    		miGoTo.Invoke( ChartControl, args );
    	}
    }

    Comment


      #17
      Any chance this could work in NT 8?

      I've tried habibalex's code and I don't think "NinjaTrader.Gui.Chart.ChartControl" has a "GoTo" method anymore.

      Code:
      	MethodInfo miGoTo = typeof(NinjaTrader.Gui.Chart.ChartControl).GetMethod( "GoTo", BindingFlags.InvokeMethod | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase );
      miGoTo is null.

      "ChartControl.FirstTimePainted" cannot be set. It's read only.

      Comment


        #18
        Thank you for your report, maker. While this tool is being provided for educational purposes only, I was able to use the (publicly available MSDN documentation linked) GetMethods method to learn what all the methods attached to ChartControl are. They are attached in the output.txt file.

        While we can not directly support undocumented methods, one method that caught my eye is

        Code:
        Void ScrollToTime(System.DateTime)
        I would recommend starting any investigation into repairing habibalex' tool with this list, as ChartControl is an object that has robust documentation, which we will be happy to answer questions regarding.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #19
          There is chartControl.LastSlotPainted which you can set this to move the chart to show that last bar painted to the idx you set it too. I would recommend using that in combination with a GetBarIdxByTime() method.



          Comment


            #20
            Brett and JessicaP thanks for the prompt reply. That pointed me in the right direction and I was able to get things working. Here's a quick example of jumping to the first trade in a Strategy.

            Code:
            // Wrapped in some custom function that gets called from a button/menu/toolbar.
            if (ChartControl.Strategies[0].SystemPerformance.AllTrades.Count > 1)
            {
              firstTrade = ChartControl.Strategies[0].SystemPerformance.AllTrades[0];
            
              if (firstTrade != null)
              {
                Execution executionExit = firstTrade.Exit;
                Print("The first trade time: " + executionExit.Time);
            
                int executionExitIndex = ChartBars.GetBarIdxByTime(ChartControl, executionExit.Time);
                Print("The execution exit index: " + executionExitIndex);
            
                // Set the right side of the chart to the exit time of the first trade.
                ChartControl.LastSlotPainted = executionExitIndex;
                Print("ChartControl.LastSlotPainted: " + ChartControl.LastSlotPainted);
            
                // Refresh the chart so it redraws at the new position.
                ForceRefresh();
              }
            }
            Most of the time "ForceRefresh()" works and the chart redraws, but I do notice that sometimes the chart gets stuck and doesn't update after scrolling until I "bump" something and get it to re-render.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ghoul, Today, 06:02 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            180 views
            0 likes
            Last Post jeronymite  
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Working...
            X