Can anyone help me diagnose why the code doesn't work?

Created at 03 Feb 2019, 21:39
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SA

sandstormer741

Joined 03.02.2019

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);
            }
        }
    }
}

 


@sandstormer741
Replies

TonNcie
04 Feb 2019, 09:37

Wrong Quantity

change to Symbol.QuantityToVolumeInUnits( Quantity)


@TonNcie