Build Succeeded 1 Warning CS0618

Created at 19 Jan 2025, 10:37
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!
XR

xrichard69

Joined 12.09.2016

Build Succeeded 1 Warning CS0618
19 Jan 2025, 10:37


can you guys help me whats wrong with the code? i cant fix it 

Warning CS0618: ‘Robot.ModifyPosition(Position, double?, double?) is obsolete: ‘Please use new version with ProtectionType parameter.’ (C:\Users\Rich\Documents\cAlgo\Sources\indicators\NESGISNALLINESGISNALLINESGISNALL.cs, line: 80,
Column: 21




using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class EMAAndRenkoDonchianStrategy : Robot
    {
        [Parameter("EMA Period", DefaultValue = 8)]
        public int EMAPeriod { get; set; }

        [Parameter("Donchian Channel Period", DefaultValue = 12)]
        public int DonchianPeriod { get; set; }

        [Parameter("Renko Box Size (Pips)", DefaultValue = 10)]
        public int RenkoBoxSize { get; set; }

        [Parameter("Position Size (Lots)", DefaultValue = 0.1)]
        public double PositionSize { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 20)]
        public int TakeProfitPips { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 10)]
        public int StopLossPips { get; set; }

        private ExponentialMovingAverage _ema;
        private DonchianChannel _donchian;

        private bool _renkoInitialized;
        private double _lastRenkoClose;

        protected override void OnStart()
        {
            _ema = Indicators.ExponentialMovingAverage(Bars.ClosePrices, EMAPeriod);
            _donchian = Indicators.DonchianChannel(Bars, DonchianPeriod);

            _renkoInitialized = false;
            _lastRenkoClose = 0;
        }

        protected override void OnTick()
        {
            double currentClose = Bars.ClosePrices.Last(0);

            // Initialize Renko if not already done
            if (!_renkoInitialized)
            {
                _lastRenkoClose = Math.Floor(currentClose / Symbol.PipSize) * Symbol.PipSize * RenkoBoxSize;
                _renkoInitialized = true;
                return;
            }

            // Update Renko close if new box forms
            if (Math.Abs(currentClose - _lastRenkoClose) >= RenkoBoxSize * Symbol.PipSize)
            {
                _lastRenkoClose = Math.Floor(currentClose / Symbol.PipSize) * Symbol.PipSize * RenkoBoxSize;

                // Check EMA and Donchian for trade signals
                bool isAboveEMA = currentClose > _ema.Result.LastValue;
                bool isBelowEMA = currentClose < _ema.Result.LastValue;

                if (isAboveEMA && _lastRenkoClose > _ema.Result.LastValue && Positions.FindAll("EMAAndRenkoDonchianStrategy").Length == 0)
                {
                    ExecuteTrade(TradeType.Buy);
                }
                else if (isBelowEMA && _lastRenkoClose < _ema.Result.LastValue && Positions.FindAll("EMAAndRenkoDonchianStrategy").Length == 0)
                {
                    ExecuteTrade(TradeType.Sell);
                }
            }

            // Manage trailing stop
            foreach (var position in Positions)
            {
                if (position.Pips >= 50 && position.StopLoss == null)
                {
                    ModifyPosition(position, position.EntryPrice, position.TakeProfit);
                }
            }
        }

        private void ExecuteTrade(TradeType tradeType)
        {
            double volumeInUnits = Symbol.QuantityToVolumeInUnits(PositionSize);
            ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "EMAAndRenkoDonchianStrategy", StopLossPips, TakeProfitPips);
        }

        protected override void OnStop()
        {
            Print("Strategy stopped.");
        }
    }
}


@xrichard69
Replies

firemyst
20 Jan 2025, 00:38 ( Updated at: 21 Jan 2025, 21:08 )

You can fix it.

It's exactly as the error message says – you're missing a parameter which specifies the “ProtectionType”. 

The code compiles and should still run at the moment.

@Spotware has yet to provide any documentation or responses to people who have posted and asked what the new ProtectionType parameter is about, or does:

https://community.ctrader.com/forum/cbot-support/46002/

https://community.ctrader.com/forum/ctrader-algo/46005/

https://community.ctrader.com/forum/ctrader-algo/45988/

 


@firemyst