Can anyone help me diagnose why the code doesn't work?
Created at 03 Feb 2019, 21:39
SA
Can anyone help me diagnose why the code doesn't work?
03 Feb 2019, 21:39
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 Yeet : Robot { const string Label = "Super RSI"; [Parameter("StopL", DefaultValue = 1)] public int StopLoss { get; set; } [Parameter("TakeP", DefaultValue = 3)] public int TakeProfit { get; set; } [Parameter("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 14)] public int Periods { get; set; } [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)] public int Quantity { get; set; } private RelativeStrengthIndex rsi; protected override void OnStart() { rsi = Indicators.RelativeStrengthIndex(Source, Periods); } protected override void OnTick() { var longPosition = Positions.Find(Label, Symbol, TradeType.Buy); var shortPosition = Positions.Find(Label, Symbol, TradeType.Sell); if (rsi.Result.LastValue < 30) { if (shortPosition != null) ClosePosition(shortPosition); ExecuteMarketOrder(TradeType.Buy, Symbol, Quantity, Label, StopLoss, TakeProfit); } else if (rsi.Result.LastValue > 70) { if (longPosition != null) ClosePosition(longPosition); ExecuteMarketOrder(TradeType.Sell, Symbol, Quantity, Label, StopLoss, TakeProfit); } } } }
TonNcie
04 Feb 2019, 09:37
Wrong Quantity
change to Symbol.QuantityToVolumeInUnits( Quantity)
@TonNcie