Expose some types from TimeFrame.
Created at 26 Nov 2024, 16:29
Expose some types from TimeFrame.
26 Nov 2024, 16:29
Currently, in order to get the value of the TimeFrame of the Robot in minutes we do something like that:
public class TimeFrameUtils
{
public static int GetTimeFrameInMinutes(TimeFrame timeFrame)
{
if (timeFrame == TimeFrame.Minute)
return 1;
if (timeFrame == TimeFrame.Minute2)
return 2;
if (timeFrame == TimeFrame.Minute3)
return 3;
if (timeFrame == TimeFrame.Minute4)
return 4;
if (timeFrame == TimeFrame.Minute5)
return 5;
…
}
}
It would be nice if the below fields (internal in the TimeFrame) could be exposed (as public). It would solve various kind of issues and would ensure minimal code.
internal TimeFrameType TimeFrameType { get; }
internal uint Size { get; }
martins
26 Nov 2024, 19:57 ( Updated at: 26 Nov 2024, 20:11 )
Agreed. Would be nice to have an easy way to get a number proportional to the TimeFrame period.
I sometimes use this, but if both of the 1st 2 Bars are non-standard, weekend and a gap in data for instance, then it won't work:
deltaBar = Math.Min(Bars[1].OpenTime.ToOADate() - Bars[0].OpenTime.ToOADate(), Bars[2].OpenTime.ToOADate() - Bars[1].OpenTime.ToOADate()); // TimeFrame as days ( * 1440 for minutes)
Or more definitively, this:
string timeframeChar = Bars.TimeFrame.ShortName.Substring(1, 1);
double timeframeNumber = 0, timeframeDaysOA = 0;
if (timeframeChar == "M") timeframeDaysOA = 20;
else {
try { timeframeNumber = Convert.ToInt32(Bars.TimeFrame.ShortName.Substring(2)); }
catch { timeframeNumber = 0; }
if (timeframeChar == "m") timeframeDaysOA = timeframeNumber / 3600;
else if (timeframeChar == "h") timeframeDaysOA = timeframeNumber / 24;
else if (timeframeChar == "D") timeframeDaysOA = timeframeNumber;
else if (timeframeChar == "W") timeframeDaysOA = timeframeNumber * 5;
}
(probably should have used chars not strings)
@martins