Access to TimeFrame values
Access to TimeFrame values
11 Nov 2024, 09:50
Hi Spotware,
Is it a method to access to the TimeFrame values? There are too many items to code and I need to find any of them.
It would be great if any similar methods would work as
foreach (var t in TimeFrame)
or the TImeFrame values can be organized as an array or any solution would be great.
Thanks.
Replies
afhacker
12 Nov 2024, 07:09
Hi,
You can achieve it with reflection:
using System.Collections.Generic;
using System.Reflection;
using cAlgo.API;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None)]
public class TimeFramesEnumerableTest : Indicator
{
protected override void Initialize()
{
foreach (var timeFrame in GetTimeFrames())
{
Print(timeFrame);
}
}
public override void Calculate(int index)
{
}
private IEnumerable<TimeFrame> GetTimeFrames()
{
var timeFrameFields = typeof(TimeFrame).GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var timeFrameField in timeFrameFields)
{
if (timeFrameField.FieldType != typeof(TimeFrame))
continue;
yield return (TimeFrame)timeFrameField.GetValue(null);
}
}
}
}
@afhacker
PanagiotisCharalampous
11 Nov 2024, 14:07
Hi there,
This is not possible at the moment but you can suggest it in Suggestions.
Best regards,
Panagiotis
@PanagiotisCharalampous