Reference custom indicator

Created at 17 Sep 2012, 09: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!
PS

PsykotropyK

Joined 17.09.2012

Reference custom indicator
17 Sep 2012, 09:15


Hi all,

 

I'm trying to figure out how to reference one of my indicator to be used in a robot, as rewritting the indicator code in the robot seems a bit useless.

 

My indicator name is "TrendFinder", it got 3 parameters (StdDevMultiplier, StdDevPeriod and MAType) and 2 outputs (UpTrend and DownTrend) - parameter & outputs declared in this order.

 

I tried the same way as when I use built in parameters (private TrendFinder UpTrend; &then UpTrend= Indicators.TrendFinder(...);) but it doesn't work.

 

Thanks if someone can help

 

 


@PsykotropyK
Replies

sktrader
17 Sep 2012, 10:06

Hi,

 

You need to click Add Reference on the top next to build, locate your algo file (indicator) and then in the code:

        TrendFinder trendFinder; // Declaration

        protected override void OnStart()
        {
            trendFinder = Indicators.GetIndicator<TrendFinder>(StdDevMultiplier, StdDevPeriod, MAType);
        }

        protected override void OnTick()
        {
            Print("{0}", trendFinder.UpTrend.LastValue);
            Print("{0}", trendFinder.DownTrend) .LastValue);
        }

@sktrader

PsykotropyK
17 Sep 2012, 12:43

Thanks, I'll try this tomorrow (no access to cAlgo for now) :)


@PsykotropyK

PsykotropyK
18 Sep 2012, 09:10

Unfortunately it doesn't work. I referenced my indicator, which added a #reference line at line 1 with the complete file path. Then, I put your code lines

private TrendFinder trendFinder;
    	
        protected override void OnStart()
        {
            // Put your initialization logic here
            trendFinder = Indicators.GetIndicator(StdDevMultiplier, StdDevPeriod, MAType);
        }

        protected override void OnTick()
        {
            // Put your core logic here
             Print("{0}", trendFinder.UpTrend.LastValue);
        }



When I build the robot, I got this error : "The type or namespace name 'TrendFinder' could not be found are you using directive or an assembly reference?)". I checked the spelling, and there are no typo with the name. I tried with 2 other indicators that I downloaded here, and call the added reference raise the same error.


@PsykotropyK

PsykotropyK
18 Sep 2012, 09:14

Little typo: seems that the code insertion doesn't want to write <TrendFinder> after getindicator, but my code does :)

 

 


@PsykotropyK

PsykotropyK
18 Sep 2012, 09:21

I try to add the #eference line issued from my indicator to my robot at the beginning but it didn't changed anything


@PsykotropyK

sktrader
18 Sep 2012, 10:23

Check to see if SampleRobotReferenceSMA builds. If it does then that means it's probably your code. 

 


@sktrader

PsykotropyK
18 Sep 2012, 10:50

If the problem is coming from my robot's code, then it should be easy to find, everything's in the thread (the only code so far is calling the indicator). If you are talking about the indicator's code, well it's working pretty well.


@PsykotropyK

sktrader
18 Sep 2012, 11:28

I'm talking about the example Robot that comes with the program(cAlgo).

The name is SampleRobotReferenceSMA. You can find it in the Robots section of cAlgo.

It's doing the same thing you want to do...


@sktrader

admin
19 Sep 2012, 15:22

Hello PsykotropyK,

 

If you are still unable to reference an indicator from a robot please post your indicator and your robot code here so that we can troubleshoot it.

 


@admin

PsykotropyK
20 Sep 2012, 09:08

Ok indeed something was wrong with my robot code :) Creating a robot miss the line "using cAlgo.Indicators;" Now its fixed and working


@PsykotropyK

matttt
21 Sep 2012, 11:21

To PsykotropyK or the support team,

 

Can you clarify your solution given in your last post ?

I do have the same issue with calling an indicator which works on the plateforme (the indicator is Aroon Horn and was downloaded from this forum).

It still gives the same error message when building the code : "The type or namespace name 'AroonHorn' could not be found are you using directive or an assembly reference?)"

I checked the spelling, it was correct. I even tried renaming the indicator (new file to keep the old one OK) without space and it still return the same error message when building the bot.

 

Beginning of the code is copied hereunder if someone could help (yet this part which is the one causing troubles) :

 


//#reference: C:\Documents and Settings\Mat\Mes documents\cAlgo\Sources\Indicators\AroonHorn.algo
// -------------------------------------------------------------------------------------------------
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot]
    public class ISSUEALONE : Robot 
    { 
        [Parameter ("Period", DefaultValue = 10)]
        public int Period { get; set; }
        
        [Parameter("Filter", DefaultValue = 25)]
        public int Filter { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 10)]
        public int StopLoss { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        private Position position;        
        private AroonHorn ARH;

        protected override void OnStart()
        {
            ARH = Indicators.GetIndicator<AroonHorn>(Period, Filter);
        }

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

 

 

and then follow the rest of the code with decision parameters... etc...

Thanks in advance for your help.


@matttt

PsykotropyK
22 Sep 2012, 11:33

My solution was only to add

using cAlgo.Indicators;

I'm not sure it will help, but change your reference to your indicator by

//#reference: ..\Indicators\AroonHorn.algo

It will prevent any errors if you change your directories, computer name, ...

Fr the rest, in your AroonHorn indicator, is the class declared at the begining is named AroonHorn (I don't know much C# but it should be this name that you call)

public class AroonHorn : Indicator

Then check that your parameters declaration is in the same order in your indicator and in your robot. If not, copy past the exact error


@PsykotropyK

PsykotropyK
22 Sep 2012, 16:01

An other thing, is your reference at the first line of your code? I just try a new robot an put it after the first comment : didn't work. Put it back first line, work perfectly


@PsykotropyK

matttt
24 Sep 2012, 16:11

Reference custom indicator

Hi PsykotropyK,

Thanks for the tips and the reply...

It appears that the issue was, as you suggested, that the class declared at the beginning in the indicator was "NewIndicator" instead of AroonHorn called in the robot. First thing solved !!

 

I also made the following changes which seem to be good advice : ''change your reference to your indicator by //#reference: ..\Indicators\AroonHorn.algo''...

 

 

Another mistake is appearing now but I'll of course check if I can solve it myself first before asking for help.

Thanks again PsykotropyK,

 


@matttt