Required Reference List

Created at 20 Mar 2018, 19:20
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!
_I

_internet

Joined 19.03.2018

Required Reference List
20 Mar 2018, 19:20


Hi, 

I'm getting multiple errors about missing a using directive or an assembly, so tried turning all of the references on (I'm very new to C# and was trying to expedite the process). Now I'm getting errors about duplicate reference imports and the like. I'm looking for a list of the references required so I don't keep going back and forth. I'm trying to use the Result method I got from this strategy /forum/cbot-support/9483 - the last one on the page. And it was repeatedly saying that I might be missing a using directive or assembly reference, but in the strategy I've linked there was no explicit reference to it before it was used to set the EMAs and orders up. This is the whole reason why I tried to change the .NET Framework to see if it would take away the issue, however it has not.  

var currentEMA_165 = EMA_120.Result.Last(1);

All I'm trying to do is retrieve the EMA value of the last bar, second-to-last bar, etc. Any advice would be much appreciated.

Thank you.


@_internet
Replies

PanagiotisCharalampous
21 Mar 2018, 10:59

Hi cianwynne,

It would be much easier for us to help you if you could share with us the cBot code so that we can reproduce your issue.

Best Regards,

Panagiotis


@PanagiotisCharalampous

_internet
21 Mar 2018, 11:12

Here's the code
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 EMA_Crossover_Strategy : Robot
    {


        [Parameter()]
        public DataSeries SourceSeries { get; set; }





        [Parameter()]
        public DateTime TimeSeries { get; set; }

        //Last(int index);


        [Parameter("EMA_9_period", DefaultValue = 9)]
        public int EMA_9_period { get; set; }

        [Parameter("EMA_3_period", DefaultValue = 3)]
        public int EMA_3_period { get; set; }

        

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]

        

        public double Quantity { get; set; }
        private RelativeStrengthIndex rsi;

        //private ExponentialMovingAverage EMA_9;
        //private ExponentialMovingAverage EMA_3;
        
        private const string label = "Strategy";
        private Position longPosition;
        private Position shortPosition;
        private bool OpenBuyTrade;
        private bool OpenSellTrade;

        protected override void OnStart()
        {
            var EMA_9 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_9_period);
            var EMA_3 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_3_period);
            

            

            OpenBuyTrade = false;
            OpenSellTrade = false;

        }

        protected override void OnBar()
        {

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);


            var currentEMA_9 = EMA_9.Result.Last(1);
            var currentEMA_3 = EMA_3.Result.Last(1);
         
            var lastEMA_9 = EMA_9.Result.Last(2);
            var lastEMA_3 = EMA_3.Result.Last(2);
            
            var currentcandleopen = MarketSeries.Open.Last(0);
            if (OpenBuyTrade)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
                OpenBuyTrade = false;
            }

            if (OpenSellTrade)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
                OpenSellTrade = false;
            }
            if (EMA_3.Result.Last(2) <= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) > EMA_9.Result.Last(1) && longPosition == null)
            {
                OpenBuyTrade = true;

            }
            else if (EMA_3.Result.Last(2) > EMA_9.Result.Last(2) && EMA_3.Result.Last(1) < EMA_9.Result.Last(1) && shortPosition == null)
            {
                OpenSellTrade = true;

            }

            if (longPosition != null && EMA_3.Result.Last(2) >= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) < EMA_9.Result.Last(1))
                ClosePosition(longPosition);

            if (shortPosition != null && EMA_3.Result.Last(2) <= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) > EMA_9.Result.Last(1))
                ClosePosition(shortPosition);
        }

        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}

I'm also getting the error: Error CS1003: Syntax error, ']' expected

and: Error CS1730: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations.

Advice would be appreciated, thank you.


@_internet

_internet
21 Mar 2018, 11:13

P.S.

I should mention that the Syntax error above is written as follows: Error AssemblyInfo.cs: Syntax error, ']' expected


@_internet

PanagiotisCharalampous
21 Mar 2018, 11:37

Hi cianwynne,

Thanks for the cBot. The provided code does not build but the error I receive is about EMA_3 and EMA_9 not being declared in the OnBar method. When I uncomment the relevant properties, it builds fine. Am i missing something?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Mar 2018, 12:06

Please also note that DateTime is not supported as an input parameter

        [Parameter()]
        public DateTime TimeSeries { get; set; }

 


@PanagiotisCharalampous

_internet
21 Mar 2018, 14:44

Hi Panagiotis,

 

Thank you for that. I used the suggestion of the reference window to use the time series option where I want to retrieve the EMA value a certain number of hours ago, i.e. 2, and input what was shown so thought this would work.

It says build succeeded, however gives the error messages

Warning EMA_TEST.cs: Error CS0169: The field 'cAlgo.EMA_TEST.rsi' is never used

Warning EMA_TEST.cs: Error CS0649: Field 'cAlgo.EMA_TEST.EMA_9' is never assigned to, and will always have its default value null

The code I ran is below.

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 EMA_TEST : Robot
    {


        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("EMA_9_period", DefaultValue = 9)]
        public int EMA_9_period { get; set; }

        [Parameter("EMA_3_period", DefaultValue = 3)]
        public int EMA_3_period { get; set; }



        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]



        public double Quantity { get; set; }
        private RelativeStrengthIndex rsi;

        private ExponentialMovingAverage EMA_9;
        private ExponentialMovingAverage EMA_3;

        private const string label = "Strategy";
        private Position longPosition;
        private Position shortPosition;
        private bool OpenBuyTrade;
        private bool OpenSellTrade;

        protected override void OnStart()
        {
            var EMA_9 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_9_period);
            var EMA_3 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_3_period);




            OpenBuyTrade = false;
            OpenSellTrade = false;

        }

        protected override void OnBar()
        {

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);


            var currentEMA_9 = EMA_9.Result.Last(1);
            var currentEMA_3 = EMA_3.Result.Last(1);

            var lastEMA_9 = EMA_9.Result.Last(2);
            var lastEMA_3 = EMA_3.Result.Last(2);

            var currentcandleopen = MarketSeries.Open.Last(0);
            if (OpenBuyTrade)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
                OpenBuyTrade = false;
            }

            if (OpenSellTrade)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
                OpenSellTrade = false;
            }
            if (EMA_3.Result.Last(2) <= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) > EMA_9.Result.Last(1) && longPosition == null)
            {
                OpenBuyTrade = true;

            }
            else if (EMA_3.Result.Last(2) > EMA_9.Result.Last(2) && EMA_3.Result.Last(1) < EMA_9.Result.Last(1) && shortPosition == null)
            {
                OpenSellTrade = true;

            }

            if (longPosition != null && EMA_3.Result.Last(2) >= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) < EMA_9.Result.Last(1))
                ClosePosition(longPosition);

            if (shortPosition != null && EMA_3.Result.Last(2) <= EMA_9.Result.Last(2) && EMA_3.Result.Last(1) > EMA_9.Result.Last(1))
                ClosePosition(shortPosition);
        }

        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}

 


@_internet

PanagiotisCharalampous
21 Mar 2018, 15:10

Hi ciawynne,

You get these warnings because you still use local variables when getting the indicators

            var EMA_9 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_9_period);
            var EMA_3 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_3_period);

it should be

            EMA_9 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_9_period);
            EMA_3 = Indicators.ExponentialMovingAverage(SourceSeries, EMA_3_period);

Best Regards,

Panagiotis


@PanagiotisCharalampous

_internet
21 Mar 2018, 18:34

Thank you


@_internet