Function in OnStart() function.

Created at 22 Jan 2018, 00:23
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!
XX

Function in OnStart() function.
22 Jan 2018, 00:23


I am trying to define the function for readable code.

something like this.

 protected override void OnStart()
        {
......
int innerFunc(int n) {
        int i = n * 10;
        return i;
      };
      
.....
        }

but I can't compile this.

Any Idea?


@xxxhailmaryxxx@gmail.com
Replies

PanagiotisCharalampous
22 Jan 2018, 12:31

Dear Trader,

Thanks for posting in our forum. Functions cannot be defined within another function. See below how to define a new function in a cBot.

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

        protected int newFunction(int n)
        {
            int i = n * 10;
            return i;
        }
    }
}

Let me know if the above helps you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

xxxhailmaryxxx@gmail.com
22 Jan 2018, 19:03

Thank you!!!


@xxxhailmaryxxx@gmail.com