Custom indicator parameters question
Custom indicator parameters question
14 Aug 2021, 13:36
Hi all,
I want to use a custom indicator that I found on cTrader.com in a bot. This is the Traders Dynamic Index (TDI.)
I referenced the indicator into the bot successfully, however, I am new to custom indicators and am not sure about the parameters I should be calling for this specific indicator (it has a lot of inner workings).
Here is the cBot source:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class TDISystem : Robot
{
//parameters
private TradersDynamicIndex _TDI;
protected override void OnStart()
{
_TDI = Indicators.GetIndicator<TradersDynamicIndex>(???);
}
protected override void OnBar()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
The three question marks are the bit I am uncertain about.
Here is the indicator source:
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Levels(32, 50, 68)]
[Indicator(AccessRights = AccessRights.None)]
public class TradersDynamicIndex : Indicator
{
private RelativeStrengthIndex _rsi;
private MovingAverage _price;
private MovingAverage _signal;
private BollingerBands _bollingerBands;
[Parameter()]
public DataSeries Source { get; set; }
[Parameter("RSI Period", DefaultValue = 13)]
public int RsiPeriod { get; set; }
[Parameter("Price Period", DefaultValue = 2)]
public int PricePeriod { get; set; }
[Parameter("Signal Period", DefaultValue = 7)]
public int SignalPeriod { get; set; }
[Parameter("Volatility Band", DefaultValue = 34)]
public int Volatility { get; set; }
[Parameter("Standard Deviations", DefaultValue = 2)]
public int StDev { get; set; }
[Parameter("Price MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType PriceMaType { get; set; }
[Parameter("Signal MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType SignalMaType { get; set; }
[Output("Upper Band", LineColor = "Blue")]
public IndicatorDataSeries Up { get; set; }
[Output("Lower Band", LineColor = "Blue")]
public IndicatorDataSeries Down { get; set; }
[Output("Middle Band", LineColor = "Orange", Thickness = 2)]
public IndicatorDataSeries Middle { get; set; }
[Output("Price", LineColor = "Green", Thickness = 2)]
public IndicatorDataSeries PriceSeries { get; set; }
[Output("Signal", LineColor = "Red", Thickness = 2)]
public IndicatorDataSeries SignalSeries { get; set; }
protected override void Initialize()
{
_rsi = Indicators.RelativeStrengthIndex(Source, RsiPeriod);
_bollingerBands = Indicators.BollingerBands(_rsi.Result, Volatility, StDev, MovingAverageType.Simple);
_price = Indicators.MovingAverage(_rsi.Result, PricePeriod, PriceMaType);
_signal = Indicators.MovingAverage(_rsi.Result, SignalPeriod, SignalMaType);
}
public override void Calculate(int index)
{
Up[index] = _bollingerBands.Top[index];
Down[index] = _bollingerBands.Bottom[index];
Middle[index] = _bollingerBands.Main[index];
PriceSeries[index] = _price.Result[index];
SignalSeries[index] = _signal.Result[index];
}
}
}
Any help as to what parameters and in which order would be appreciated, thanks.
Replies
waym77
16 Aug 2021, 16:22
RE:
amusleh said:
Hi,
When you are using a custom indicator on a cBot you must pass a value for all of the indicator parameters, for TDI you can use it like this:
namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class TDISystem : Robot { //parameters private TradersDynamicIndex _TDI; protected override void OnStart() { _TDI = Indicators.GetIndicator<TradersDynamicIndex>(Bars.ClosePrices, 13, 2, 7, 34, 2, MovingAverageType.Simple, MovingAverageType.Simple); } protected override void OnBar() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
The parameters you pass must be in same order that is defined in indicator.
Hi,
This is perfect, thanks!
@waym77
amusleh
16 Aug 2021, 15:36
Hi,
When you are using a custom indicator on a cBot you must pass a value for all of the indicator parameters, for TDI you can use it like this:
The parameters you pass must be in same order that is defined in indicator.
@amusleh