using cAlgo.API;
<span="k">using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
// このサンプルcBotは、ティックボリュームインジケーターの使用方法を示します
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TickVolumeSample : Robot
{
private double _volumeInUnits;
private TickVolume _tickVolume;
[Parameter("Volume (Lots)", DefaultValue = 0.01, Group = "Trade")]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 10, Group = "Trade")]
public double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 10, Group = "Trade")]
public double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "Sample", Group = "Trade")]
public string Label { get; set; }
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label<span="p">);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots<span="p">);
_tickVolume = Indicators.TickVolume<span="p">();
}
protected override void OnBar()
{
if (Bars.Last(1).ClosePrice > Bars.Last(<span="m">2).ClosePrice<span="p">)
{
ClosePositions(TradeType<span="p">.Sell);
if (_tickVolume.Result.Last(<span="m">1) > _tickVolume.Result.Last(<span="m">2))
ExecuteMarketOrder(TradeType<span="p">.Buy, SymbolName<span="p">, _volumeInUnits, Label<span="p">, StopLossInPips<span="p">, TakeProfitInPips<span="p">);
}
else if (Bars<span="p">.Last(1<span="p">).ClosePrice < Bars<span="p">.Last(2<span="p">).ClosePrice<span="p">)
{
ClosePositions<span="p">(TradeType<span="p">.Buy);
if (_tickVolume.Result<span="p">.Last<span="p">(1<span="p">) > _tickVolume.Result<span="p">.<span="n">Last<span="p">(2<span="p">))
ExecuteMarketOrder<span="p">(<span="n">TradeType<span="p">.<span="n">Sell<span="p">, <span="n">SymbolName<span="p">, <span="n">_volumeInUnits<span="p">, <span="n">Label<span="p">, <span="n">StopLossInPips<span="p">, <span="n">TakeProfitInPips<span="p">);
}
}
private void ClosePositions<span="p">(TradeType tradeType<span="p">)
{
foreach (var position in BotPositions<span="p">)
{
if (position<span="p">.TradeType != tradeType<span="p">) continue<span="p">;
ClosePosition<span="p">(position<span="p">);
<span="p">}
<span="p">}
<span="p">}
<span="p">}