Class BuiltInIndicators
Namespace: TradingPlatform.BusinessLayer
Syntax
public sealed class BuiltInIndicators
Methods
AC()
Returns an instance of the Acceleration/Deceleration Oscillator (AC).
AC measures the acceleration and deceleration of the current momentum.
Declaration
public Indicator AC()
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Acceleration Oscillator example.
/// </summary>
public class AC : Indicator
{
// Holds AC's values.
private Indicator ac;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public AC()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Acceleration Oscillator";
Description = "Acceleration Oscillator example";
// Defines line on demand with particular parameters.
AddLineSeries("AC'Line", Color.Gray, 1, LineStyle.HistogrammChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "AC";
// Creates an instance of the proper indicator (AC) from the default indicators list.
ac = Core.Instance.IndicatorManager.BuiltIn.AC();
// Adds an auxiliary (AC) indicator to the current one (AC Example).
// This will let inner indicator (AC) to be calculated in advance to the current one (AC Example).
AddIndicator(ac);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(ac.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
ADX(Int32, MaMode)
Returns an instance of the Average Directional Index (ADX) indicator.
The ADX determines the strength of a prevailing trend.
Declaration
public Indicator ADX(int period, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// ADX example.
/// </summary>
public class ADX : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period", 0, 1, 999, 0, 0)]
public int Period = 20;
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
#endregion
// Holds ADX's values.
private Indicator adx;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public ADX()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "ADX example";
Description = "ADX example";
// Defines line on demand with particular parameters.
AddLineSeries("ADX'Line", Color.Green, 1, LineStyle.SimpleChart);
AddLineSeries("+DI'Line", Color.Blue, 1, LineStyle.SimpleChart);
AddLineSeries("-DI'Line", Color.Red, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "ADX (" + Period.ToString() + ": " + MAType.ToString() + ")";
// Creates an instance of the proper indicator (ADX) from the default indicators list.
adx = Core.Instance.IndicatorManager.BuiltIn.ADX(Period, MAType);
// Adds an auxiliary (ADX) indicator to the current one (ADX Example).
// This will let inner indicator (ADX) to be calculated in advance to the current one (ADX Example).
AddIndicator(adx);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets values for the displaying on the chart.
for (int i = 0; i < adx.LinesSeries.Length; i++)
{
SetValue(adx.GetValue(0,i),0,i);
}
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
AFIRMA(Int32, PriceType, AfirmaMode, Boolean)
Gets the AFIRMA indicator
Autoregressive finite impulse response moving average. A digital filter accurately shows the price movement as powered with least square method to minimise time lag
Declaration
public Indicator AFIRMA(int period, PriceType priceType, AfirmaMode afirmaMode, bool least_squares_method)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Moving average period |
PriceType | priceType | Type of the price |
TradingPlatform.BusinessLayer.AfirmaMode | afirmaMode | Afirma mode |
System.Boolean | least_squares_method | with least squares method overlapping if true |
Returns
Type | Description |
---|---|
Indicator |
Examples
using System;
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Indicators
{
public class TestAfirma : Indicator
{
#region Input params
Indicator Afirma, Windowing;
///
///Input Parameter with an input field or checkbox (if bolean)
///
[InputParameter("Window period", 0, 1, 9999)]
public int Period = 20;
///
/// Input Parameter with a dropdown
///
[InputParameter("Sources prices for calculation", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
[InputParameter("Windowing function", 2, new object[]{
"Hanning", AfirmaMode.Hanning,
"Hamming", AfirmaMode.Hamming,
"Blackman", AfirmaMode.Blackman,
"Blackman - Harris", AfirmaMode.BlackmanHarris}
)]
public AfirmaMode win = AfirmaMode.Hanning;
#endregion
public TestAfirma()
: base()
{
Name = "Afirma GAP";
Description = "Prints gap between Window function and least-squares method";
AddLineSeries("Line", Color.Blue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public override void Init()
{
// Creation of an indicator Windowing MA with least-squares method overlapping (Afirma)
Afirma = Core.Instance.IndicatorManager.BuiltIn.AFIRMA(Period, SourcePrice, win, true);
AddIndicator(Afirma);
// Creation of an indicator Windowing MA
Windowing = Core.Instance.IndicatorManager.BuiltIn.AFIRMA(Period, SourcePrice, win, false);
AddIndicator(Windowing);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
if (Count <= Period)
return;
var res = Math.Abs((Afirma.GetValue()-Windowing.GetValue()))/100;
Print(res.ToString()+" %");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Alligator(MaMode, PriceType, Int32, Int32, MaMode, PriceType, Int32, Int32, MaMode, PriceType, Int32, Int32)
Gets the Alligator.
Three moving averages with different colors, periods and calculation methods.
Declaration
public Indicator Alligator(MaMode JawMAType, PriceType JawSourcePrice, int JawMAPeiod, int JawMAShift, MaMode TeethMAType, PriceType TeethSourcePrice, int TeethMAPeiod, int TeethMAShift, MaMode LipsMAType, PriceType LipsSourcePrice, int LipsMAPeiod, int LipsMAShift)
Parameters
Type | Name | Description |
---|---|---|
MaMode | JawMAType | Type of Jaw Moving Average. |
PriceType | JawSourcePrice | SourcePrice of Jaw Moving Average. |
System.Int32 | JawMAPeiod | Period of Jaw Moving Average. |
System.Int32 | JawMAShift | Shift of Jaw Moving Average. |
MaMode | TeethMAType | Period of Moving Average. |
PriceType | TeethSourcePrice | Type of Moving Average. |
System.Int32 | TeethMAPeiod | Period of Moving Average. |
System.Int32 | TeethMAShift | Type of Moving Average. |
MaMode | LipsMAType | Period of Moving Average. |
PriceType | LipsSourcePrice | Type of Moving Average. |
System.Int32 | LipsMAPeiod | Period of Moving Average. |
System.Int32 | LipsMAShift | Type of Moving Average. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestAlligator : Indicator
{
#region Paramaters
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Jaw Moving Average", 0, new object[]{
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode JawMAType = MaMode.SMA;
[InputParameter("Source price for Jaw Moving Average", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType JawSourcePrice = PriceType.Close;
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period of Jaw Moving Average", 0, 2, 999, 1, 0)]
public int JawMAPeiod = 13;
#endregion Parameters
private Indicator Alligator;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestAlligator()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestAlligator";
Description = "Example of using built-in Alligator indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("JAW", Color.Green, 1, LineStyle.SimpleChart);
AddLineSeries("LIPS", Color.LightSkyBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "TestAlligator :JawMAPeiod" + JawMAPeiod.ToString();
// Get 'Alligator' indicator from built-in indicator collection. Reset only jaw params, the rest is by default.
Alligator = Core.Instance.IndicatorManager.BuiltIn.Alligator(JawMAType, JawSourcePrice, JawMAPeiod, 0, MaMode.SMA,PriceType.Close,8,0, MaMode.SMA, PriceType.Close, 5, 0);
AddIndicator(Alligator);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Get values from 'Alligator' indicator lines.
var Jaw = Alligator.GetValue();
var Lips = Alligator.GetValue(0,2);
SetValue(Jaw);
SetValue(Lips, 0,1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
AO()
Gets the AO (Awesome Oscillator) indicator.
The 'AO' indicator determines market momentum.
Declaration
public Indicator AO()
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestAO : Indicator
{
private Indicator ao;
public TestAO()
: base()
{
// Defines indicator's name and description.
Name = "Test AO";
Description = "Example of using built-in AO indicator";
// Define two lines (on sub window) with particular parameters
AddLineSeries("AO", Color.Gray, 3, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestAO";
// Get 'AO' indicator from built-in indicator collection.
ao = HistoricalData.BuiltIn.AO();
}
public override void OnUpdate(UpdateArgs args)
{
// Get AO indicator value.
var aoValue = ao.GetValue();
// The AO has fixed periods (9 and 34) in own calculation.
// We check, if 'aoValue' is 'NaN' (That's mean, at this moment, the 'Count' isn't enough for correct calculation of AO)
// then we skip our logic below.
if (aoValue == double.NaN)
return;
// Set values to 'AO' line buffer.
SetValue(aoValue);
}
}
}
AROON(Int32)
Gets the Aroon indicator.
Reveals the beginning of a new trend and determines how strong it is
Declaration
public Indicator AROON(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Aroons period |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class AroonTest : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Aroon Period", 0, 1, 999, 1, 0)]
public int Period = 14;
#endregion Parameters
private Indicator Aroon;
public AroonTest()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "AroonTest";
Description = "Example of using built-in Aroon indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Up line", Color.Red, 2, LineStyle.SimpleChart);
AddLineSeries("Down line", Color.CadetBlue, 2, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "Arron ("+Period.ToString()+")";
// Get 'Arron' indicator from built-in indicator collection.
Aroon = Core.Instance.IndicatorManager.BuiltIn.AROON(Period);
AddIndicator(Aroon);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count<=Period)
return;
// Get values from 'Aroon' indicator lines.
var highestValue = Aroon.GetValue(0, 0);
var lowestValue = Aroon.GetValue(0, 1);
// Set values to the 'AroonTest' buffers ('Highest' and 'Lowest' lines).
SetValue(highestValue, 0, 0);
SetValue(lowestValue, 0, 1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
ATR(Int32, MaMode)
Gets the Average True Range (ATR) indicator.
The ATR measures of market volatility.
Declaration
public Indicator ATR(int period, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of Moving Average. |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System;
namespace Example
{
public class TestATR : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Period", 0, 1, 999, 1, 0)]
public int Period = 20;
// Displays Input Parameter as input field.
[InputParameter("Period of Moving Average (ATR)", 1, 1, 999, 1, 0)]
public int AtrPeriod = 13;
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average (ATR)", 2, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Smoothed", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
private Indicator atr;
private int maxPeriod;
public TestATR()
: base()
{
// Defines indicator's name and description.
Name = "TestATR";
Description = "Example of using built-in ATR indicator";
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "My indicator ("+ Period + ":" + AtrPeriod + ":" + MAType.ToString() + ")";
// Get ATR indicator from built-in indicator collection.
atr = Core.Instance.IndicatorManager.BuiltIn.ATR(AtrPeriod, MAType);
maxPeriod = Math.Max(Period, AtrPeriod);
// Add auxiliary ATR indicator to the current one.
AddIndicator(atr);
}
public override void OnUpdate(UpdateArgs args)
{
// Launch calculation every NewBar only.
if (args.Reason != UpdateReason.NewBar)
return;
// Skip max period.
if (Count <= maxPeriod)
return;
// Get the highest and lowest values of ATR on the interval.
var highestATR = GetHighestATR(0, Period);
var lowestATR = GetLowestATR(0, Period);
// Show alert window with usefull information.
Alert($"The highest ATR value on the interval is : {highestATR}\n" +
$"The lowest ATR value on the interval is : {lowestATR}");
}
private double GetHighestATR(int startOffset, int count)
{
// Find the highest value of ATR indicator on the specific interval.
int maxValueOffset = startOffset;
for (int i = 0; i < count; i++)
{
if (atr.GetValue(maxValueOffset) < atr.GetValue(startOffset + i))
maxValueOffset = startOffset + i;
}
return maxValueOffset;
}
private double GetLowestATR(int startOffset, int count)
{
// Find the lowest value of ATR indicator on the specific interval.
int minValueOffset = startOffset;
for (int i = 0; i < count; i++)
{
if (atr.GetValue(minValueOffset) > atr.GetValue(startOffset + i))
minValueOffset = startOffset + i;
}
return minValueOffset;
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
BB(Int32, Double, PriceType, MaMode)
Gets the BB(Bollinger Bands) indicator.
The 'BB' indicator provides a relative definition of high and low based on standard deviation and a simple moving average.
Declaration
public Indicator BB(int period, double coefficient, PriceType priceType, MaMode maMode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of MA for envelopes. |
System.Double | coefficient | Value of confidence interval. |
PriceType | priceType | Sources prices for MA. |
MaMode | maMode | Type of moving average. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestBB : Indicator
{
//Defines 'Period' input parameters as input field and set allowable range from 1 to 999
[InputParameter("Period of MA for envelopes", 0, 1, 999)]
public int Period = 5;
//Defines 'Period' input parameters as input field and set allowable range from 0.1 to 100.0, increment of 0.1
[InputParameter("Value of confidence interval", 1, 0.1, 100.0, 0.1, 1)]
public double D = 1.0;
//Defines input parameters as dropdown lists
[InputParameter("Sources prices for MA", 2, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrices = PriceType.Low;
[InputParameter("Type of moving average", 3, new object[]{
"Simple Moving Average", MaMode.SMA,
"Exponential Moving Average", MaMode.EMA,
"Smoothed Moving Average", MaMode.SMMA,
"Linearly Weighted Moving Average", MaMode.LWMA,
})]
public MaMode MaType = MaMode.SMA;
private Indicator bb;
public TestBB()
: base()
{
// Defines indicator's name and description.
Name = "TestBB";
Description = "Example of using built-in BB indicator";
// Defines line on demand with particular parameters.
AddLineSeries("Diff", Color.Red, 5, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestBB (" + Period + ":" + D + ":" + SourcePrices.ToString() + ":" + MaType.ToString() + ")";
// Get BB indicator from built-in indicator collection.
bb = HistoricalData.BuiltIn.BB(Period, D, SourcePrices, MaType);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get BB values from zero ("Upper Band") and second ("Lower Band") lines.
var upperBand = bb.GetValue(0, 0);
var lowerBand = bb.GetValue(0, 2);
// Get close price
var closePrice = Close();
// Calculates a difference between current close price and specific 'BB' line value.
var diff = 0d;
if (upperBand < closePrice && lowerBand < closePrice)
diff = closePrice - upperBand;
else if (upperBand > closePrice && lowerBand > closePrice)
diff = closePrice - lowerBand;
// Set value to 'Diff' line buffer.
SetValue(diff, 0, 0);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
BBF(Int32, Double, PriceType, MaMode)
Returns an instance of the Bollinger Bands Flat (BBF) indicator.
The BBF provides the same data as BB, but drawn in separate field and easier to recognize whether price is in or out of the band.
Declaration
public Indicator BBF(int period, double deviation, PriceType priceType, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period |
System.Double | deviation | Deviation |
PriceType | priceType | Sources prices for MA |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Bollinger Bands Flat example.
/// </summary>
public class BBF : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period", 0, 1, 999, 1, 0)]
public int Period = 9;
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 2, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Deviation", 3, 0.01, 3, 0.01, 2)]
public double Deviation = 1.5;
// Holds BBF's values.
private Indicator bbf;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public BBF()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Bollinger Bands Flat";
Description = "Bollinger Bands Flat example";
// Defines line on demand with particular parameters.
AddLineSeries("+SD", Color.Red, 1, LineStyle.SimpleChart);
AddLineSeries("-SD", Color.Red, 1, LineStyle.SimpleChart);
AddLineSeries("BBF'Line", Color.FromArgb(0, 51, 252), 1, LineStyle.SimpleChart);
AddLineLevel(0, "0'Line", Color.Aqua, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "BBF (" + Period.ToString() + ")";
// Creates an instance of the proper indicator (BBF) from the default indicators list.
bbf = Core.Instance.IndicatorManager.BuiltIn.BBF(Period, Deviation, SourcePrice, MAType);
// Adds an auxiliary (BBF) indicator to the current one (BBF Example).
// This will let inner indicator (BBF) to be calculated in advance to the current one (BBF Example).
AddIndicator(bbf);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets relevant values for displaying on the chart.
for (int i = 0; i < bbf.LinesSeries.Length; i++)
{
SetValue(bbf.GetValue(0,i),0,i);
}
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
CCI(Int32, PriceType, MaMode)
Gets the Commodity Channel Index.
Measures the position of price in relation to its moving average.
Declaration
public Indicator CCI(int maPeriod, PriceType priceType, MaMode maMode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maPeriod | Period for CCI MA |
PriceType | priceType | Sources prices for CCI |
MaMode | maMode | MA mode for CCI |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Indicators
{
public class TestCCI : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("CCI Period", 0, 1, 999, 1, 0)]
public int Period = 14;
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 0, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Typical;
#endregion Parameters
private Indicator CCI;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestCCI()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestCCI";
Description = "Example of using built-in CCI indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("CCI Line", Color.Red, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
ShortName = "TestCCI ("+Period.ToString()+")";
// Get 'CCI' indicator from built-in indicator collection.
CCI = Core.Instance.IndicatorManager.BuiltIn.CCI(Period, SourcePrice, MAType);
AddIndicator(CCI);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count<= Period)
return;
// Get values from 'CCI' indicator lines.
var cciRecent = CCI.GetValue();
if(args.Reason != UpdateReason.NewTick&& cciRecent>100 && cciRecent<150)
Print("Long signal");
else if(args.Reason != UpdateReason.NewTick&& cciRecent<-100 &&cciRecent>-150)
Print("Short signal");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Channel(Int32)
Gets the Channel (Price Channel) indicator.
The 'Channel' indicator is based on measurement of min and max prices for the definite number of periods.
Declaration
public Indicator Channel(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of price channel |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestChannel : Indicator
{
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Period of MA for envelopes", 0, 1, 999, 1, 0)]
public int Period = 5;
private Indicator channel;
public TestChannel()
: base()
{
// Defines indicator's name and description.
Name = "TestChannel";
Description = "Example of using built-in Channel indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Highest", Color.Red, 2, LineStyle.SimpleChart);
AddLineSeries("Lowest", Color.CadetBlue, 2, LineStyle.SimpleChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestChannel (" + Period + ")";
// Get 'Channel' indicator from built-in indicator collection.
channel = HistoricalData.BuiltIn.Channel(Period);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get values from 'Channel' indicator lines.
var highestValue = channel.GetValue(0, 0);
var lowestValue = channel.GetValue(0, 1);
// Set values to the 'TestChannel' buffers ('Highest' and 'Lowest' lines).
SetValue(highestValue, 0, 0);
SetValue(lowestValue, 0, 1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
CMO(Int32, PriceType)
Gets the CMO (Chande Momentum Oscillator) indicator.
The CMO calculates the dividing of difference between the sum of all recent gains and the sum of all recent losses by the sum of all price movement over the period.
Declaration
public Indicator CMO(int period, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of MA for envelopes. |
PriceType | priceType | Sources prices for MA. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestCMO : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Period of MA for envelopes", 0, 1, 999, 1, 0)]
public int Period = 8;
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
private Indicator cmo;
private LineLevel upLevel;
private LineLevel downLevel;
public TestCMO()
: base()
{
// Defines indicator's name and description.
Name = "Test CMO";
Description = "Example of using built-in CMO indicator";
}
public override void Init()
{
/// Serves for an identification of related indicators with different parameters.
ShortName = "TestCMO (" + Period + ":" + SourcePrice + ")";
// Get 'CMO' indicator from built-in indicator collection.
cmo = HistoricalData.BuiltIn.CMO(Period, SourcePrice);
// Get 'CMO' levels, if indicator was created.
if (cmo != null)
{
upLevel = cmo.LinesLevels[0];
downLevel = cmo.LinesLevels[1];
}
}
public override void OnUpdate(UpdateArgs args)
{
// Call the calculation below, only on HistoricalBar of NewBar.
if (args.Reason == UpdateReason.NewTick)
return;
// Check if we got 'CMO' levels.
if (upLevel == null && downLevel == null)
return;
// Get current 'CMO' value.
var cmoValue = cmo.GetValue();
// Show an alert window with some info.
if (cmoValue > upLevel.Level)
Alert($"{Name}. The CMO value is higher than {upLevel.Name} level.");
else if (cmoValue < downLevel.Level)
Alert($"{Name}. The CMO value is lower than {downLevel.Name} level.");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
DMI(Int32, MaMode)
Gets the Directional Movement Index(DMI) indicator.
The DMI іdentifies whether there is a definable trend in the market.
Declaration
public Indicator DMI(int period, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of Moving Average. |
MaMode | mode | Type of Moving Average. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestDMI : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Period of DMI", 0, 1, 999, 1, 0)]
public int Period = 13;
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
private Indicator dmi;
public TestDMI()
: base()
{
// Defines indicator's name and description.
Name = "Test DMI";
Description = "Example of using built-in DMI indicator";
Group = "Test";
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestDMI (" + Period + ":" + MAType.ToString() + ")";
// Get DMI and two MA indicators from built-in indicator collection.
dmi = Core.Instance.IndicatorManager.BuiltIn.DMI(Period, MAType);
// Add auxiliary DMI indicator to the current one.
AddIndicator(dmi);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip all historical bar and start calculation only when a NewBar comes.
if (args.Reason == UpdateReason.HistoricalBar || args.Reason == UpdateReason.NewTick)
return;
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get "Plus" and "Minus" line values from the DMI indicator.
double plus = dmi.GetValue(0, 0);
double minus = dmi.GetValue(0, 1);
string upperLineName = string.Empty;
// Get the name of upper line.
if (plus > minus)
upperLineName = dmi.LinesSeries[0].Name;
else if (plus < minus)
upperLineName = dmi.LinesSeries[1].Name;
// Show the alert window with some info.
Alert("At this moment, the upper line is : " + upperLineName);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
EMA(Int32, PriceType)
Returns an instance of the Exponential Moving Average (EMA) indicator.
EMA provides a weighted price calculation for the last N periods.
Declaration
public Indicator EMA(int maPeriod, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maPeriod | Period of Exponential Moving Average |
PriceType | priceType | Sources prices for MA |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
///<summary>
///Exponential moving average example.
///</summary>
public class EMA : Indicator
{
#region Parameters
// Period of moving average.
[InputParameter("Period of Exponential Moving Average", 0, 1, 999, 1, 0)]
public int Period = 2;
// Price type of moving average.
[InputParameter("Sources prices for MA", 1, new object[]
{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
// Holds EMA's smoothing values.
private Indicator ema;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public EMA()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "EMA";
Description = "Exponential moving average example";
// Defines line on demand with particular parameters.
AddLineSeries("EMA", Color.DodgerBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "EMA (" + Period.ToString() + ": " + SourcePrice.ToString() + ")";
// Creates an instance of the proper indicator (EMA) from the default indicators list.
ema = Core.Instance.IndicatorManager.BuiltIn.EMA(Period, SourcePrice);
// Adds an auxiliary (EMA) indicator to the current one (EMA Example).
// This will let inner indicator (EMA) to be calculated in advance to the current one (EMA Example).
AddIndicator(ema);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip if count is smaller than period value.
if (Count <= Period)
return;
// Sets value for displaying on the chart.
SetValue(ema.GetValue());
}
}
}
HV(Int32, Int32, PriceType, HVSheduleMode)
Declaration
public Indicator HV(int stdPeriod, int volatilityPeriod, PriceType priceType, HVSheduleMode hvMode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | stdPeriod | |
System.Int32 | volatilityPeriod | |
PriceType | priceType | |
TradingPlatform.BusinessLayer.HVSheduleMode | hvMode |
Returns
Type | Description |
---|---|
Indicator |
HV(Int32, Int32, PriceType, HVSheduleMode, Int32)
Declaration
public Indicator HV(int stdPeriod, int volatilityPeriod, PriceType priceType, HVSheduleMode hvMode, int percentilePeriod)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | stdPeriod | |
System.Int32 | volatilityPeriod | |
PriceType | priceType | |
TradingPlatform.BusinessLayer.HVSheduleMode | hvMode | |
System.Int32 | percentilePeriod |
Returns
Type | Description |
---|---|
Indicator |
ICH(Int32, Int32, Int32)
Gets the Ichimoku.
Enables to quickly discern and filter 'at a glance' the low-probability trading setups from those of higher probability.
Declaration
public Indicator ICH(int TenkanPeriod, int KijunPeriod, int SenkouSpanB)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | TenkanPeriod | Tenkan Period |
System.Int32 | KijunPeriod | Kijun Period |
System.Int32 | SenkouSpanB | Senkou Span B |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestICH : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Tenkan Sen", 0, 1, 999, 1, 0)]
public int TenkanPeriod = 9;
[InputParameter("Kijun Sen", 1, 1, 999, 1, 0)]
public int KijunPeriod = 26;
[InputParameter("Senkou Span B", 2, 1, 999, 1, 0)]
public int SenkouSpanB = 52;
#endregion Parameters
private Indicator ICH;
/// <summary>
///Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestICH()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestICH";
Description = "Example of using built-in Ichimoku indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Tenkan Sen", Color.Green, 1, LineStyle.SimpleChart);
AddLineSeries("Kijun Sen", Color.LightSkyBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "TestICH :Tenkan" + TenkanPeriod.ToString() + " vs Kijun" + KijunPeriod.ToString();
// Get 'ICH' indicator from built-in indicator collection.
ICH = Core.Instance.IndicatorManager.BuiltIn.ICH(TenkanPeriod, KijunPeriod, SenkouSpanB);
AddIndicator(ICH);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Get values from 'ICH' indicator lines.
var Tenkan = ICH.GetValue();
var Kijun = ICH.GetValue(0,1);
SetValue(Tenkan);
SetValue(Kijun, 0,1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
KAMA(Int32, Double, Double, Double, Double, PriceType, AMATrendType)
Returns an instance of the Kaufman Adaptive Moving Average (KAMA) indicator.
KAMA is an exponential style average with a smoothing that varies according to recent data.
Declaration
public Indicator KAMA(int period, double fast, double slow, double G, double dK, PriceType priceType, AMATrendType trendType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period |
System.Double | fast | Fast factor |
System.Double | slow | Slow factor |
System.Double | G | G coefficient |
System.Double | dK | dK coefficient |
PriceType | priceType | Sources prices for MA |
TradingPlatform.BusinessLayer.AMATrendType | trendType | AMA Trend Type |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Kaufman Adaptive Moving Average example.
/// </summary>
public class KAMA : Indicator
{
#region Parameters
// Defines initial parameters.
[InputParameter("Period", 0, 1, 9999)]
public int periodAMA = 10;
[InputParameter("#Fast", 1, 1, 500, 1)]
public double nfast = 2.0;
[InputParameter("#Slow", 2, 1, 500, 1)]
public double nslow = 30.0;
[InputParameter("G", 3, 1, 10, 0.1)]
public double G = 2.0;
[InputParameter("dK", 4, 1, 10, 0.1)]
public double dK = 2.0;
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 5, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
// Displays Input Parameter as dropdown list.
[InputParameter("AMA Trend Type", 6, new object[] {
"Fixed", AMATrendType.Fixed,
"Average", AMATrendType.Average }
)]
public AMATrendType AMA_Trend_Type;
#endregion
// Holds KAMA's values.
private Indicator kama;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public KAMA()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Kaufman Adaptive Moving Average example";
Description = "Kaufman Adaptive Moving Average example";
// Defines line on demand with particular parameters.
AddLineSeries("KAMA'Line", Color.Gray, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "KAMA (" + periodAMA.ToString() + ": " + nfast.ToString() + ": " + nslow.ToString() + ": " + G.ToString() + ": " + dK.ToString() + ")";
// Creates an instance of the proper indicator (KAMA) from the default indicators list.
kama = Core.Instance.IndicatorManager.BuiltIn.KAMA(periodAMA,nfast, nslow, G, dK, SourcePrice, AMA_Trend_Type);
// Adds an auxiliary (KAMA) indicator to the current one (KAMA Example).
// This will let inner indicator (KAMA) to be calculated in advance to the current one (KAMA Example).
AddIndicator(kama);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(kama.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Keltner(Int32, Double, PriceType, MaMode)
Returns an instance of the Keltner Channel indicator.
Keltner Channels are volatility-based envelopes set above and below an exponential moving average.
Declaration
public Indicator Keltner(int period, double offset, PriceType priceType, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of MA for Keltner's Channel |
System.Double | offset | Coefficient of channel's width |
PriceType | priceType | Sources prices for MA |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Keltner example.
/// </summary>
public class Keltner : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Sources prices for MA", 0, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
// Displays Input Parameter as dropdown list.
[InputParameter("Period of MA for Keltner's Channel", 2, 1, 9999, 1)]
public int Period = 5;
// Displays Input Parameter as dropdown list.
[InputParameter("Coefficient of channel's width", 3, 1, 100)]
public double Offset = 2;
#endregion
// Holds Keltner's values.
private Indicator keltner;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public Keltner()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Keltner example";
Description = "Keltner example";
// Defines line on demand with particular parameters.
AddLineSeries("MA'Line", Color.Coral, 1, LineStyle.SimpleChart);
AddLineSeries("+ATR'Line", Color.Red, 1, LineStyle.SimpleChart);
AddLineSeries("-ATR'Line", Color.Purple, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "Keltner (" + Period.ToString() + ": " + Offset.ToString() + ": " + SourcePrice.ToString() + ": " + MAType.ToString() + ")";
// Creates an instance of the proper indicator (Keltner) from the default indicators list.
keltner = Core.Instance.IndicatorManager.BuiltIn.Keltner(Period, Offset, SourcePrice, MAType);
// Adds an auxiliary (Keltner) indicator to the current one (Keltner Example).
// This will let inner indicator (Keltner) to be calculated in advance to the current one (Keltner Example).
AddIndicator(keltner);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets values for the displaying on the chart.
for (int i = 0; i < keltner.LinesSeries.Length; i++)
{
SetValue(keltner.GetValue(0,i),0,i);
}
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
KRI(Int32)
Returns an instance of the Kairi Relative Index (KRI) indicator.
KRI calculates deviation of the current price from its simple moving average as a percent of the moving average.
Declaration
public Indicator KRI(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Kairi Relative Index example.
/// </summary>
public class KRI : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period", 2, 1, 999, 1, 0)]
public int Period = 20;
// Holds KRI's values.
private Indicator kri;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public KRI()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Kairi Relative Index";
Description = "Kairi Relative Index example";
// Defines line on demand with particular parameters.
AddLineSeries("SD'Line", Color.Blue, 1, LineStyle.SimpleChart);
AddLineLevel(0, "0'Line", Color.Gray, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "KRI (" + Period.ToString() + ")";
// Creates an instance of the proper indicator (KRI) from the default indicators list.
kri = Core.Instance.IndicatorManager.BuiltIn.KRI(Period);
// Adds an auxiliary (KRI) indicator to the current one (KRI Example).
// This will let inner indicator (KRI) to be calculated in advance to the current one (KRI Example).
AddIndicator(kri);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(kri.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
LWMA(Int32, PriceType)
Gets the Linearly Weighted Moving Average
Linear Weighted Moving Average makes the most recent bar more important unlike SMA.
Declaration
public Indicator LWMA(int maPeriod, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maPeriod | Moving average period |
PriceType | priceType | Type of the price |
Returns
Type | Description |
---|---|
Indicator |
Examples
using System;
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
public class TestLWMA : Indicator
{
#region Input params
Indicator slowLWMA, fastLWMA;
#endregion
// Input Parameter with an input field or checkbox (if bolean)
[InputParameter("Period slow LWMA", 0, 1, 9999)]
public int slowPeriod = 12;
[InputParameter("Period fast LWMA", 0, 1, 9999)]
public int fastPeriod = 8;
// Input Parameter with a dropdown
[InputParameter("Sources prices for calculation LWMA", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestLWMA()
: base()
{
// Defines indicator's name and description.
Name = "LWMA test";
Description = "Example of using built-in LWMA indicator";
// Defines line on demand with particular parameters.
AddLineSeries("TestLWMA", Color.Blue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
/// </summary>
public override void Init()
{
ShortName = "LWMA ("+slowPeriod.ToString()+":"+fastPeriod.ToString()+")";
// Creation of an indicator with long period
slowLWMA = Core.Instance.IndicatorManager.BuiltIn.LWMA(slowPeriod, SourcePrice);
AddIndicator(slowLWMA);
// Creation of an indicator with short period
fastLWMA = Core.Instance.IndicatorManager.BuiltIn.LWMA(fastPeriod, SourcePrice);
AddIndicator(fastLWMA);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
if (Count > Math.Max(slowPeriod, fastPeriod))
SetValue((slowLWMA.GetValue() + fastLWMA.GetValue()) / 2);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MA(Int32, PriceType, MaMode)
Gets the specific MA indicator, according to selected 'MaMode'.
Declaration
public Indicator MA(int period, PriceType priceType, MaMode maMode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of moving average. |
PriceType | priceType | Type of price. |
MaMode | maMode | MA mode. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestMA : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Period of Moving Average", 0, 1, 999, 1, 0)]
public int Period = 10;
// Displays Input Parameter as dropdown list.
[InputParameter("MA mode", 1, new object[]{
"Simple Moving Average", MaMode.SMA,
"Exponential Moving Average", MaMode.EMA,
"Smoothed Moving Average", MaMode.SMMA,
"Linearly Weighted Moving Average", MaMode.LWMA,
})]
public MaMode MaType = MaMode.SMA;
[InputParameter("Sources prices for MA", 2, new object[]{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
private Indicator testMa;
private Indicator sma;
public TestMA()
: base()
{
// Defines indicator's name and description.
Name = "TestMA";
Description = "Test of built-in MA method";
// Defines one line with particular parameters.
AddLineSeries("MA", Color.Green, 2, LineStyle.SimpleChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TMA (" + Period + ":" + SourcePrice.ToString() + ":" + MaType.ToString() + ")";
// Get MA indicator from built-in indicator collection (according to selected 'MaType').
testMa = HistoricalData.BuiltIn.MA(Period, SourcePrice, MaType);
// Get SMA indicator from built-in indicator collection.
sma = HistoricalData.BuiltIn.SMA(Period, SourcePrice);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Print name of 'testMa' indicator and its value
// + name of 'sma' indicator (it's always "SMA") and its value
// + 'true' if their values are equal or 'false' if it isn't.
Print($"{testMa.Name}: {testMa.GetValue()}. \n" +
$"{sma.Name}: {sma.GetValue()}. \n" +
$"Indicator values are equal: {testMa.GetValue() == sma.GetValue()}.");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MACD(Int32, Int32, Int32)
Gets the MACD (Moving Average Convergence/Divergence) indicator.
The MACD is a trend-following momentum indicator that shows the relationship between two moving averages of prices.
Declaration
public Indicator MACD(int fastEMA, int slowEMA, int signalEMA)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fastEMA | Period of fast EMA. |
System.Int32 | slowEMA | Period of slow EMA. |
System.Int32 | signalEMA | Period of signal EMA. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Linq;
namespace Example
{
public class TestMACD : Indicator
{
// Display input parameters as input fields.
[InputParameter("Period of fast EMA", 0, 1, 999, 1, 0)]
public int FastPeriod = 12;
[InputParameter("Period of slow EMA", 1, 1, 999, 1, 0)]
public int SlowPeriod = 26;
[InputParameter("Period of signal EMA", 2, 1, 999, 1, 0)]
public int SignalPeriod = 9;
private int maxPeriod;
private Indicator macd;
public TestMACD()
: base()
{
// Defines indicator's name and description.
Name = "Test MACD";
Description = "Example of using built-in MACD indicator";
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestMACD (" + FastPeriod + ":" + SlowPeriod + ":" + SignalPeriod + ")";
// Find the max period.
maxPeriod = Enumerable.Max(new int[] { FastPeriod, SlowPeriod, SignalPeriod });
// Get MACD indicator from built-in indicator collection and add it to the current one as auxiliary.
macd = Core.Instance.IndicatorManager.BuiltIn.MACD(FastPeriod, SlowPeriod, SignalPeriod);
AddIndicator(macd);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip the history. Start calculation only on real-time data (newBar/newTick).
if (args.Reason == UpdateReason.HistoricalBar)
return;
// Get the current and previoud signal line values of MACD indicator (1 line index).
var currSignal = macd.GetValue(0, 1);
var prevSignal = macd.GetValue(1, 1);
// Show an alert window with some info.
if (prevSignal < 0d && currSignal > 0d)
Alert("The 'Signal' line crosses of zero line from bottom to top.");
else if (prevSignal > 0d && currSignal < 0d)
Alert("The 'Signal' line crosses of zero line from top to bottom.");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MAE(Int32, PriceType, MaMode, Double, Double)
Gets the MAE (Moving Average Envelope) indicator.
The 'MAE' indicator demonstrates a range of the prices discrepancy from a Moving Average.
Declaration
public Indicator MAE(int period, PriceType priceType, MaMode maMode, double upShift, double downShift)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of MA for envelopes. |
PriceType | priceType | Sources prices for MA. |
MaMode | maMode | Type of moving average. |
System.Double | upShift | Upband deviation in %. |
System.Double | downShift | Downband deviation in %. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestMAE : Indicator
{
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Period of MA for envelopes", 0, 1, 999, 1, 0)]
public int Period = 5;
// Defines the 'SourcePrice' parameter as dropdown list
[InputParameter("Sources prices for MA", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Low;
// Defines the 'MaType' parameter as dropdown list
[InputParameter("Type of moving average", 2, new object[]{
"Simple Moving Average", MaMode.SMA,
"Exponential Moving Average", MaMode.EMA,
"Smoothed Moving Average", MaMode.SMMA,
"Linearly Weighted Moving Average", MaMode.LWMA,
})]
public MaMode MaType = MaMode.SMA;
// Defines the 'UpShift' parameter as input field (where 'min' is 0.1, 'max' is 1.0 and 'increment' is 0.1).
[InputParameter("Upband deviation in %", 3, 0.1, 1.0, 0.1, 1)]
public double UpShift = 0.1;
// Defines the 'DownShift' parameter as input field (where 'min' is 0.1, 'max' is 1.0 and 'increment' is 0.1).
[InputParameter("Downband deviation in %", 4, 0.1, 1.0, 0.1, 1)]
public double DownShift = 0.1;
private Indicator mae;
public TestMAE()
: base()
{
// Defines indicator's name and description.
Name = "TestMAE";
Description = "Example of using built-in MAE indicator";
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestMAE (" + Period + ":" + UpShift + ":" + DownShift + ")";
// Get MAE indicator from built-in indicator collection.
mae = HistoricalData.BuiltIn.MAE(Period, SourcePrice, MaType, UpShift, DownShift);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip the history. Start calculation only on real-time data (newBar/newTick).
if (args.Reason == UpdateReason.HistoricalBar)
return;
// Get current close price (0 offset by default)
var closePrice = Close();
// Show the alert window with some info.
if (closePrice > mae.GetValue(0, 0))
Alert($"The current close price is higher than 'Upper Band' line of MAE indicator");
else if (closePrice < mae.GetValue(0, 1))
Alert($"The current close price is lower than 'Lower Band' line of MAE indicator");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MAS3(Int32, Int32, Int32, Int32)
Gets the MAS3 (3MASignal) indicator.
The 'MAS3' indicator offers buy and sell signals according to intersections of three moving averages.
Declaration
public Indicator MAS3(int shortPeriod, int middlePeriod, int longPeriod, int barsInterval)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | shortPeriod | Short moving average period. |
System.Int32 | middlePeriod | Middle moving average period. |
System.Int32 | longPeriod | Long moving average period. |
System.Int32 | barsInterval | The count of bars. The trend will be determined on this interval. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestMAS3 : Indicator
{
//Defines input parameters as input fields
[InputParameter("Short Moving Average Period", 0, 1, 999, 1, 0)]
public int ShortMaPeriod = 5;
[InputParameter("Middle Moving Average Period", 1, 1, 999, 1, 0)]
public int MiddleMaPeriod = 10;
[InputParameter("Long Moving Average Period", 2, 1, 999, 1, 0)]
public int LongMaPeriod = 25;
[InputParameter("Amount of bars passed before opening position", 3, 1, 999, 1, 0)]
public int BarsInterval = 1;
private Indicator mas;
private double trend = 0d;
public TestMAS3()
: base()
{
// Defines indicator's name and description.
Name = "TestMAS3";
Description = "Example of using MAS3 indicator";
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestMAS3 (" + ShortMaPeriod + ":" + MiddleMaPeriod + ":" + LongMaPeriod + ":" + BarsInterval + ")";
// Get MAS3 indicator from built-in indicator collection.
mas = Core.Instance.IndicatorManager.BuiltIn.MAS3(ShortMaPeriod, MiddleMaPeriod, LongMaPeriod, BarsInterval);
// Add auxiliary indicators to the current.
AddIndicator(mas);
}
public override void OnUpdate(UpdateArgs args)
{
//Skip the history. Start calculation only on the real time data.
if (args.Reason == UpdateReason.HistoricalBar)
return;
// Get MAS3 value of current bar (0 offset by default)
var currentTrend = mas.GetValue();
// The service method, which according to the 'currentTrend' value returns the trend name (as string)
var trendName = GetTrendNameHelper(currentTrend);
// Show the alert window, with the info about current market trend
if (currentTrend != trend)
Alert($"The market trend was changed. Current trend is: '{ trendName }'");
trend = currentTrend;
}
private string GetTrendNameHelper(double trend)
{
if (trend > 0d)
return "Up";
else if (trend < 0d)
return "Down";
else
return "None";
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MD(Int32, Int32, PriceType)
Returns an instance of the McGinley Dynamic indicator.
McGinley Dynamic avoids of most whipsaws and it rapidly moves up or down according to a quickly changing market. It needs no adjusting because it is dynamic and it adjusts itself.
Declaration
public Indicator MD(int period, int trackingFactor, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of exponential moving average |
System.Int32 | trackingFactor | Dynamic tracking factor |
PriceType | priceType | Source price type |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// McGinley Dynamic example.
/// </summary>
public class MD : Indicator
{
#region Parameters
// Period of McGinley Dynamic.
[InputParameter("Period", 0, 1, 999, 1, 0)]
public int Period = 2;
// Smoothing of McGinley Dynamic.
[InputParameter("Smoothing", 1, 1, 999, 1, 0)]
public int Smoothing = 2;
// Price type of McGinley Dynamic.
[InputParameter("Source price", 2, new object[]
{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
// Holds MD's smoothing values.
private Indicator md;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public MD()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "MD";
Description = "McGinley Dynamic example";
// Defines line on demand with particular parameters.
AddLineSeries("MD", Color.DodgerBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "MD (" + Period.ToString() + ": " + Smoothing.ToString() + ": " + SourcePrice.ToString() + ")";
// Creates an instance of the proper indicator from the default indicators list.
md = Core.Instance.IndicatorManager.BuiltIn.MD(Period, Smoothing, SourcePrice);
// Adds an auxiliary (MD) indicator to the current one (MD).
// This will let inner indicator (MD) to be calculated in advance to the current one (MD).
AddIndicator(md);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip if count is smaller than period value.
if (Count <= Period)
return;
// Sets value for displaying on the chart.
SetValue(md.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MFI(Int32)
Gets the MFI(Money Flow Index) indicator.
The MFI(Money Flow Index) is an oscillator that uses both price and volume to measure buying and selling pressure.
Declaration
public Indicator MFI(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of MFI. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestMFI : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("MFI Period", 0, 1, 999, 1, 0)]
public int Period = 14;
private Indicator mfi;
private LineLevel upLevel;
private LineLevel downLevel;
public TestMFI()
: base()
{
// Serves for an identification of related indicators.
Name = "Test MFI";
Description = "Example of using built-in MFI indicator";
// Defines line on demand with particular parameters.
AddLineSeries("MFI", Color.Orange, 5, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestMFI (" + Period + ")";
// Get MFI indicator from built-in indicator collection
mfi = Core.Instance.IndicatorManager.BuiltIn.MFI(Period);
// Get an instance of level lines from MFI indicator.
upLevel = mfi.LinesLevels[0];
downLevel = mfi.LinesLevels[1];
// Attach the 'MFI' indicator to the current 'TestMFI'.
AddIndicator(mfi);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Start the calculation only on HistoricalBar or NewBar.
if (args.Reason == UpdateReason.NewTick)
return;
// Get current and previous values of MFI indicator.
var currMFI = mfi.GetValue(0);
var prevMFI = mfi.GetValue(1);
// Assign 0 to a signal variable by default .
var signal = 0;
// Change the signal value if the crossing of 'ROC' indicator with zero level was happened.
if (currMFI > upLevel.Level && prevMFI < upLevel.Level)
signal = 1;
else if (currMFI < downLevel.Level && prevMFI > downLevel.Level)
signal = -1;
// Set signal value to a 'Signal' line buffer.
SetValue(signal);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
MMA(Int32, PriceType)
Returns an instance of the Modified Moving Average (MMA) indicator.
MMA comprises a sloping factor to help it overtake with the growing or declining value of the trading price of the currency.
Declaration
public Indicator MMA(int maPeriod, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maPeriod | Period of Modified Moving Average |
PriceType | priceType | Sources prices for MA |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Modified Moving Average example.
/// </summary>
public class MMA : Indicator
{
#region Parameters
// Period of moving average.
[InputParameter("Period of Modified Moving Average", 0, 1, 999, 1, 0)]
public int Period = 2;
// Price type of moving average.
[InputParameter("Sources prices for MA", 1, new object[]
{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
// Holds MMA's smoothing values.
private Indicator mma;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public MMA()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "MMA";
Description = "Modified Moving Average example";
// Defines line on demand with particular parameters.
AddLineSeries("MMA", Color.DodgerBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "MMA (" + Period.ToString() + ": "+ SourcePrice.ToString() + ")";
// Creates an instance of the proper indicator (MMA) from the default indicators list.
mma = Core.Instance.IndicatorManager.BuiltIn.MMA(Period, SourcePrice);
// Adds an auxiliary (MMA) indicator to the current one (MMA Example).
// This will let inner indicator (MMA) to be calculated in advance to the current one (MMA Example).
AddIndicator(mma);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip if count is smaller than period value.
if (Count <= Period)
return;
// Sets value for displaying on the chart.
SetValue(mma.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Momentum(Int32, PriceType)
Gets the Momentum indicator.
Momentum compares where the current price is in relation to where the price was in the past.
Declaration
public Indicator Momentum(int period, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period for Momentum |
PriceType | priceType | Sources prices for Momentum |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestMomentum : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Momentum Period", 0, 1, 999, 1, 0)]
public int Period = 20;
#endregion Parameters
private Indicator Momentum;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestMomentum()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestMomentum";
Description = "Example of using built-in Momentum indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Signal", Color.DodgerBlue, 5, LineStyle.HistogrammChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "Momentum ("+Period.ToString()+")";
// Get 'Momentum' indicator from built-in indicator collection.
Momentum = Core.Instance.IndicatorManager.BuiltIn.Momentum(Period,PriceType.Close);
AddIndicator(Momentum);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count<= Period)
return;
// Get values from 'Momentum' indicator lines.
var MomentumNew = Momentum.GetValue();
if(MomentumNew>0)
Print("Upward movement");
else
Print("Downward movement");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
OBV(PriceType)
Gets On Balance Volume.
On Balance Volume (OBV) measures buying and selling pressure as a cumulative indicator that adds volume on up days and subtracts volume on down days.
Declaration
public Indicator OBV(PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
PriceType | priceType | Sources prices for OBV |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestOBV : Indicator
{
#region Paramaters
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for OBV", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
#endregion Parameters
private Indicator OBV;
public TestOBV()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestOBV";
Description = "Example of using built-in OBV indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries();
}
public override void Init()
{
ShortName = "OBV ("+SourcePrice.ToString()+")";
// Get 'OBV' indicator from built-in indicator collection.
OBV = Core.Instance.IndicatorManager.BuiltIn.OBV(SourcePrice);
AddIndicator(OBV);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= 1)
return;
// Get values from 'OBV' indicator lines.
var OBVNew = OBV.GetValue();
SetValue(OBVNew);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
OsMA(Int32, Int32, Int32)
Gets the OsMA (Moving Average of Oscillator) indicator.
The OsMA reflects the difference between an oscillator (MACD) and its moving average (signal line).
Declaration
public Indicator OsMA(int fastEMA, int slowEMA, int signalEMA)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fastEMA | Period of fast EMA. |
System.Int32 | slowEMA | Period of slow EMA. |
System.Int32 | signalEMA | Period of signal EMA. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
using System.Linq;
namespace Example
{
public class TestOsMA : Indicator
{
// Display input parameters as input fields.
[InputParameter("Period of fast EMA", 0, 1, 999, 1, 0)]
public int FastPeriod = 12;
[InputParameter("Period of slow EMA", 1, 1, 999, 1, 0)]
public int SlowPeriod = 26;
[InputParameter("Period of signal EMA", 2, 1, 999, 1, 0)]
public int SignalPeriod = 9;
private int maxPeriod;
private Indicator osma;
public TestOsMA()
: base()
{
// Defines indicator's name and description.
Name = "Test OsMA";
Description = "Example of using built-in OsMA indicator";
// Defines line on demand with particular parameters.
AddLineSeries("OsMA", Color.Orange, 4, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestOsMA (" + FastPeriod + ":" + SlowPeriod + ":" + SignalPeriod + ")";
// Find the max period.
maxPeriod = Enumerable.Max(new int[] { FastPeriod, SlowPeriod, SignalPeriod });
// Get OsMA indicator from built-in indicator collection and add it to the current one as auxiliary.
osma = Core.Instance.IndicatorManager.BuiltIn.OsMA(FastPeriod, SlowPeriod, SignalPeriod);
AddIndicator(osma);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip max period for correct calculation.
if (Count <= maxPeriod)
return;
// Get value from OsMA indicator.
var value = osma.GetValue(0, 0);
// Set value to the 'OsMA' line buffer.
SetValue(value);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
PO(Int32, Int32, PriceType, MaMode)
Returns an instance of the Price Oscillator (PO) indicator.
PO calculates the variation between price moving averages.
Declaration
public Indicator PO(int period1, int period2, PriceType priceType, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period1 | Period of MA1 |
System.Int32 | period2 | Period of MA2 |
PriceType | priceType | Sources prices for MA |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Price Oscillator example.
/// </summary>
public class PO : Indicator
{
#region Parameters
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average", 0, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
[InputParameter("Sources prices for MA", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period of MA1", 2)]
public int MAPeriod1 = 2;
[InputParameter("Period of MA2", 3)]
public int MAPeriod2 = 25;
// Holds PO's values.
private Indicator po;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public PO()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Price Oscillator";
Description = "Price Oscillator example";
// Defines line on demand with particular parameters.
AddLineSeries("PO'Line", Color.Blue, 1, LineStyle.SimpleChart);
AddLineLevel(0, "0'Line", Color.Gray, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "PO (" + MAPeriod1.ToString() + ": " + MAPeriod2.ToString() + ": " + SourcePrice.ToString() + ": " + MAType.ToString() + ")";
// Creates an instance of the proper indicator (PO) from the default indicators list.
po = Core.Instance.IndicatorManager.BuiltIn.PO(MAPeriod1, MAPeriod2, SourcePrice, MAType);
// Adds an auxiliary (PO) indicator to the current one (PO Example).
// This will let inner indicator (PO) to be calculated in advance to the current one (PO Example).
AddIndicator(po);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(po.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
PPMA(Int32)
Gets the PPMA(Pivot Point Moving Average) indicator.
The 'PPMA' indicator uses the pivot point calculation as the input a simple moving average.
Declaration
public Indicator PPMA(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of PPMA indicator |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
namespace Example
{
public class TestPPMA : Indicator
{
//Defines input parameter as input field
[InputParameter("Period of TestPPMA", 0, 1, 999, 1, 0)]
public int Period = 2;
private Indicator ppma;
private Indicator ema;
public TestPPMA()
: base()
{
// Defines indicator's name and description.
Name = "TestPPMA";
Description = "Example of using PPMA indicator";
// This example doesn't require indicator lines
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TPPMA (" + Period + ")";
// Create PPMA and EMA indicators from built-in indicator collection
ppma = Core.Instance.IndicatorManager.BuiltIn.PPMA(Period);
ema = Core.Instance.IndicatorManager.BuiltIn.EMA(Period, PriceType.Close);
// Add auxiliary indicators to the current.
AddIndicator(ppma);
AddIndicator(ema);
}
public override void OnUpdate(UpdateArgs args)
{
//Skip the history. Start calculation only on the real time data.
if (args.Reason == UpdateReason.HistoricalBar)
return;
// Get EMA and PPMA values of previous bar (1 offset) from first line (line index is 0)
var prevEma = ema.GetValue(1);
var prevPPMA = ppma.GetValue(1, 1);
// Get EMA and PPMA values of current bar (0 offset) form second line (line index is 1)
var currentPPMA = ppma.GetValue(0, 1);
var currentEma = ema.GetValue(0);
// Show the alert window with some info
if (prevEma < prevPPMA && currentEma > currentPPMA)
Alert("The ema crossed ppma from bottom to top");
else if (prevEma > prevPPMA && currentEma < currentPPMA)
Alert("The ema crossed ppma from top to bottom");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
PPO(Int32, Int32, Int32)
Returns an instance of the Percentage Price Oscillator (PPO).
Percentage Price Oscillator is a momentum indicator. Signal line is EMA of PPO. Formula: (FastEMA-SlowEMA)/SlowEMA.
Declaration
public Indicator PPO(int fastPeriod, int slowPeriod, int signalPeriod)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fastPeriod | Fast EMA Period |
System.Int32 | slowPeriod | Slow EMA Period |
System.Int32 | signalPeriod | Signal EMA Period |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// PPO example.
/// </summary>
public class PPO : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Fast EMA Period", 0)]
public int fastEmaPeriod = 12;
[InputParameter("Slow EMA Period", 1)]
public int slowEmaPeriod = 26;
[InputParameter("Signal EMA Period", 2)]
public int signalEmaPeriod = 9;
#endregion
// Holds PPO's values.
private Indicator ppo;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public PPO()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "PPO example";
Description = "PPO example";
// Defines line on demand with particular parameters.
AddLineSeries("PPO'Line", Color.SkyBlue, 2, LineStyle.SimpleChart);
AddLineSeries("Signal'Line", Color.Red, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "PPO (" + fastEmaPeriod.ToString() + ": " + slowEmaPeriod.ToString() + ": " + signalEmaPeriod.ToString() + ")";
// Creates an instance of the proper indicator (PPO) from the default indicators list.
ppo = Core.Instance.IndicatorManager.BuiltIn.PPO(fastEmaPeriod, slowEmaPeriod, signalEmaPeriod);
// Adds an auxiliary (PPO) indicator to the current one (PPO Example).
// This will let inner indicator (PPO) to be calculated in advance to the current one (PPO Example).
AddIndicator(ppo);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets values for the displaying on the chart.
for (int i = 0; i < ppo.LinesSeries.Length; i++)
{
SetValue(ppo.GetValue(0,i),0,i);
}
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
PVI(PriceType)
Returns an instance of the Positive Volume Index (PVI) indicator.
The PVI value changes on the periods in which value of volume has increased in comparison with the previous period.
Declaration
public Indicator PVI(PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
PriceType | priceType |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Positive Volume Index example.
/// </summary>
public class PVI : Indicator
{
#region Parameters
// Displays Input Parameter as dropdown list.
[InputParameter("Source price", 0, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
#endregion
// Holds PVI's values.
private Indicator pvi;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public PVI()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Positive Volume Index";
Description = "Positive Volume Index example";
// Defines line on demand with particular parameters.
AddLineSeries("PVI'Line", Color.Blue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "PVI (" + SourcePrice.ToString() + ")";
// Creates an instance of the proper indicator (PVI) from the default indicators list.
pvi = Core.Instance.IndicatorManager.BuiltIn.PVI(SourcePrice);
// Adds an auxiliary (PVI) indicator to the current one (PVI Example).
// This will let inner indicator (PVI) to be calculated in advance to the current one (PVI Example).
AddIndicator(pvi);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(pvi.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Qstick(Int32, MaMode)
Returns an instance of the Qstick indicator.
The Qstick is a moving average that shows the difference between the prices at which an issue opens and closes.
Declaration
public Indicator Qstick(int period, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | |
MaMode | mode |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Qstick example.
/// </summary>
public class Qstick : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period", 0, 1, 999, 0, 0)]
public int Period = 20;
// Displays Input Parameter as dropdown list.
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
#endregion
// Holds Qstick's values.
private Indicator qstick;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public Qstick()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Qstick example";
Description = "Qstick example";
// Defines line on demand with particular parameters.
AddLineSeries("Qstick'Line", Color.Gray, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "Qstick (" + Period.ToString() + ": " + MAType.ToString() + ")";
// Creates an instance of the proper indicator (Qstick) from the default indicators list.
qstick = Core.Instance.IndicatorManager.BuiltIn.Qstick(Period, MAType);
// Adds an auxiliary (Qstick) indicator to the current one (Qstick Example).
// This will let inner indicator (Qstick) to be calculated in advance to the current one (Qstick Example).
AddIndicator(qstick);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(qstick.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Regression(Int32, PriceType)
Gets the Regression indicator
The Linear Regression Indicator plots the ending value of a Linear Regression Line for a specified number of bars; showing, statistically, where the price is expected to be.
Declaration
public Indicator Regression(int period, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Moving average period |
PriceType | priceType | Type of the price |
Returns
Type | Description |
---|---|
Indicator |
Examples
using System;
using TradingPlatform.BusinessLayer;
namespace Indicators
{
public class TestRegression : Indicator
{
#region Input params
Indicator slowRL, fastRL;
///<summary>
///Input Parameter with an input field or checkbox (if bolean)
///</summary>
[InputParameter("Period slow", 0, 1, 9999)]
public int Rlslow = 12;
[InputParameter("Period fast", 2, 1, 9999)]
public int Rlfast = 8;
/// <summary>
/// Input Parameter with a dropdown
/// </summary>
[InputParameter("Sources prices for calculation", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestRegression()
: base()
{
Name = "Regression test";
Description = "Example of using built-in Regression indicator";
AddLineSeries();
}
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public override void Init()
{
ShortName = "TestRegression ("+Rlslow.ToString()+":"+Rlfast.ToString()+")";
// Creation of an indicator with long period
slowRL = Core.Instance.IndicatorManager.BuiltIn.Regression(Rlslow, SourcePrice);
AddIndicator(slowRL);
// Creation of an indicator with short period
fastRL = Core.Instance.IndicatorManager.BuiltIn.Regression(Rlfast, SourcePrice);
AddIndicator(fastRL);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
if (Count <= Math.Max(Rlslow, Rlfast))
return;
if (fastRL.GetValue()<slowRL.GetValue())
Alert("Downgoing");
else if (fastRL.GetValue()>slowRL.GetValue())
Alert("Upgoing");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
RLW(Int32)
Gets the %R Larry Williams.
Uses Stochastic to determine overbought and oversold levels.
Declaration
public Indicator RLW(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period for Momentum |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestRLW : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("RLW Period", 0, 1, 999, 1, 0)]
public int Period = 20;
#endregion Parameters
private Indicator RLW;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestRLW()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestRLW";
Description = "Example of using built-in RLW indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries();
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "RLW ("+Period.ToString()+")";
// Get 'RLW' indicator from built-in indicator collection.
RLW = Core.Instance.IndicatorManager.BuiltIn.RLW(Period);
AddIndicator(RLW);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count<= Period)
return;
// Get values from 'RLWNew' indicator lines.
var RLWNew = RLW.GetValue();
if(args.Reason != UpdateReason.NewTick && RLWNew>70)
Print("Upward movement");
else if(args.Reason != UpdateReason.NewTick && RLWNew <20)
Print("Downward movement");
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
ROC(Int32)
Gets the ROC (Rate of Change) indicator.
The ROC shows the speed at which price is changing.
Declaration
public Indicator ROC(int period)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of momentum. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestROC : Indicator
{
// Displays 'Period' input parameter as input field.
[InputParameter("Period of momentum", 0, 1, 999, 1, 0)]
public int Period = 20;
private Indicator roc;
private LineLevel zeroLevel;
public TestROC()
: base()
{
// Serves for an identification of related indicators.
Name = "Test ROC";
Description = "Example of using built-in ROC indicator";
// Defines line on demand with particular parameters.
AddLineSeries("Signal", Color.DodgerBlue, 5, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestROC (" + Period + ")";
// Get ROC indicator from built-in indicator collection
roc = Core.Instance.IndicatorManager.BuiltIn.ROC(Period);
// Get an instance of level line from ROC indicator.
zeroLevel = roc.LinesLevels[0];
// Attach the 'ROC' indicator to the current 'TestROC'.
AddIndicator(roc);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Start the calculation only on HistoricalBar or NewBar.
if (args.Reason == UpdateReason.NewTick)
return;
// Get current and previous values of ROC indicator.
var currROC = roc.GetValue(0);
var prevROC = roc.GetValue(1);
// Assign 0 to a signal variable by default .
var signal = 0;
// Change the signal value if the crossing of 'ROC' indicator with zero level was happened.
if (currROC > zeroLevel.Level && prevROC < zeroLevel.Level)
signal = 1;
else if (currROC < zeroLevel.Level && prevROC > zeroLevel.Level)
signal = -1;
// Set signal value to a 'Signal' line buffer.
SetValue(signal);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
RSI(Int32, PriceType, RSIMode, MaMode, Int32)
Gets the RSI indicator.
Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements.
Declaration
public Indicator RSI(int period, PriceType priceType, RSIMode rsiMode, MaMode maMode, int maperiod)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | RSI Period |
PriceType | priceType | Price Type |
TradingPlatform.BusinessLayer.RSIMode | rsiMode | RSI Mode (Simple or Exponential) |
MaMode | maMode | |
System.Int32 | maperiod |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class SmoothRSI : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("RSI Period", 0, 1, 999, 1, 0)]
public int Period = 14;
[InputParameter("EMA Period", 0, 1, 999, 1, 0)]
public int emaPeriod = 10;
#endregion Parameters
// Default will be performed on Close prices
[InputParameter("Sources prices for the RSI line", 1, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
// Default will be performed on Simple mode
[InputParameter("Mode for the RSI line", 2, new object[] {
"Simple", RSIMode.Simple,
"Exponential", RSIMode.Exponential}
)]
public RSIMode SourceRSI = RSIMode.Exponential;
private Indicator RSI;
public SmoothRSI()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "RSItest";
Description = "Example of using built-in RSI indicator";
AddLineSeries("Smooth RSI line", Color.CadetBlue, 2, LineStyle.SimpleChart);
}
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public override void Init()
{
ShortName = "Smooth RSI ("+emaPeriod.ToString()+")";
// Get 'RSI' indicator from built-in indicator collection.
RSI = Core.Instance.IndicatorManager.BuiltIn.RSI(Period, SourcePrice, SourceRSI);
AddIndicator(RSI);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>.
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get MA values from 'RSI' indicator lines.
var rsiValue = RSI.GetValue(0, 1);
// Set values to the 'SmoothRSI' buffers.
SetValue(rsiValue);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
SAR(Double, Double)
Returns an instance of the Parabolic Time/Price System (SAR) indicator.
SAR indicator helps to define the direction of the prevailing trend and the moment to close positions opened during the reversal.
Declaration
public Indicator SAR(double step, double maximum)
Parameters
Type | Name | Description |
---|---|---|
System.Double | step | Step of parabolic SAR system |
System.Double | maximum | Maximum value for the acceleration factor |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Parabolic Time/Price System example.
/// </summary>
public class SAR : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Step of parabolic SAR system", 0, 2)]
public double Step = 0.02;
[InputParameter("Maximum value for the acceleration factor", 1, 1)]
public double Maximum = 0.2;
// Holds SAR's smoothing values.
private Indicator sar;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public SAR()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "SAR";
Description = "Parabolic Time/Price System example";
// Defines line on demand with particular parameters.
AddLineSeries("SAR", Color.Firebrick, 4, LineStyle.DotChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "SAR (" + Step.ToString() + ": " + Maximum.ToString() + ")";
// Creates an instance of the proper indicator (SAR) from the default indicators list.
sar = Core.Instance.IndicatorManager.BuiltIn.SAR(Step, Maximum);
// Adds an auxiliary (SAR) indicator to the current one (SAR Example).
// This will let inner indicator (SAR) to be calculated in advance to the current one (SAR Example).
AddIndicator(sar);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(sar.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
SD(Int32, PriceType, MaMode)
Returns an instance of the Standart Deviation (SD) indicator.
The SD shows the difference of the volatility value from the average one.
Declaration
public Indicator SD(int period, PriceType priceType, MaMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of indicator |
PriceType | priceType | Sources prices for MA |
MaMode | mode | Type of Moving Average |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Standard Deviation example.
/// </summary>
public class SD : Indicator
{
#region Parameters
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 0, new object[] {
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Medium", PriceType.Median,
"Weighted", PriceType.Weighted}
)]
public PriceType SourcePrice = PriceType.Close;
[InputParameter("Type of Moving Average", 1, new object[] {
"Simple", MaMode.SMA,
"Exponential", MaMode.EMA,
"Modified", MaMode.SMMA,
"Linear Weighted", MaMode.LWMA}
)]
public MaMode MAType = MaMode.SMA;
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Period", 2, 1, 999, 1, 0)]
public int Period = 20;
// Holds SD's smoothing values.
private Indicator sd;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public SD()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Standard Deviation";
Description = "Standard Deviation example";
// Defines line on demand with particular parameters.
AddLineSeries("SD'Line", Color.Blue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "SD (" + Period.ToString() + ": " + SourcePrice.ToString() + ": " + MAType.ToString() + ")";
// Creates an instance of the proper indicator (SD) from the default indicators list.
sd = Core.Instance.IndicatorManager.BuiltIn.SD(Period, SourcePrice, MAType);
// Adds an auxiliary (SD) indicator to the current one (SD Example).
// This will let inner indicator (SD) to be calculated in advance to the current one (SD Example).
AddIndicator(sd);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(sd.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
SI(Double)
Get the Swing Index (SI) indicator.
The SI is used to confirm trend line breakouts on price charts.
Declaration
public Indicator SI(double divider)
Parameters
Type | Name | Description |
---|---|---|
System.Double | divider | The divider. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestSI : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Divider", 0, 0.1, 9999.0, 0.1, 1)]
public double Divider = 300.0;
[InputParameter("The interval for calculation of percentile", 1, 1, 999, 1, 0)]
public int PercInterval = 100;
private Indicator si;
public TestSI()
: base()
{
// Defines indicator's name and description.
Name = "Test SI";
Description = "Example of using built-in SI indicator";
// Defines line on demand with particular parameters.
AddLineSeries("Percentile", Color.HotPink, 1, LineStyle.SimpleChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = $"TestSI (" + Divider + ":"+ PercInterval +")";
// Get SI indicator from built-in indicator collection.
si = Core.Instance.IndicatorManager.BuiltIn.SI(Divider);
// Add auxiliary SI indicator to the current one.
AddIndicator(si);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= PercInterval)
return;
// Get a current SI value.
double siValue = si.GetValue();
// Calculate a percentile of current SI value.
var percentile = CalculatePercentile(0, PercInterval, siValue);
// Set value to "Percentile" line buffer.
SetValue(percentile, 0, 0);
}
private double CalculatePercentile(int startOffset, int inteval, double value)
{
// Calculate the count of all SI values,
// which are equal or less than the current SI value on an interval.
double count = 0d;
if (inteval <= 0)
return 0d;
for (int i = startOffset; i < inteval; i++)
{
if (si.GetValue(i) <= value)
count = count + 1.0;
}
return count / inteval * 100d;
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
SMA(Int32, PriceType)
Gets the SMA(Simple Moving Average) indicator.
The 'SMA' indicator provides an average price for the last N periods.
Declaration
public Indicator SMA(int period, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period of simple moving average. |
PriceType | priceType | Sources prices for MA. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestSMA : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("Period of Simple Moving Average", 0, 1, 999, 1, 0)]
public int Period = 2;
// Displays Input Parameter as dropdown list.
[InputParameter("Sources prices for MA", 1, new object[]
{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
private Indicator sma;
public TestSMA()
: base()
{
Name = "TestSMA";
Description = "Example of using SMA indicator";
// Define one line with particular parameters.
AddLineSeries("Signal", Color.Green, 5, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serve for identification of related indicators with different parameters.
ShortName = "TestMA (" + Period + ":" + SourcePrice.ToString() + ")";
// Get SMA indicator from built-in indicator collection
sma = Core.Instance.IndicatorManager.BuiltIn.SMA(Period, SourcePrice);
// Add auxiliary SMA indicator to the current.
AddIndicator(sma);
}
public override void OnUpdate(UpdateArgs args)
{
// Checking, if current amount of bars
// more, than period of moving average. If it is
// then the calculation is possible
if (Count <= Period)
return;
// Get SMA values for current and previos bars
var currentSmaValue = sma.GetValue(0);
var previousSmaValue = sma.GetValue(1);
// Set value to the "Signal" line buffer
if (previousSmaValue < currentSmaValue)
SetValue(1);
else if (previousSmaValue > currentSmaValue)
SetValue(-1);
else
SetValue(0);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
SMMA(Int32, PriceType)
Returns an instance of the Smoothed Moving Average (SMMA) indicator.
SMMA indicator provides a smoothed average price for the last N periods.
Declaration
public Indicator SMMA(int period, PriceType priceType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Moving average period |
PriceType | priceType | Type of the price |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Smoothed Moving Average example.
/// </summary>
public class SMMA : Indicator
{
#region Parameters
// Period of moving average.
[InputParameter("Period of Smoothed Moving Average", 0, 1, 999, 1, 0)]
public int Period = 12;
// Price type of moving average.
[InputParameter("Sources prices for MA", 1, new object[]
{
"Close", PriceType.Close,
"Open", PriceType.Open,
"High", PriceType.High,
"Low", PriceType.Low,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
})]
public PriceType SourcePrice = PriceType.Close;
// Holds SMMA's smoothing values.
Indicator smma;
#endregion
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public SMMA()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "SMMA";
Description = "Smoothed moving average example";
// Defines line on demand with particular parameters.
AddLineSeries("SMMA", Color.DodgerBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "SMMA (" + MaPeriod.ToString() + ": " + SourcePrice.ToString() + ")";
// Creates an instance of the proper indicator (SMMA) from the default indicators list.
smma = Core.Instance.IndicatorManager.BuiltIn.SMMA(Period, SourcePrice);
// Adds an auxiliary (SMMA) indicator to the current one (SMMA Example).
// This will let inner indicator (SMMA) to be calculated in advance to the current one (SMMA Example).
AddIndicator(smma);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip if count is smaller than period value.
if (Count <= Period)
return;
// Sets value for displaying on the chart.
SetValue(smma.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Stochastic(Int32, Int32, Int32, MaMode)
Gets the Stochastic Slow.
Shows the location of the current close relative to the high/low range over a set number of periods (Slow).
Declaration
public Indicator Stochastic(int period, int smooth, int doubleSmooth, MaMode MaType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | period | Period |
System.Int32 | smooth | Smoothing |
System.Int32 | doubleSmooth | Double smoothing |
MaMode | MaType | Moving type |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestStochastic : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Stochastic Period", 0, 1, 999, 1, 0)]
public int Period = 20;
[InputParameter("Smooth Period", 0, 1, 999, 1, 0)]
public int Smooth = 3;
[InputParameter("DoubleSmooth Period", 0, 1, 999, 1, 0)]
public int DoubleSmooth = 6;
#endregion Parameters
private Indicator Stoch;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestStochastic()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestStochastic";
Description = "Example of using built-in Stochastic indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Stochastic", Color.Green, 1, LineStyle.SimpleChart);
AddLineSeries("Stochastic Smoothed", Color.LightSkyBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "TestStochastic " + Period.ToString();
// Get 'Stochastic' indicator from built-in indicator collection.
Stoch = Core.Instance.IndicatorManager.BuiltIn.Stochastic(Period, Smooth, DoubleSmooth, MaMode.LWMA);
AddIndicator(Stoch);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get values from 'Stoch' indicator lines.
var StochNew = Stoch.GetValue();
var StochNewMA = Stoch.GetValue(0,1);
SetValue(StochNew);
SetValue(StochNewMA,0,1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
StochasticxRSI(Int32, Int32, Int32)
Gets the Stochastic x Relative Strength Index.
StochRSI is an oscillator that measures the level of RSI relative to its range.
Declaration
public Indicator StochasticxRSI(int rsiPeriod, int kPeriod, int dPeriod)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rsiPeriod | Period |
System.Int32 | kPeriod | Smoothing |
System.Int32 | dPeriod | Double smoothing |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestStochRSI : Indicator
{
#region Paramaters
// Defines the 'Period' parameter as input field (where 'min' is 1 and 'max' is 999).
[InputParameter("Stochastic Period", 0, 1, 999, 1, 0)]
public int Period = 20;
[InputParameter("Smooth Period", 0, 1, 999, 1, 0)]
public int Smooth = 3;
[InputParameter("DoubleSmooth Period", 0, 1, 999, 1, 0)]
public int DoubleSmooth = 6;
#endregion Parameters
private Indicator StochRSI;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public TestStochRSI()
: base()
{
// Serves for an identification of related indicators with different parameters.
Name = "TestStochasticxRSI";
Description = "Example of using built-in Stochastic x Relative Strength Index indicator";
// Define two lines (on main window) with particular parameters
AddLineSeries("Stochastic", Color.Green, 1, LineStyle.SimpleChart);
AddLineSeries("Stochastic Smoothed", Color.LightSkyBlue, 1, LineStyle.SimpleChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) update
/// </summary>
public override void Init()
{
ShortName = "StochasticxRSI"+ "("+Period+")";
// Get 'StochasticxRSI' indicator from built-in indicator collection.
StochRSI = Core.Instance.IndicatorManager.BuiltIn.StochasticxRSI(Period, Smooth, DoubleSmooth);
AddIndicator(StochRSI);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= Period)
return;
// Get values from 'StochasticxRSI' indicator lines.
var StochNew = StochRSI.GetValue();
var StochNewMA = StochRSI.GetValue(0,1);
SetValue(StochNew);
SetValue(StochNewMA,0,1);
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
TSI(Int32, Int32)
Get the True Strength Index (TSI) indicator.
The TSI is a variation of the Relative Strength Indicator which uses a doubly-smoothed EMA of price momentum to eliminate choppy price changes and spot trend changes.
Declaration
public Indicator TSI(int firstPeriod, int secondPeriod)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | firstPeriod | First MA period. |
System.Int32 | secondPeriod | Second MA period. |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace Example
{
public class TestTSI : Indicator
{
// Displays Input Parameter as input field.
[InputParameter("First MA period", 0, 1, 999, 1, 0)]
public int FirstPeriod = 5;
// Displays Input Parameter as input field.
[InputParameter("Second MA period", 1, 1, 999, 1, 0)]
public int SecondPeriod = 8;
[InputParameter("The interval for calculation of percentile", 2, 1, 999, 1, 0)]
public int PercInterval = 100;
private Indicator tsi;
public TestTSI()
: base()
{
// Defines indicator's name and description.
Name = "Test TSI";
Description = "Example of using built-in TSI indicator";
// Defines line on demand with particular parameters.
AddLineSeries("Percentile", Color.Orange, 1, LineStyle.HistogrammChart);
}
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "TestTSI (" + FirstPeriod + ":" + SecondPeriod + ":" + PercInterval + ")";
// Get TSI indicator from built-in indicator collection.
tsi = Core.Instance.IndicatorManager.BuiltIn.TSI(FirstPeriod, SecondPeriod);
// Add auxiliary TSI indicator to the current one.
AddIndicator(tsi);
}
public override void OnUpdate(UpdateArgs args)
{
// Skip some period for correct calculation.
if (Count <= PercInterval)
return;
// Get a current TSI value.
double tsiValue = tsi.GetValue();
// Calculate a percentile of current TSI value.
var percentile = CalculatePercentile(0, PercInterval, tsiValue);
// Set value to "Percentile" line buffer.
SetValue(percentile, 0, 0);
}
private double CalculatePercentile(int startOffset, int inteval, double value)
{
// Calculate the count of all TSI values,
// which are equal or less than the current TSI value on an interval.
double count = 0d;
if (inteval <= 0)
return 0d;
for (int i = startOffset; i < inteval; i++)
{
if (tsi.GetValue(i) <= value)
count = count + 1.0;
}
return count / inteval * 100d;
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Volume()
Returns an instance of the Volume indicator.
Volume allows to confirm the strength of a trend or to suggest about it's weakness.
Declaration
public Indicator Volume()
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
/// <summary>
/// Volume example.
/// </summary>
public class Volume : Indicator
{
// Holds Volume's values.
private Indicator volume;
/// <summary>
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
/// </summary>
public Volume()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "Volume";
Description = "Volume example";
// Defines line on demand with particular parameters.
AddLineSeries("Volume'Line", Color.Gray, 1, LineStyle.HistogrammChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "Volume";
// Creates an instance of the proper indicator (Volume) from the default indicators list.
volume = Core.Instance.IndicatorManager.BuiltIn.Volume();
// Adds an auxiliary (Volume) indicator to the current one (Volume Example).
// This will let inner indicator (Volume) to be calculated in advance to the current one (Volume Example).
AddIndicator(volume);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(volume.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
ZZ(Double)
Returns an instance of the ZigZag indicator.
ZigZag is a trend following indicator that is used to predict when a given symbol's momentum is reversing.
Declaration
public Indicator ZZ(double deviation)
Parameters
Type | Name | Description |
---|---|---|
System.Double | deviation | Percent Deviation |
Returns
Type | Description |
---|---|
Indicator |
Examples
using TradingPlatform.BusinessLayer;
using System.Drawing;
namespace IndicatorExample
{
///
/// ZigZag example.
///
public class ZZ : Indicator
{
#region Parameters
// Displays Input Parameter as input field (or checkbox if value type is bolean).
[InputParameter("Percent Deviation", 0, 0.01, 1.5, 0.01, 2)]
public double deviation = 1;
// Holds ZigZag's smoothing values.
private Indicator zz;
#endregion
///
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
///
public ZZ()
: base()
{
// Defines indicator's group, name and description.
Group = "Custom";
Name = "ZigZag";
Description = "ZigZag example";
// Defines line on demand with particular parameters.
AddLineSeries("ZZ'Line", Color.DarkOrange, 2, LineStyle.DotChart);
}
/// <summary>
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbolor timeframe) updates.
/// </summary>
public override void Init()
{
// Serves for an identification of related indicators with different parameters.
ShortName = "ZZ (" + deviation.ToString() + ")";
// Creates an instance of the proper indicator (ZZ) from the default indicators list.
zz = Core.Instance.IndicatorManager.BuiltIn.ZZ(deviation);
// Adds an auxiliary (ZZ) indicator to the current one (ZZ Example).
// This will let inner indicator (ZZ) to be calculated in advance to the current one (ZZ Example).
AddIndicator(zz);
}
/// <summary>
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// </summary>
/// <param name="args">Provides data of updating reason and incoming price.</param>
public override void OnUpdate(UpdateArgs args)
{
// Sets value for displaying on the chart.
SetValue(zz.GetValue());
}
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |