Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Drawing Tool Question...

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

    Custom Drawing Tool Question...

    In GetSelectionPoints() I want to change the "anchor point" to the high of the bar selected, how would this be done?

    Code:
    public override Point[] GetSelectionPoints(ChartControl chartControl, ChartScale chartScale)
    		{
    			if (chartControl.BarsArray.Count == 0)
    				return null;
    			
    			try
    			{
                                    Bars bars = chartControl.BarsArray[0].Bars;
    
    				ChartPanel chartPanel = chartControl.ChartPanels[chartScale.PanelIndex];
    				Point anchorPoint = Anchor.GetPoint(chartControl, chartPanel, chartScale);
    				
                                    int idx = bars.GetBar(Anchor.Time);
    				[color=red]double high = bars.GetHigh(idx);[/color]
    
                                    // Point highPoint = new Point();
                                    [b] // how do I convert this "high" value to a useable "anchor point" to return?[/b]
    				
    				[color=red]return new[] { highPoint }; ??[/color]
    			}
    			catch (Exception e)
    			{
    				Print (e.Message);
    				return null;
    			}
    		}

    #2
    I will answer my own question for others :-)

    Code:
    public override Point[] GetSelectionPoints(ChartControl chartControl, ChartScale chartScale)
    		{
    			if (chartControl.BarsArray.Count == 0)
    				return null;
    			
    			try
    			{
    				ChartPanel chartPanel = chartControl.ChartPanels[chartScale.PanelIndex];
    				Point anchorPoint = Anchor.GetPoint(chartControl, chartPanel, chartScale);
    				
                                    // high is defined else where in the code from Bars object -> bars.GetHigh(index);
                                    ChartAnchor HighAnchor = new ChartAnchor(Anchor.Time, high, chartControl);
                                    Point highPoint = HighAnchor.GetPoint(chartControl, chartPanel, chartScale);
    				
    				return new[] { highPoint };
    			}
    			catch (Exception e)
    			{
    				Print (e.Message);
    				return null;
    			}
    		}

    Comment


      #3
      Use the chartScale.GetYByValue() method and pass in the high value you calculated.

      If you solely want the selection point to be on the high of the bar, there is no reason to create a new anchor point, you can just assign the anchorPoint.Y to that value:

      Code:
      anchorPoint.Y = chartScale.GetYByValue(high);
      				
      return new[] { anchorPoint };
      If you want to have both the objects Anchor as the selection point and you want a new selection point as the High value, you can create a copy of Anchor point and then set that copies .Y value, then return both points

      Code:
      Point highPoint = anchorPoint;
      
      highPoint.Y = chartScale.GetYByValue(high);
      
      return new[] { anchorPoint, highPoint };
      MatthewNinjaTrader Product Management

      Comment


        #4
        Ah, cool, thanks.

        Comment


          #5
          Thanks so much for sharing this!

          Could you please paste the full context of your cod3? Need to do something similar in an indicator and am wondering where to put it. (OnBarUpdate? OnRender?)

          Thanks again.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tim-c, Today, 03:54 AM
          0 responses
          2 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          2 views
          0 likes
          Last Post FrancisMorro  
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,770 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          31 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          945 views
          0 likes
          Last Post spwizard  
          Working...
          X