ChartAnchor

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Drawing Tool >

ChartAnchor

Previous page Return to chapter overview Next page

Definition

Defines objects used by Drawing Tools which represent a point on the chart where the Drawing Tool is located.

 

Syntax

class ChartAnchor

 

Constructors

new ChartAnchor()

Initializes a new instance of the ChartAnchor object

new ChartAnchor(DateTime time, double price, ChartControl 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 chartControl)

Initializes a new instance of the ChartAnchor object using time, y-axis coordinates, current bar, and relative chart control

 

Methods and Properties

CopyDataValues()

Copies the ChartAnchor time and price values from on 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 the anchor is visible on the UI.

IsEditing

A bool value determining the anchor is currently being edited

IsNinjaScriptDrawn

Indicates if the chart anchor was drawn by a NinjaScript object

IsXPropertiesVisible

A bool value determining the X properties are visible on the UI

IsYPropertyVisible

A bool value determining 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 x values from start point by a delta point amount

MoveAnchorY()

Moves an anchor y values from start point by a delta point amount

Price

Determines price value the chart anchor is drawn.

SlotIndex

Indicates the nearest bar slot where anchor is drawn.

Time

Determines 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

ns


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 instances 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);
    }
  }
}