Help me correct this error

Created at 10 May 2015, 16:19
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!
GS

GS66

Joined 12.04.2015

Help me correct this error
10 May 2015, 16:19


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

namespace cAlgo.Robots
{
    [Robot()]
    public class MA_Hull Cross : Robot
    {
        private int _trendDirection;
        private double _pipSize;

        private HMA _hullmaIndi;
        private MovingAverage _maIndi;

        [Parameter(DefaultValue = "HMA")]
        public string Label { get; set; }

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

        [Parameter("HMA Period", DefaultValue = 21, MinValue = 4)]
        public int HullPeriod { get; set; }


        [Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }


        [Parameter("MA Period", DefaultValue = 14)]
        public int maPeriod { get; set; }

        [Parameter(DefaultValue = 5, MinValue = 0)]
        public int MinMADiff { get; set; }

        [Parameter(DefaultValue = 30000)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 40, MinValue = 0)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 250, MinValue = 0)]
        public int TakeProfit { get; set; }

        [Parameter(DefaultValue = 0)]
        public int TrailingStop { get; set; }

        [Parameter(DefaultValue = 0)]
        public int TriggerTrailing { get; set; }

        [Parameter(DefaultValue = 3)]
        public int Slippage { get; set; }


        protected override void OnStart()
        {
            _hullmaIndi = Indicators.GetIndicator<HMA>(Source, HullPeriod);
            _maIndi = Indicators.MovingAverage(Source, maPeriod, MAType);
            _pipSize = Symbol.PipSize;
        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            CheckCross();

            if (TrailingStop > 0)
                TrailPosition();
        }


        // Check for cross and open/close the positions respectively       
        private void CheckCross()
        {
            double fmaCurrent = _hullmaIndi.Result.LastValue;

            double smaCurrent = _maIndi.Result.LastValue;

            switch (_trendDirection)
            {
                case 0:
                    if ((fmaCurrent - smaCurrent) >= MinMADiff * _pipSize)
                        _trendDirection = 1;
                    //Bullish state
                    else if ((smaCurrent - fmaCurrent) >= MinMADiff * _pipSize)
                        _trendDirection = -1;
                    //Bearish state
                    break;
                case 1:
                    //Became bearish
                    if ((smaCurrent - fmaCurrent) >= MinMADiff * _pipSize)
                    {
                        ClosePrev();
                        ExecuteTrade(TradeType.Sell);
                        _trendDirection = -1;
                    }
                    break;
                case -1:
                    //Became bullish
                    if ((fmaCurrent - smaCurrent) >= MinMADiff * _pipSize)
                    {
                        ClosePrev();
                        ExecuteTrade(TradeType.Buy);
                        _trendDirection = 1;
                    }
                    break;
            }
        }

        private void ClosePrev()
        {
            foreach (Position position in Account.Positions.Where(position => position.Label == Label && position.SymbolCode == Symbol.Code))
            {
                Trade.Close(position);
            }
        }

        private void ExecuteTrade(TradeType tradeType)
        {
            var request = new MarketOrderRequest(tradeType, Volume) 
            {
                Label = Label,
                SlippagePips = Slippage,
                StopLossPips = StopLoss,
                TakeProfitPips = TakeProfit
            };
            Trade.Send(request);
        }


        private void TrailPosition()
        {
            foreach (Position position in Account.Positions.Where(position => position.Label == Label && position.SymbolCode == Symbol.Code))
                if (position.TradeType == TradeType.Buy)
                {
                    var distance = (double)(position.StopLoss == null ? Symbol.Bid - position.EntryPrice : Symbol.Bid - position.StopLoss);

                    if (distance >= TriggerTrailing * Symbol.PipSize)
                    {
                        double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits);

                        if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
                        {
                            Trade.ModifyPosition(position, newStopLossPrice, position.TakeProfit);
                        }
                    }
                }
                else
                {
                    var distance = (double)(position.StopLoss == null ? position.EntryPrice - Symbol.Ask : position.StopLoss - Symbol.Ask);

                    if (distance >= TriggerTrailing * Symbol.PipSize)
                    {
                        double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits);

                        if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
                        {
                            Trade.ModifyPosition(position, newStopLossPrice, position.TakeProfit);
                        }
                    }
                }
        }

        protected override void OnError(Error error)
        {
            Print(error.Code);
            Stop();
        }
    }
}

Hi, this algo generates long and short orders on the cross of hma and sma. Positions are closed on stop loss and trailing stop and NOT on the inverse cross. I linked the reference to HMA indicator

Visually It generates good results.

When I built the code it gives this error: 

Error CS1061: 'cAlgo.Indicators.HMA' non contiene una definizione di 'Result' e non è stato trovato alcun metodo di estensione 'Result' che accetta un primo argomento di tipo 'cAlgo.Indicators.HMA'. Probabilmente manca una direttiva using o un riferimento a un assembly.

How can be solved?


@GS66
Replies

GS66
10 May 2015, 16:50

I've solved.

It was missing definition of result in the Indicator


@GS66