How to use new watchlist API
26 Jun 2019, 15:52
Hello,
I already know that you can use watchlists like this :
foreach (var watchlist in Watchlists)
{
Print(watchlist.Name);
foreach (var symbolname in watchlist.SymbolNames)
{
Print(symbolname);
}
}
But I want to understand what is Watchlists (it's not a list nor an array) and how can you use it without a foreach.
In the reference it says you can use this property to get the watchlist at the index :
https://ctrader.com/api/reference/watchlists/item
But it doesn't work, how to use that ?
How can you loop through Watchlists with a standard for loop ?
Thanks,
Best regards
Replies
PanagiotisCharalampous
26 Jun 2019, 16:34
Hi,
Here is an example
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.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
Print(Watchlists[0].SymbolNames[0]);
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
a.fernandez.martinez
26 Jun 2019, 19:43
Thanks, how to get the number of Watchlists ?
Watchlists.Count or .Length don't work.
@a.fernandez.martinez
PanagiotisCharalampous
27 Jun 2019, 09:38
Hi a.fernandez.martinez,
Works fine for me
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.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
Print(Watchlists.Count());
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous

a.fernandez.martinez
26 Jun 2019, 16:13
I tried this and it doesn't work :
IEnumerable<Watchlist> test = new List<Watchlist>(Watchlists); for (int i = 0; i < test.Count(); i++) { Print(test.ElementAt(i)); }@a.fernandez.martinez