Set the indicator name in runtime

Created at 19 Nov 2016, 10:39
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!
CT

ctid256802

Joined 18.10.2016

Set the indicator name in runtime
19 Nov 2016, 10:39


Hello

I'd like to set the indicator display name based on the parameters set by the user - i.e. if I'm implementing my RSI so I'd like to have the name set as "RSI(<Period>)" where Period is a parameter. IS there any way how it's can be done at runtime - for example in Initialize() function?


@ctid256802
Replies

Jiri
19 Nov 2016, 15:35

Hi, the indicator name must be constant value so it's not possible to change in runtime. By default it shows indicator name and its parameters in parentheses, therefore if the Period is a parameter then it should be printed on the chart as desired.

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Levels(30, 70)]
    [Indicator("RSI", IsOverlay = false, ScalePrecision = 0, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RSI : Indicator
    {
        [Parameter(DefaultValue = 14, MinValue = 1)]
        public int Period { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private RelativeStrengthIndex rsi;

        protected override void Initialize()
        {
            rsi = Indicators.RelativeStrengthIndex(MarketSeries.Close, Period);
        }

        public override void Calculate(int index)
        {
            Result[index] = rsi.Result[index];
        }
    }
}


@Jiri

ctid256802
20 Nov 2016, 00:12

RE:

tmc. said:

Hi, the indicator name must be constant value so it's not possible to change in runtime. By default it shows indicator name and its parameters in parentheses, therefore if the Period is a parameter then it should be printed on the chart as desired.

 

Hm... why it "must be constant"? Just a quick example: I'm making indicator for COT Reports. As the parameter the user supplies the market code - i.e. "094532". So it's not user friendly to see the name like "COTReport(094532)" - I want to show instead something like "COTReport(British Pound)" - which I can actually can do as I have a key-value map in my indicator.

In fact inability to set the name in runtime is really a big limitation which makes indicators less user-friendly.


@ctid256802

Jiri
20 Nov 2016, 16:10

You should ask Spotware not me. All I am just saying is the fact that the name showed on the chart must be constant value and values in parentheses are inputed paramater values.

You can print whatever you want on the chart as text object with static position.

ChartObjects.DrawText("objectName", "COTReport(British Pound)", StaticPosition.TopLeft, Colors.Black);

 


@Jiri

ctid256802
20 Nov 2016, 19:17

Hi tmc,

That was the rhetorical question :)

And thank you for the tip with text object - it could be an option for me. Thanks!


@ctid256802