Replies

Hansen
02 Nov 2023, 14:00

RE: How to write GetFitness

PanagiotisCharalampous said: 

Hi there,

You won't get the same results if the fitness function is different

Hi Buddy,

You responese make me look like a fool. 

So do you know the algo of fitness function?

Where is the doc?

Can you get the same results as config of ui interface?

I do know how to write fitness function, but accurate algo is not clear… what a pity. 

 


@Hansen

Hansen
01 Nov 2023, 07:16 ( Updated at: 21 Dec 2023, 09:23 )

RE: How to write GetFitness

PanagiotisChar said: 

Hi there,

You are probably translating to English but your issue is not intelligible. I did not understand what your problem is. Can you please rephrase it providing steps how we can reproduce it?

 

I want the code to produce the same results as the interface settings. So could you give me the algo of standand criteria?

in ctrader Steps:

  1. in optimistion function,
  2. select standand creterion
  3. run
  4. get result1

in code:

  1. override getfintness function
  2. in optimistion function,select custom
  3. run
  4. get result2

I find it hard to let result1 as same as result2


@Hansen

Hansen
31 Oct 2023, 01:23 ( Updated at: 21 Dec 2023, 09:23 )

RE: In Automate: ctrader indicator has 1 tick each bar, but cbot has two tick each bar

PanagiotisChar said: 

Hi Hansen,

Maybe it is better to provide a specific example demonstrating what you are looking at, since what you write is not true

  1. debug any indicator, you will see Calculate method only receive OLHC data when the bar is closed. 

This is not how it works. Calculate is called once for every historical bar and on every tick for the current bar. If you keep executing the Calculate until the bar is closed, then the value for the current bar will become equivalent to the closed bar.

  1. debug any cbot, you will see OnBar method will receive two tick OLHC data, first one occur when the bar is open, second one close the bar.

OnBar is called once every time a new bar is opened.

Sorry for not being clear,let me show you code, this code is from sample ema, i just add a print

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleEMA : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Output("Main", LineColor = "Turquoise")]
        public IndicatorDataSeries Result { get; set; }

        private double exp;

        protected override void Initialize()
        {
            exp = 2.0 / (Periods + 1);
        }

        public override void Calculate(int index)
        {
            Print($"Bars.HighPrices[{index}]={Bars.HighPrices[index]}, Bars.LowPrices[{index}]={Bars.LowPrices[index]}, Bars.OpenPrices[{index}]={Bars.OpenPrices[index]}, Bars.ClosePrices[{index}]={Bars.ClosePrices[index]}");
            var previousValue = Result[index - 1];

            if (double.IsNaN(previousValue))
                Result[index] = Source[index];
            else
                Result[index] = Source[index] * exp + previousValue * (1 - exp);
        }
    }
}

 

the result is 

you can see all the history data only have one output, which behavior will diff if you refer the indicator in the bot, so the calc results

will diff in the end.

I have a work around method for the behavior,  in the indicator method i add this code

        public override void Calculate(int index)
        {
            if (!IsInRealTime)
            {
                try
                {
                 
                    if (Bars.LowPrices[index] == Bars.HighPrices[index]
                        && Bars.LowPrices[index] == Bars.ClosePrices[index]
                        && Bars.LowPrices[index] == Bars.OpenPrices[index]
                       )
                    {
                        return;
                    }

                    ...
                }
                finally
                {
                    IsInRealTime = false;
                }
            }
        }

My purpose is let my backtest result as  same as real transaction, in order to avoid tick data infulence result, i also minus 2 of index in the cbot, is this the best practice? I think this is really ticky, so may ctrader team could give more complex examples.

    protected override void OnBar()
    {

        var index = Bars.Count - 2;
        ...
    }

@Hansen

Hansen
26 Oct 2023, 17:34 ( Updated at: 21 Dec 2023, 09:23 )

GPT3.5 answer...

@Hansen

Hansen
03 Feb 2023, 12:20 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE:

hansenlovefiona said:

Spotware said:

Hi hansenlovefiona,

Can you please provide us screenshots with the exact messages you receive from Kaspersky? It will help us identify the issue with Kaspersky and resolve it.

Best regards,

cTrader Team

I have reinstalled cTrader and worked fine.

But I found all indicators need fullaccess, it may be download worms from this way.


@Hansen

Hansen
03 Feb 2023, 12:17

RE:

Spotware said:

Hi hansenlovefiona,

Can you please provide us screenshots with the exact messages you receive from Kaspersky? It will help us identify the issue with Kaspersky and resolve it.

Best regards,

cTrader Team


@Hansen

Hansen
30 Jan 2023, 13:47

RE:

Spotware said:

Dear trader,

Do you still experience this problem using 4.6.2?

Best regards,

cTrader Team

The problem is still in 4.6.2

The workaround method is set  `AccessRights = AccessRights.FullAccess`.


@Hansen