ChartAnchor
Definition
Defines objects used by Drawing Tools which represent a point on the chart where the Drawing Tool is located.
Syntax
class ChartAnchor
Constructors
| Constructor | Description |
|---|---|
| new ChartAnchor() | Initializes a new instance of the ChartAnchor object |
| new ChartAnchor(DateTime time, double price, ChartControl) | Initializes a new instance of the ChartAnchor object using time, price, and relative chart control |
| new ChartAnchor(DateTime time, double yValue, int currentBar, ChartControl) | Initializes a new instance of the ChartAnchor object using time, y-axis coordinates, current bar, and relative chart control |
Methods and Properties
| Method/Property | Description |
|---|---|
| CopyDataValues() | Copies the ChartAnchor time and price values from one anchor to another |
| DisplayName | A string value which sets the name prefix used for all properties for a chart anchor |
| DrawingTool | The drawing tool which owns a chart anchor |
| DrawnOnBar | Gets the current bar value that the chart anchor is drawn by a NinjaScript object. |
| GetPoint() | Returns a chart anchor’s data points. |
| IsBrowsable | A bool value determining if the anchor is visible on the UI. |
| IsEditing | A bool value determining if the anchor is currently being edited |
| IsNinjaScriptDrawn | Indicates if the chart anchor was drawn by a NinjaScript object |
| IsXPropertiesVisible | A bool value determining if the X properties are visible on the UI |
| IsYPropertyVisible | A bool value determining if the Y data value is visible on the UI |
| MoveAnchor() | Moves a Chart Anchor’s x and y values from start point by a delta point amount. |
| MoveAnchorX() | Moves an anchor’s x values from start point by a delta point amount |
| MoveAnchorY() | Moves an anchor’s y values from start point by a delta point amount |
| Price | Determines the price value the chart anchor is drawn. |
| SlotIndex | Indicates the nearest bar slot where the anchor is drawn. |
| Time | Determines the date/time value the chart anchor is drawn. |
| UpdateFromPoint() | Updates an anchor’s x and y values from a given point (in device pixels) |
| UpdateXFromPoint() | Updates an anchor’s X values from a given point (in device pixels) |
| UpdateYFromPoint() | Updates an anchor’s Y value from a given point (in device pixels) |
Examples
1 public ChartAnchor MyAnchor { get; set; } // declares the "MyAnchor" ChartAnchor object 2 public override IEnumerable<chartanchor> Anchors { get { return new[] { MyAnchor }; } } //adds the "MyAnchor" ChartAnchor object to a collection of anchors used to interact with your anchors 3 protected override void OnStateChange() 4 { 5 if (State == State.SetDefaults) 6 { 7 Description = @"Drawing tool example"; 8 Name = "SampleDrawingTool"; 9 10 MyAnchor = new ChartAnchor(); //creates a new instance of the ChartAnchor object 11 MyAnchor.IsEditing = true; 12 MyAnchor.DrawingTool = this; 13 MyAnchor.IsBrowsable = false; 14 } 15 } 16 17 public override void OnMouseUp(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) 18 { 19 if (DrawingState == DrawingState.Editing) 20 { 21 if (MyAnchor.IsEditing) 22 { 23 //if anchor is editing, update anchor point 24 dataPoint.CopyDataValues(MyAnchor); 25 } 26 }

