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 aa731, Today, 02:54 AM
            0 responses
            4 views
            0 likes
            Last Post aa731
            by aa731
             
            Started by thanajo, 05-04-2021, 02:11 AM
            3 responses
            469 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            10 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,237 views
            0 likes
            Last Post sidlercom80  
            Started by thread, Yesterday, 11:58 PM
            0 responses
            4 views
            0 likes
            Last Post thread
            by thread
             
            Working...
            X