Help With Custom Indicators in CBot

Created at 23 Jan 2021, 01:15
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!
JA

jackhpfilerrowson

Joined 26.11.2020

Help With Custom Indicators in CBot
23 Jan 2021, 01:15


Can someone please help me figure out why this isnt working. Thanks

Error Code : Error CS1061: 'cAlgo.EmaforATRBot' does not contain a definition for 'Result' and no extension method 'Result' accepting a first argument of type 'cAlgo.EmaforATRBot' could be found (are you missing a using directive or an assembly reference?)

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }


        private ATRPipValue Atr;
        private EmaforATRBot Ema;
        private Fractals Frac;
        private SimpleMovingAverage High;
        private SimpleMovingAverage Low;
        private double C;
        private double Volume;
        private double VolumeUsd;
        private double lot;
        private double Lot;
        //Symbol _gbpusd;
        //private double GBPUSD;

        protected override void OnStart()
        {
            Atr = Indicators.GetIndicator<ATRPipValue>();
            Ema = Indicators.GetIndicator<EmaforATRBot>();
            Frac = Indicators.Fractals(5);
            High = Indicators.SimpleMovingAverage(Bars.HighPrices, 1);
            Low = Indicators.SimpleMovingAverage(Bars.LowPrices, 1);
            C = High.Result.LastValue - Low.Result.LastValue;
            Volume = (0.57 * High.Result.LastValue) / C;
            VolumeUsd = Volume * 1.37;
            lot = 100000 * High.Result.LastValue;
            Lot = Volume / lot;
        }

        protected override void OnBar()
        {
            //Atr and Ema
            if (Ema.Result.LastValue > Atr.Result.LastValue)
                //Fractles (Trigger)
                if (Frac.DownFractal.LastValue > Low.Result.LastValue)
                {
                    PlaceStopOrder(TradeType.Buy, SymbolName, Volume, High.Result.LastValue, "StopOrder");
                }

        }



        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


@jackhpfilerrowson
Replies

firemyst
23 Jan 2021, 08:31

As the error message says, why do you think there's a property called "Result"?

There clearly isn't one, so you'll have to figure out what property you need to reference to get the latest value. Not every indicator has a "Result" field nor is it required to.

 

So the best way to tackle this problem is change the line from "Ema.Result.LastValue" to just "Ema". Once you have that, type the period "." to see if any properties show up. Then you'll have to pick from the list if they do.

If they don't, you need to either be able to see the source code to see what the property is, read the documentation, or get in contact with the indicator's author.


@firemyst

jackhpfilerrowson
23 Jan 2021, 14:06

RE:

firemyst said:

As the error message says, why do you think there's a property called "Result"?

There clearly isn't one, so you'll have to figure out what property you need to reference to get the latest value. Not every indicator has a "Result" field nor is it required to.

 

So the best way to tackle this problem is change the line from "Ema.Result.LastValue" to just "Ema". Once you have that, type the period "." to see if any properties show up. Then you'll have to pick from the list if they do.

If they don't, you need to either be able to see the source code to see what the property is, read the documentation, or get in contact with the indicator's author.

Thanks. Looking back at my indicator I had used Resultema instead of Result


@jackhpfilerrowson