How to call custom indicator

Created at 23 Mar 2019, 12: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!
LG

lgwsyqnfr

Joined 23.03.2019

How to call custom indicator
23 Mar 2019, 12:19


How to call a custom indicator?

Example, there is a custom indicator of abc.calgo in ...\cAlgo\Sources\Indicators.  Now i want to call it in cBot with H1, and another with H4, in OnSart().

How should i to do ?

Thanks Advance.


@lgwsyqnfr
Replies

2bnnp
24 Mar 2019, 09:34

        [Parameter("Timeframe #1", DefaultValue = "Minute15")]
        public TimeFrame Tf1 { get; set; }

        private StochasticOscillator _stochCTF { get; set; }
        private StochasticOscillator _stochMTF { get; set; }

        protected override void OnStart()
        {
            var timeFrameOne = MarketData.GetSeries(Tf1);

            _stochCTF = Indicators.StochasticOscillator(KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);
            _stochMTF = Indicators.StochasticOscillator(timeFrameOne, KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);

        }

 


@2bnnp

2bnnp
24 Mar 2019, 09:40 ( Updated at: 21 Dec 2023, 09:21 )

Sorry missed the part with the custom indicator.

First you need to add a reference for the custom indicator to call it in your bot.

 

Then you can call it with Indicators.GetIndicator<CustomIndicatorHere>(Param1, Param2, Param3)


@2bnnp

lgwsyqnfr
24 Mar 2019, 13:43 ( Updated at: 21 Dec 2023, 09:21 )

RE:

2bnnp said:

Sorry missed the part with the custom indicator.

First you need to add a reference for the custom indicator to call it in your bot.

 

Then you can call it with Indicators.GetIndicator<CustomIndicatorHere>(Param1, Param2, Param3)

Thanks your help. but i still get it.

One of the reasons why MT4 and 5 are so popular is that MQL has detailed practical application examples, so, anyone can write its own program according to the examples. CTrader does very poorly in this respect, after all, most traders are not professional programmers. Therefore, cTrader has a long way to go before it can be popularized in the market.


@lgwsyqnfr

PanagiotisCharalampous
26 Mar 2019, 11:07

Hi lgwsyqnfr,

The process of referencing custom indicators is documented here.

Best Regards,

Panagiotis


@PanagiotisCharalampous

jani
28 Oct 2019, 13:48

RE:

Panagiotis Charalampous said:

Hi lgwsyqnfr,

The process of referencing custom indicators is documented here.

Best Regards,

Panagiotis

We appreciate your help and you're doing a great job for the cAlgo community!

But unfortunately, lgwsyqnfr is correct. The instructional material and examples for cAlgo are hard to find and sometimes lack in-depth content

API reference is notoriously poor to search for anything and even syntax definitions are sometimes lacking in content and important info.

Good example is the issue of cBot referencing custom indicator's. The document here that is always used as a reference unfortunately has NO INFORMATION on how cBot references custom indicators.

Also I cannot find any info on how I reference past custom indicator values... for a C# programmer this would be an obvious case, but many of us are not programmers but self-learned developers that need more handholding.

 

I just migrated from MT4 to cTrader and I would hate to have to go back to MQL, because I cannot find enough educational and reference material for cAlgo... :( (ps. I'm currently paying programmers to teach me...and I should not have to... there should be at least comprehensive reference material available!)


@jani

PanagiotisCharalampous
29 Oct 2019, 09:12

Hi Jani,

Thanks for your feedback but it is not clear to me which information you thing is missing. Regarding

Also I cannot find any info on how I reference past custom indicator values

It is exacly the same as for built in indicators and an example is provided in the link you posted. Pasting it again below

[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
public class SampleReferenceSMA : Indicator
{
    [Parameter("Source")]
    public DataSeries Source { get; set; }
 
    [Parameter(DefaultValue = 14)]
    public int SmaPeriod { get; set; }
 
    [Output("Referenced SMA Output")]
    public IndicatorDataSeries refSMA { get; set; }
 
    private SampleSMA sma;
 
    protected override void Initialize()
    {
        sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);
    }
 
    public override void Calculate(int index)
    {
        refSMA[index] = sma.Result[index];
    }
}

If you need older values you can use the Last() function.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
22 Feb 2022, 10:16

Nothing in the referenced link talks about or explains the concept of "lazy loading" of the indicators. There are numerous questions always popping up on the forums asking about this and people not being able to get values.


@firemyst