Error CS0266... Can Anyone help me?

Created at 08 Feb 2022, 13:48
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!
GI

GiacomoGiannandrea

Joined 08.02.2022

Error CS0266... Can Anyone help me?
08 Feb 2022, 13:48


Im having some problems in compiling this algorithm. Specifically i'm having these errors in the console:


Error CS0266: Could not implicitly convert type 'cAlgo.FDGGCSMA' to 'cAlgo.API.Indicators.SimpleMovingAverage'. There is an explicit conversion. Probable missing cast.
Error CS0266: Could not implicitly convert type 'cAlgo.FDGGCSMA' to 'cAlgo.API.Indicators.SimpleMovingAverage'. There is an explicit conversion. Probable missing cast.
Error CS0266: Could not implicitly convert type 'cAlgo.FDGGCSMA' to 'cAlgo.API.Indicators.SimpleMovingAverage'. There is an explicit conversion. Probable missing cast.

 

Source Code:

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

namespace cAlgo.Robots
{

    //DEFINIZIONE ROBOT
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestBench : Robot
    {

        //DEFINIZIONE PARAMETRI

        [Parameter("Lot Size", DefaultValue = 0.01, MinValue = 0.01, MaxValue = 100)]
        public double LotSize { get; set; }

        [Parameter("Source EMA #1")]
        public DataSeries SourceEma1 { get; set; }

        [Parameter("Source EMA #2")]
        public DataSeries SourceEma2 { get; set; }

        [Parameter("Source EMA #3")]
        public DataSeries SourceEma3 { get; set; }

        [Parameter("Period EMA #1", DefaultValue = 1, MinValue = 1, MaxValue = 500)]
        public int PeriodsEma1 { get; set; }

        [Parameter("Period EMA #1", DefaultValue = 1, MinValue = 1, MaxValue = 500)]
        public int PeriodsEma2 { get; set; }

        [Parameter("Period EMA #2", DefaultValue = 80, MinValue = 1, MaxValue = 500)]
        public int PeriodsEma3 { get; set; }

        [Parameter("StopPipsInizio", DefaultValue = 3, MinValue = 1, MaxValue = 100)]
        public double StopPipsInizio { get; set; }

        [Parameter("LimitTrailingStopPips", DefaultValue = 0.0006, MinValue = 1E-05, MaxValue = 1)]
        public double LimitTrailingStopPips { get; set; }

        [Parameter("OffsetTrailingStopPips", DefaultValue = 0.0006, MinValue = 1E-05, MaxValue = 1)]
        public double OffsetTrailingStopPips { get; set; }

        [Parameter("LimitBreakEaven", DefaultValue = 0.0006, MinValue = 1E-05, MaxValue = 1)]
        public double LimitBreakEaven { get; set; }

        //DEFINIZIONE EMA

        private SimpleMovingAverage stochFast1;
        private SimpleMovingAverage stochFast2;
        private SimpleMovingAverage stochSlow;


        //DEFINIZIONE VARIABILI PER ODINI BUY E SELL
        int n = 0;
        int m = 0;
        int PGB = 0;
        int PGS = 0;
        double Limit = 0;



        protected override void OnStart()
        {
            int barraCorrente = Bars.Count - 1;
            stochFast1 = Indicators.GetIndicator<FDGGCSMA>(SourceEma1, PeriodsEma1, 2, 2);
            stochFast2 = Indicators.GetIndicator<FDGGCSMA>(SourceEma2, PeriodsEma2, 10, 5);
            stochSlow = Indicators.GetIndicator<FDGGCSMA>(SourceEma3, PeriodsEma3, 7, 6);
        }





        protected override void OnBar()
        {

        }


        protected override void OnStop()
        {

        }
    }

}

 

Ty for help in advice


@GiacomoGiannandrea
Replies

firemyst
08 Feb 2022, 15:22

You're trying to store the value from this:

Indicators.GetIndicator<FDGGCSMA>

which is an "FDGGCSMA" type into the variable "stochFast1", which is defined as an SMA:

private SimpleMovingAverage stochFast1;

 

We have no idea what you want to do, so the easiest thing to do is change the stochFast1 variable type:

private FDGGCSMA stochFast1;

 


@firemyst