Brenno paid
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SimpleMovingAverageRobot : Robot
{
[Parameter("Periods", DefaultValue = 20)]
public int Periods { get; set; }
private MovingAverage _sma;
protected override void OnStart()
{
_sma = Indicators.SimpleMovingAverage(MarketSeries.Close, Periods);
}
protected override void OnBar()
{
if (Positions.Count == 0)
{
if (_sma.Result.Last(1) < _sma.Result.Last(2))
{
ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "SMA Sell");
}
else if (_sma.Result.Last(1) > _sma.Result.Last(2))
{
ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "SMA Buy");
}
}
else
{
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && _sma.Result.Last(1) > _sma.Result.Last(2))
{
ClosePosition(position);
}
else if (position.TradeType == TradeType.Buy && _sma.Result.Last(1) < _sma.Result.Last(2))
{
ClosePosition(position);
}
}
}
}
}
u s i n g S y s t e m ; u s i n g c A l g o . A P I ; n a m e s p a c e c A l g o . R o b o t s { [ R o b o t ( "