Collections

ChartDrawings

Description

ChartDrawings is a collection containing all drawing objects within the chart. The property hold all drawings which were generated by the script. The index for ChartDrawings is the explicit name for the drawing object (string tag).

Usage

ChartDrawings [string tag]

Example

Note: To be able to use the interface definitions you must use the using method.

using AgenaTrader.Plugins;
// Output number of drawing objects within the chart and their tags
Print("The chart contains " + ChartDrawings.Count + " drawing objects.");
foreach (IDrawObject draw in ChartDrawings) Print(draw.Tag);
//Draw a black trend line...
AddChartLine("MyLine", true, 10, Close[10], 0, Close[0], Color.Black, DashStyle.Solid, 3);
// ... and change the color to red
ITrendLine line = (ITrendLine) ChartDrawings["MyLine"];
if (line != null) line.Pen.Color = Color.Red;
// Set all lines within the chart to a line strength of 3,
// and lock it so that it cannot be edited or moved
foreach (IDrawObject draw in ChartDrawings)
if (draw is IVerticalLine)
{
    IVerticalLine vline = (IVerticalLine) draw;
    vline.IsLocked = true;
    vline.Editable = false;
    vline.Pen.Width = 3;
}

InSeries

Description

InSeries is a DataSeries object in which the input data for an indicator or strategy is stored.

If the indicator is used without any explicit instructions for the input data, then the closing price for the current market prices will be used.

When calling up the SMA(20) the smoothing average is calculated on the basis of the closing prices for the current chart price data (this is equivalent to SMA(close,20).

InSeries[0] = Close[0].

When calling up the SMA(high, 20) the high price values are loaded and used for the calculation of the smoothing average.

InSeries[0] = High[0].

This way you can select which data series should be used for the calculation of the indicator.

double d = RSI(SMA(20), 14, 3)[0]; calculates the 14 period RSI using the SMA(20) as the input data series. InSeries[0] = SMA(20)[0].

Usage

InSeries
InSeries[int barsAgo]

Example

Print("The input data for the indicators are " + Input[0]);

Lines

Description

Lines is a collection that contains all LevelLine objects of an indicator.

When a line object is added to the indicator using the Add() method, this line is automatically added to the "lines" collection.

The order of the add commands determines how these lines are sorted. The first information request of Add() will create Lines[0], the next information request will be Lines[1] etc.

See OutputDescriptor.

Usage

Lines[int index]

Example

// Add "using System.Drawing.Drawing2D;" for DashStyle
protected override void OnInit()
{
Add(new LevelLine(Color.Blue, 70, "Upper")); // saves into Lines[0]
Add(new LevelLine(Color.Blue, 30, "Lower")); // saves into Lines[1]
}
protected override void OnCalculate()
{
// When the RSI is above 70, properties of the lines will be changed
if (RSI(14 ,3)[0] >= 70)
{
    Lines[0].Width = 3;
    Lines[0].Color = Color.Red;
    Lines[0].DashStyle = DashStyle.Dot;
}
else
{
    Lines[0].Width = 1;
    Lines[0].Color = Color.Blue;
    Lines[0].DashStyle = DashStyle.Solid;
}
}

PlotColors

Description

PlotColors is a collection that contains all color series of all plot objects.

When a plot is added using the Add() method it automatically creates a color series object and is added to the PlotColors collection.

The order of the add commands determines how the plot colors are sorted. The first information request of Add() will create PlotColors[0], the following information request will create PlotColors[1] etc.

Usage

PlotColors[int PlotIndex][int barsAgo]

More Information

More information regarding the collection class: http://msdn.microsoft.com/en-us/library/ybcx56wz%28v=vs.80%29.aspx

Example

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using AgenaTrader.API;
namespace AgenaTrader.UserCode
{
    [Description("PlotColor Demo")]
    public class PlotColorsDemo : UserIndicator
{
    public DataSeries SMA20 { get {return Outputs[0];} }
    public DataSeries SMA50 { get {return Outputs[1];} }
    public DataSeries SMA100 { get {return Outputs[2];} }
    private Pen pen;
    protected override void OnInit()
{
// Set line strength (width) to 4
pen = new Pen(Color.Empty, 4);
// Add three plots with the defined line strength to the chart
Add(new OutputDescriptor(pen, OutputSeriesDisplayStyle.LevelLine, "SMA20" )); //attached to PlotColors[0]
Add(new OutputDescriptor(pen, OutputSeriesDisplayStyle.LevelLine, "SMA50" )); //attached to PlotColors[1]
Add(new OutputDescriptor(pen, OutputSeriesDisplayStyle.LevelLine, "SMA100")); //attached to PlotColors[2]
IsOverlay = true;
}
    protected override void OnCalculate()
{
// Add values to the three plots
SMA20.Set (SMA(20) [0]);
SMA50.Set (SMA(50) [0]);
SMA100.Set(SMA(100)[0]);
// Change colors depending on the trend
if (IsSerieRising(Close))
{
    PlotColors[0][0] = Color.LightGreen;
    PlotColors[1][0] = Color.Green;
    PlotColors[2][0] = Color.DarkGreen;
}
else if (IsSerieFalling(Close))
{
    PlotColors[0][0] = Color.LightSalmon;
    PlotColors[1][0] = Color.Red;
    PlotColors[2][0] = Color.DarkRed;
}
else
{
    PlotColors[0][0] = Color.LightGray;
    PlotColors[1][0] = Color.Gray;
    PlotColors[2][0] = Color.DarkGray;
}
}
}
}

OutputDescriptor

Description

OutputDescriptor is a collection that contains the plot objects of an indicator.

When a plot object is added to an indicator using the Add() method, it is also automatically added to the "plots" collection.

The order of the add commands determines how the plots are sorted. The first Add() information request will create Plots[0], the following information request will create OutputDescriptor[1] etc.

See Lines.

Usage

OutputDescriptor[int index]

Example

protected override void OnInit()
{
    Add(new OutputDescriptor(Color.FromKnownColor(KnownColor.Blue), "MySMA 20")); // saved to OutputDescriptor[0]
}
protected override void OnCalculate()
{
Value.Set(SMA(20)[0]);
// If the market price is above the SMA colorize it green, otherwise red
if (Close[0] > SMA(20)[0])
    OutputDescriptor[0].PlotColor = Color.Green;
else
    OutputDescriptor[0].PlotColor = Color.Red;
}

Values

Description

Values are a collection that contains the data series objects of an indicator.

When a plot is added to an indicator using the Add() method, a value object is automatically created and added to the "values" collection.

The order of the add commands determines how the values are sorted. The first information request will create Values[0], the next information request will create Values[1], etc.

Value is always identical to Values[0].

Usage

Outputs[int index]
Outputs[int index][int barsAgo]

More Information

The methods known for a collection, Set() Reset() and Count(), are applicable for values.

Information on the class collection: http://msdn.microsoft.com/en-us/library/ybcx56wz%28v=vs.80%29.aspx

Example

// Check the second indicator value of one bar ago and set the value of the current indicator value based on it.
if (Instrument.Compare(Outputs[1][1], High[0] - Low[0]) < 0)
    Value.Set(High[0] - Low[0]);
else
    Value.Set(High[0] - Close[0]);

Last updated