C ALGO I NEED TO CORRECT SOME ERRORS

Created at 30 Jun 2024, 22:07
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!
GO

GOLDENGRAIL

Joined 30.05.2023

C ALGO I NEED TO CORRECT SOME ERRORS
30 Jun 2024, 22:07


THIS BOT CODE SHOWS ERRORS, ANYONE CAN HELP PLEASE TO CORRECT THE ERRORS 

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HEREWEGO : Robot
    {
        [Parameter("Lots", DefaultValue = 0.1)]
        public double Lots { get; set; }

        [Parameter("Target", DefaultValue = 4)]
        public double Target { get; set; }

        private int cbars = 0;
        private const int magic = 1111111;
        private int dist = 24;

        protected override void OnStart()
        {
            Positions.Closed += OnPositionClosed;
        }

        protected override void OnTick()
        {
            double profit = 0;

            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                var position = Positions[i];
                if (position.Label == magic.ToString() && position.SymbolCode == Symbol.Code)
                    profit += position.NetProfit + position.Swap;
            }

            if (profit >= Target)
            {
                for (int i = Positions.Count - 1; i >= 0; i--)
                {
                    var position = Positions[i];
                    if (position.TradeType == TradeType.Buy && position.Label == magic.ToString() && position.SymbolCode == Symbol.Code)
                        ClosePosition(position);
                }
            }

            double lowest = MarketSeries.Lowest(MarketSeries.Close, dist);
            if (cbars != MarketSeries.Bars && lowest == MarketSeries.Low.Last(1))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Lots, "buy", magic.ToString(), 0, 0, null, "Blue");
                ChartObjects.DrawArrow("ArrBuy", MarketSeries.OpenTime.Last(1), MarketSeries.Low.Last(1) - 6 * Symbol.PipSize, Colors.Blue);
            }

            profit = 0;

            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                var position = Positions[i];
                if (position.TradeType == TradeType.Sell && position.Label == magic.ToString() && position.SymbolCode == Symbol.Code)
                    profit += position.NetProfit + position.Swap;
            }

            if (profit >= Target)
            {
                for (int i = Positions.Count - 1; i >= 0; i--)
                {
                    var position = Positions[i];
                    if (position.TradeType == TradeType.Sell && position.Label == magic.ToString() && position.SymbolCode == Symbol.Code)
                        ClosePosition(position);
                }
            }

            double highest = MarketSeries.Highest(MarketSeries.Close, dist);
            if (cbars != MarketSeries.Bars && highest == MarketSeries.High.Last(1))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, Lots, "sell", magic.ToString(), 0, 0, null, "Magenta");
                ChartObjects.DrawArrow("ArrSell", MarketSeries.OpenTime.Last(1), MarketSeries.High.Last(1) + 6 * Symbol.PipSize, Colors.Magenta);
            }

            cbars = MarketSeries.Bars;
        }

        private void OnPositionClosed(PositionClosedEventArgs args)
        {
            // Handle position closed event if needed
        }
    }
}


@GOLDENGRAIL
Replies

PanagiotisCharalampous
01 Jul 2024, 05:27

Hi there,

cAlgo.API.Indicators.Extensions namespace is missing. You need to find it and reference it.

Best regards,

Panagiotis


@PanagiotisCharalampous