using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
// このサンプルcBotは、フラクタルインジケーターの使用方法を示します
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FractalsSample : Robot
{
private double _volumeInUnits;
private Fractals _fractals;
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; <span="k">set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 10)]
public double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 10)]
public double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label<span="p">);
}
}
protected override void OnStart<span="p">()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_fractals = Indicators.Fractals(5);
}
protected override void OnBar<span="p">()
{
if <span="p">(!double.IsNaN(_fractals.DownFractal.Last(1)))
{
ClosePositions(TradeType<span="p">.Sell);
ExecuteMarketOrder(TradeType<span="p">.Buy<span="p">, SymbolName<span="p">, _volumeInUnits<span="p">, Label<span="p">, StopLossInPips<span="p">, TakeProfitInPips);
}
else if (!double.IsNaN(_fractals<span="p">.UpFractal.Last(1)))
{
ClosePositions<span="p">(TradeType<span="p">.Buy<span="p">);
ExecuteMarketOrder<span="p">(TradeType<span="p">.Sell<span="p">, SymbolName<span="p">, _volumeInUnits<span="p">, Label<span="p">, StopLossInPips<span="p">, TakeProfitInPips);
}
}
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(position<span="p">);
}
}
}
}