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

ConstructorDescription
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/PropertyDescription
CopyDataValues()Copies the ChartAnchor time and price values from one anchor to another
DisplayNameA string value which sets the name prefix used for all properties for a chart anchor
DrawingToolThe drawing tool which owns a chart anchor
DrawnOnBarGets the current bar value that the chart anchor is drawn by a NinjaScript object.
GetPoint()Returns a chart anchor's data points.
IsBrowsableA bool value determining if the anchor is visible on the UI.
IsEditingA bool value determining if the anchor is currently being edited
IsNinjaScriptDrawnIndicates if the chart anchor was drawn by a NinjaScript object
IsXPropertiesVisibleA bool value determining if the X properties are visible on the UI
IsYPropertyVisibleA 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
PriceDetermines the price value the chart anchor is drawn.
SlotIndexIndicates the nearest bar slot where the anchor is drawn.
TimeDetermines 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


public ChartAnchor MyAnchor { get; set; } // declares the "MyAnchor" ChartAnchor object
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
protected override void OnStateChange()
{
   if (State == State.SetDefaults)
   {
     Description = @"Drawing tool example";
     Name = "SampleDrawingTool";

     MyAnchor = new ChartAnchor(); //creates a new instance of the ChartAnchor object
     MyAnchor.IsEditing = true;
     MyAnchor.DrawingTool = this;
     MyAnchor.IsBrowsable = false;
   }
}

public override void OnMouseUp(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
{
   if (DrawingState == DrawingState.Editing)
   {
     if (MyAnchor.IsEditing)
     {
         //if anchor is editing, update anchor point
         dataPoint.CopyDataValues(MyAnchor);
     }
   }