Turn indicator to a cBot
Turn indicator to a cBot
12 Mar 2017, 12:20
Hi,
I'm currently learning C# and would like to know if it's possible to turn a indicator to a cBot by only adding functions to the code itself. These functions would be order open , - close, trailingstop, etc. And ofcourse change the namspace to Robot and add Onstart and void to the code itself.
I'm more than happy to provide you with a code that I've been working on as an example if needed.
Thank you in advance.
Replies
... Deleted by UFO ...
phily1_1
16 Mar 2017, 19:25
RE:
lucian said:
You can start with this code:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ADX : Robot { private DirectionalMovementSystem _dms; [Parameter("Period", DefaultValue = 25)] public int Period { get; set; } [Parameter("DIPlus", DefaultValue = 20)] public int DIPlus { get; set; } [Parameter("DIMinus", DefaultValue = 20)] public int DIMinus { get; set; } [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Label", DefaultValue = "ADX")] public string Label { get; set; } protected override void OnStart() { _dms = Indicators.DirectionalMovementSystem(Period); } protected override void OnBar() { if (_dms.DIMinus.LastValue > DIMinus && _dms.DIPlus.LastValue < DIPlus && Positions.FindAll(Label, Symbol, TradeType.Buy).Length == 0) { close(TradeType.Sell); trade(TradeType.Buy); } if (_dms.DIMinus.LastValue < DIMinus && _dms.DIPlus.LastValue > DIPlus && Positions.FindAll(Label, Symbol, TradeType.Sell).Length == 0) { close(TradeType.Buy); trade(TradeType.Sell); } } private void close(TradeType tradeType) { foreach (var position in Positions.FindAll(Label, Symbol, tradeType)) ClosePosition(position); } private void trade(TradeType tradetype) { ExecuteMarketOrder(tradetype, Symbol, Volume, Label); } } }Thank you so much ! You truly made my day.
@phily1_1
phily1_1
14 Mar 2017, 20:45
Like this ???
@phily1_1