Topics
28 May 2022, 06:27
 952
 5
Replies

YC1186
14 Sep 2022, 05:12 ( Updated at: 14 Sep 2022, 05:14 )

RE: RE:

prosteel1 said:

PanagiotisCharalampous said:

Hi there,

Obviously something has changed in the API between 4.1 and 4.2 but this does not mean it's a bug. But in order to advise where the change is, evaluate if it is a bug or an impreovement, and how address it, I need a small code sample that reproduces the problem. Unfortunately I cannot spend hours undestanding and debugging your code to figure out what is calcuated differently.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Panagiotis and YC1186,

Small code sample below. The following code works, but breaks when the OnBar line is commented out.

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 a2DumptoCSVJan2022Works : Robot
    {
        [Parameter("Periods", Group = "RSI", DefaultValue = 24)]
        public int Periods { get; set; }

        private RelativeStrengthIndex RSI;
        double _RSI;
        
        protected override void OnStart()
        {
            RSI = Indicators.RelativeStrengthIndex(Bars.OpenPrices,Periods);
        }
        
        protected override void OnBar()
        {
            // Comment out following line to produce NaN
            _RSI = RSI.Result.LastValue;
        }

        protected override void OnStop()
        {
            for (var i = Periods; i <= Bars.ClosePrices.Count; i++)
            {
                Print(i + " " + RSI.Result[i-1]);
            }
        }
    }
}

 


Freakin finally! that's seal the deal.. Great.. Don't know why it doesn't populate or initiate the values with the old good index call like [t-50] or so but it's ridiculous if for every indicator or oscillator used we gonna need to used that Result.LastValue call, so i hope there's some system guys here to fix that very annoying bug that bugs me for like a month and a half and of course nowhere to be found a fix for it.. 

Many thanks Pro-steel1 for solving that issue.. 
 


@YC1186

YC1186
06 Sep 2022, 15:08

RE:

PanagiotisCharalampous said:

Hi there,

I am not sure how to make it simpler. You ask me to reverse engineer and debug a 250 lines cBot to understand if there is a problem with the code or with cTrader. Unfortunately I cannot. If you can provide a simpler cBot that has the same problem, I am happy to look at it.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Not actually Reverse engineering it, but conceptualy how to figure it... I guess that whatwe need here is an expert with the cTrader systems more than in C# coding or programming, cause again, maybe the bug isn't even in my code.. which is most likely, as it works perfectly on 4.1 system that doesn't have the .net 6 or other versions of it that may cause the problem..


@YC1186

YC1186
06 Sep 2022, 14:31

RE:

PanagiotisCharalampous said:

Hi there,

What do you mean by small code sample? How do you "Shrink" a code without affecting of it's functionality and what it is actually?

A code example with 10-20 lines ago that can reproduce this discrepancy between 4.1 and 4.2.

And again, if the problem is at the code at all, based on the facts that this exact code working perectly on CT4.1 machine, and it does throws good values on specific WMA96 series, implies strongly again that the problem isn't at the code at all, any maybe at the API or the server i don't know but it's really odd one..

I addressed this im my response above.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Still don't understand what you mean... How can i write a code that reproduce the discrepancy if i don't even know if there's any discrepancy [let alone the relevant one] between 4.1 and 4.2? and for sure i can't know what it is.. And what you mean by 10-20 line ago?.. You are making a lot of non sense here.. and BTW, the main first version of this code i downloaded long ago from this very website, called Dump to CSV... So there's shouldn't be any complexity or weird stuff here..


@YC1186

YC1186
06 Sep 2022, 12:42

RE:

PanagiotisCharalampous said:

Hi there,

Obviously something has changed in the API between 4.1 and 4.2 but this does not mean it's a bug. But in order to advise where the change is, evaluate if it is a bug or an impreovement, and how address it, I need a small code sample that reproduces the problem. Unfortunately I cannot spend hours undestanding and debugging your code to figure out what is calcuated differently.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

What do you mean by small code sample? How do you "Shrink" a code without affecting of it's functionality and what it is actually? i think it can be very simple by sort of Reverse Engineering it, like we know where the problem is, at the WMAX.Result[i-1], so from here back, maybe the declaration of the private WeightedMovingAverage WMA0; should be readonly and/or public there's many possibilities but we know where the problem is..

 

And again, if the problem is at the code at all, based on the facts that this exact code working perectly on CT4.1 machine, and it does throws good values on specific WMA96 series, implies strongly again that the problem isn't at the code at all, any maybe at the API or the server i don't know but it's really odd one..


@YC1186

YC1186
06 Sep 2022, 11:02

RE:

I Just tried copy the exact same code from the Laptop which there it's good with the 4.1 version of cT, and oddly enough it's just working on the WMA96.Result[t-1].. And it's all the exact same code and formations for all of the indicators..

 


@YC1186

YC1186
06 Sep 2022, 10:45

RE:

PanagiotisCharalampous said:

Hi there,

If you can simplify the code, we can check what happens. At the moment it is very complicated and will take a long time for somebody to figure out what is going on.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi.. Thanks for your reply..

 

Actually i don't think it's about the code, since it's the same code that i have in my Laptop which there it works but it runs the cTrader 4.1 which i guess it's because it doesn't have the .net 6, so it's most probably not with the code but i added it cause any expert on the platform know where to look for the error causing code, like there's no way it's double not assigned as private or public or so.. and i saw bigger and more complex code snips so i think it's not that big / complex, i don't know how to simplify it, but the NaN values i get is in all the indicators like     WMA0.Result[i-1],
                            WMA1.Result[i-1],
                            WMA2.Result[i-1],
                            WMA50.Result[i-1],
                            WMA96.Result[i-1] Throws NaN values..


@YC1186

YC1186
06 Jun 2022, 17:45

RE:

amusleh said:

Hi,

No, there is no available data to know how a position is closed, you can check the position close reason inside position closed event but it only gives you information on what caused the position to close, not by who.

Regarding adding comment or label, yes it's possible, both comment and label are available for Positions and orders, you can set comment for a position either by using create new position window on cTrader or with automate API, labels are only available for API.




Also i'm pretty sure there's some way to know how a position has been closed.. It should be very simple programatically to know if it's been closed manually or by a bot..


@YC1186

YC1186
30 May 2022, 09:51

RE:

amusleh said:

Hi,

No, there is no available data to know how a position is closed, you can check the position close reason inside position closed event but it only gives you information on what caused the position to close, not by who.

Regarding adding comment or label, yes it's possible, both comment and label are available for Positions and orders, you can set comment for a position either by using create new position window on cTrader or with automate API, labels are only available for API.


Hi.. thanks for the reply..

So how i do this?.. see the position closed event details? Also i just saw the comment small window below the Stop Lim orders on the PO box.. missed it as i so used for that window LOL... thanks for the enlighting also...






 


@YC1186

YC1186
24 Dec 2020, 23:52

RE:

Hi.. Thanks and sorry for the late reply.. So how do i do that? Running this code on backtesting? And how far back i cab go?..

Thanks..

 

 

AndreiPisarev said:

Run following code in Backtesting using Tick Data from Server
You will get .csv file with tick data history.

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class NewcBot : Robot
{
    private StringBuilder sb = new StringBuilder();

    protected override void OnTick()
    {
        sb.AppendLine(string.Format("{0},{1},{2}", Time.ToString("dd.MM.yyyy HH:mm:ss.fff"), Bid, Ask));
    }

    protected override void OnStop()
    {
        var filePath = string.Format("c:\\temp\\{0}.csv", SymbolName);
        File.WriteAllText(filePath, sb.ToString());
    }
}

 

 


@YC1186

YC1186
28 Jul 2020, 19:04

RE:

PanagiotisCharalampous said:

Hi mahnas2869,

You can get both Bid and Ask prices in backtesting, hence you can calculate the spread as well. See below 

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

namespace cAlgo.Robots
{
    [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()
        {
            Print("Ask: " + Symbol.Ask);
            Print("Bid: " + Symbol.Bid);
            Print("Spread: " + Math.Round(Symbol.Ask - Symbol.Bid, Symbol.Digits));
        }

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

 

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi.. That's the code for the current BidAsk, i meant for the Historical Spreads..


@YC1186