negrium
negrium's avatar

Info

Username:negrium
Name:negrium
Member since: 30 Jan 2020

About

None

Signature

None
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
Brenno
  2
  0
  131
paid  05 May 2023
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);                 }             }         }     } }