PH
Topics
12 Mar 2017, 12:20
3038
4
Replies
phily1_1
14 Mar 2017, 20:45
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 { public class SampleRobot : Robot { private DirectionalMovementSystem _dms; private double _DIplus; private double _DIminus; [Parameter("Period", DefaultValue = 25)] public int Period { get; set; } [Parameter("DIPlus", DefaultValue = 0)] public int DIPlus { get; set; } [Parameter("DIMinus", DefaultValue = 0)] public int DIMinus { get; set; } protected override void OnStart() { _dms = Indicators.DirectionalMovementSystem(Period); } protected override void OnBar() { if (Trade.IsExecuting) return; bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy; bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell; if (_dms.ADX.LastValue > 0.0 && _dms.DIPlus.LastValue() && !isLongPositionOpen) { ClosePosition(); Buy(); } if (_dms.ADX.LastValue < 0.0 && _dms.DIMinus.LastValue() && !isShortPositionOpen) { ClosePosition(); Sell(); } } private void Buy() { Trade.CreateBuyMarketOrder(Symbol, Volume); } private void Sell() { Trade.CreateSellMarketOrder(Symbol, Volume); } protected override void OnPositionOpened(Position openedPosition) { _position = openedPosition; } } }
Like this ???
@phily1_1
phily1_1
16 Mar 2017, 19:25
RE:
lucian said:
@phily1_1