OJ
Topics
24 Jun 2023, 05:31
562
3
14 Feb 2022, 15:02
1055
3
Replies
ojey39
16 Feb 2022, 11:12
RE:
amusleh said:
Hi,
You can use an enum, ex:
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter("Instance Name", DefaultValue = "001")] public string InstanceName { get; set; } [Parameter("Lot Size", DefaultValue = 0.1)] public double LotSize { get; set; } [Parameter("Source SMA #1", DefaultValue = DataSource.Low)] public DataSource SourceSma1 { get; set; } [Parameter("Source SMA #2", DefaultValue = DataSource.High)] public DataSource SourceSma2 { get; set; } [Parameter("Period SMA #1", DefaultValue = 5, MinValue = 1, MaxValue = 100)] public int PeriodsSma1 { get; set; } [Parameter("Period SMA #2", DefaultValue = 20, MinValue = 1, MaxValue = 100)] public int PeriodsSma2 { get; set; } [Parameter("Calculate OnBar", DefaultValue = false)] public bool CalculateOnBar { get; set; } #region Indicator declarations private SimpleMovingAverage _sma1 { get; set; } private SimpleMovingAverage _sma2 { get; set; } #endregion Indicator declarations /// <summary> /// This is called when the robot first starts, it is only called once. /// </summary> protected override void OnStart() { // construct the indicators _sma1 = Indicators.SimpleMovingAverage(GetSeries(SourceSma1), PeriodsSma1); _sma2 = Indicators.SimpleMovingAverage(GetSeries(SourceSma2), PeriodsSma2); } private DataSeries GetSeries(DataSource source) { switch (source) { case DataSource.High: return Bars.HighPrices; case DataSource.Low: return Bars.LowPrices; case DataSource.Close: return Bars.ClosePrices; case DataSource.Open: return Bars.OpenPrices; default: throw new ArgumentOutOfRangeException("source"); } } } public enum DataSource { Open, High, Low, Close } }
Thanks a lot. It works.
@ojey39
ojey39
27 Jun 2023, 12:35
RE:
firemyst said:
Thanks a lot.
@ojey39