Display Parameter Input as text on chart

Created at 31 Dec 2020, 07:20
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!
DW

dwalkhul

Joined 15.09.2018

Display Parameter Input as text on chart
31 Dec 2020, 07:20


Objective: To display Parameter Input as Text on Chart

The below code displays on chart as: Lots:

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AKBTR : Robot
    {
        [Parameter("Lots", Group = "Parameters", DefaultValue = 0.01)]
        public double defaultLots { get; set; }

        private const string paraTXT = "Lots: "  + "  " + "\n\n\n\n  ";

The objective below is to display on chart the input at the Parameter: Lots: 0.01 or Lots: 5.50 (etc.)

string paraTXT will not accept defaultLots directly - if I add the below code it produces error - solution sought - thanks

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AKBTR : Robot
    {
        [Parameter("Lots", Group = "Parameters", DefaultValue = 0.01)]
        public double defaultLots { get; set; }

        private double LTS = defaultLots; // LTS and LTS.ToString("N2") not working

        private const string paraTXT = "Lots: " + LTS.ToString("N2") + "  " + "\n\n\n\n  ";

The error against - private double LTS  = defaultLots;

Error CS0236: A field initializer cannot reference the non-static field, method, or property 'cAlgo.AKBTR.defaultLots.get'

NO REPLY REQUIRED - SOLUTION AS BELOW

  [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AKBTR : Robot
    {
        [Parameter("Lots", Group = "Parameters", DefaultValue = 0.01)]
        public double defaultLots { get; set; }
      
        protected override void OnStart()
        {
            paraTXT();
        }
        private void paraTXT()
        {
            string paraTXTst = "Lots: " + defaultLots.ToString("N2") + "  " + "\n\n\n\n  ";

            Chart.DrawStaticText("", paraTXTst, VerticalAlignment.Bottom, HorizontalAlignment.Left, Chart.ColorSettings.ForegroundColor);
        }

Output at chart: Lots: 8.00


@dwalkhul