GetFitnessArgs return value stored in a variable

Created at 23 Jun 2015, 05: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!
kricka's avatar

kricka

Joined 13.03.2013

GetFitnessArgs return value stored in a variable
23 Jun 2015, 05:23


Hi,

I would like the return value stored in a variable or printed to the log, is that a possibility?

 

protected override double GetFitness(GetFitnessArgs args)

{

return args.WinningTrades / args.LosingTrades;//maximize count of winning trades and minimize count of losing trades

}

Thanks


@kricka
Replies

Spotware
23 Jun 2015, 12:58

Dear Trader,

It is possible to store a return value of a method in a variable, or print it to the log. The following code snippet illustrates it.

        private double Example(int temp1, int temp2)
        {
            double temp3 = 0;
            //do some calculations
            return temp3;
        }

double divide = Example(10,20);
Print("", Example(70, 10));

We hope this helps you.


@Spotware

kricka
24 Jun 2015, 19:00

No print to the log

Tried the above example, and could not print the return value. So maybe its not a possibility within GetFitnessArgs to do so. If you have another snippets or workaround that works to get the GetFitnessArgs calculation printed, I would be thankful.

protected override double GetFitness(GetFitnessArgs args)

    {

        double temp1 = 0;

        return args.WinningTrades / args.LosingTrades;

        return temp1;

        print (temp1); // should print the return to the log.
        }

 


@kricka

Spotware
25 Jun 2015, 10:16

Dear Trader,

The value cannot be printed in the way you wrote the method because the Print(…) method is written after the return statement of the method. Please note that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.

 


@Spotware

kricka
25 Jun 2015, 21:13

Not a matter of coding assistant

Dear Spotware,

this is not a matter of getting coding assistant from your providers, this is more a lack of information from your side given in the API documentation about GetFitnessArgs. How to retrieve information and how to use it the right way. By updating the API documentation you will have less questions from us and what is possible to do with it. I have not still gotten a satisfied working answer from you how to store the GetFitnessArgs calculation in a variable and print it to the log.


@kricka

Spotware
29 Jun 2015, 15:06

Dear Trader,

Regarding GetFitnessArgs please take a look at the following reference: http://help.spotware.com/calgo/cbots/optimization#optimization-criteria

We hope this helps you.


@Spotware

kricka
29 Jun 2015, 21:25

Awesome calculation using GetFitnessArgs

Thanks for the link but it's not what I'm really after. GetFitnessArgs I know is made to be able to optimize back testing and that is just great. I see GetFitnessArgs also can be used in other ways that can shorten the programming time by 1/10th. If the calculation can be stored and printed to the log or displayed on the screen using  ChartObjects.DrawText. Awesome calculation can then be done using the  GetFitnessArgs. Hope you understand my interest in it :).


@kricka

Spotware
01 Jul 2015, 12:18

Dear kricka,

the following code snippet shows you how to print the fitness to the log.

        protected override double GetFitness(GetFitnessArgs args)

       {

           double result = args.WinningTrades / args.LosingTrades;

           Print(result);

           return result;

       }

You cannot draw the result of GetFitness in a Chart because it runs at Optimization where there is no price chart. We hope this helps you.


@Spotware

kricka
02 Jul 2015, 07:43

No print still

If you can print it you should be able to store the print in a variable and display it on the screen by using ChartObjects.DrawText. I am not getting any printout whatsoever to the log, can't see it physical anyways. Either I am doing something that is wrong or you are not explaining it the right way, or it is not possible to print the calculation to the log. Please give the above example included in a standard cBot template how to get the GetFitnessArgs printed to the log. I would then be really happy to get this thing working.


@kricka

Spotware
02 Jul 2015, 10:10

Dear kricka,

As explained in the above messages, you cannot draw the result of GetFitness in a price chart because it runs at Optimization where there is no price chart. The previous code snippet shows you how to print the fitness to the log, you can copy paste it into your cBot and check it and make your modifications. If you write any lines after the return statement they will not be executed. We advise you to print the result prior returning it. Note that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

hossein.shobeyri
02 Apr 2018, 23:45

RE:

Spotware said:

Dear kricka,

As explained in the above messages, you cannot draw the result of GetFitness in a price chart because it runs at Optimization where there is no price chart. The previous code snippet shows you how to print the fitness to the log, you can copy paste it into your cBot and check it and make your modifications. If you write any lines after the return statement they will not be executed. We advise you to print the result prior returning it. Note that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.

I want to useing getfitnessArgs parameter in my custom andicator and create mony mamagment indicator with them.

how can i do that

want to print Profit Factor or win rate or ... in top of the chart

please help me


@hossein.shobeyri