有谁知道如何计算自进入以来的周期数?
Does anybody know how to count number of periods since entry?
如何计算开仓后的周期数?我是否应该从当前位置开始向后计算开盘价低于前一根的蜡烛?预先感谢您的帮助。
protected override void OnStart()
{
var MyPositions = Positions.FindAll(MyLabel, Symbol);
foreach (var position in MyPositions){
... ???
}
}
您可以使用内置方法获取柱索引Bars.OpenTimes.GetIndexByTime
var position = Positions[0];
var barIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);
if (barIndex == -1)
{
Print("No bars in history with opening time before the position was opened");
}
else
{
var barsSinceEntry = Bars.Count - 1 - barIndex;
Print("Position was opened {0} bar(s) ago", barsSinceEntry);
}
你是指开仓后经过的柱数吗?
如果那是你的意思,你可以使用开仓时间和 Bars.OpenTimes.GetIndexByTime 来找到开仓时的柱线索引,之后你可以使用当前柱线索引减去开仓柱线索引来获得总数通过的柱数:
using cAlgo.API;
using System;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PositionBarsPassed : Robot
{
[Parameter("Label", DefaultValue = "MyBot")]
public string Label { get; set; }
protected override void OnStart()
{
var currentIndex = Bars.Count - 1;
foreach (var position in Positions)
{
if (!string.Equals(position.Label, Label, StringComparison.OrdinalIgnoreCase)) continue;
var positionOpenBarIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);
var numberOfBarsPassedSincePositionOpened = currentIndex - positionOpenBarIndex;
Print(numberOfBarsPassedSincePositionOpened);
}
}
}
}
如何计算开仓后的周期数?我是否应该从当前位置开始向后计算开盘价低于前一根的蜡烛?预先感谢您的帮助。
protected override void OnStart()
{
var MyPositions = Positions.FindAll(MyLabel, Symbol);
foreach (var position in MyPositions){
... ???
}
}
您可以使用内置方法获取柱索引Bars.OpenTimes.GetIndexByTime
var position = Positions[0];
var barIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);
if (barIndex == -1)
{
Print("No bars in history with opening time before the position was opened");
}
else
{
var barsSinceEntry = Bars.Count - 1 - barIndex;
Print("Position was opened {0} bar(s) ago", barsSinceEntry);
}
你是指开仓后经过的柱数吗? 如果那是你的意思,你可以使用开仓时间和 Bars.OpenTimes.GetIndexByTime 来找到开仓时的柱线索引,之后你可以使用当前柱线索引减去开仓柱线索引来获得总数通过的柱数:
using cAlgo.API;
using System;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PositionBarsPassed : Robot
{
[Parameter("Label", DefaultValue = "MyBot")]
public string Label { get; set; }
protected override void OnStart()
{
var currentIndex = Bars.Count - 1;
foreach (var position in Positions)
{
if (!string.Equals(position.Label, Label, StringComparison.OrdinalIgnoreCase)) continue;
var positionOpenBarIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);
var numberOfBarsPassedSincePositionOpened = currentIndex - positionOpenBarIndex;
Print(numberOfBarsPassedSincePositionOpened);
}
}
}
}