Topics
02 Aug 2024, 08:40
 330
 8
14 Jul 2024, 19:24
 1
 280
 0
10 Jul 2024, 20:06
 1
 282
 0
14 Jun 2024, 20:33
 306
 2
Replies

ncel01
02 Feb 2023, 18:26 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: RE: RE: RE: RE: RE:

Goulk said:

ncel01 said:

Goulk said:

ncel01 said:

Goulk said:

ncel01 said:

Goulk said:

 Hello everyone,
 
 I have a code able to close a group of positions "BUY - SELL" with positive profit.
 Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?


if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0)
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID)
ClosePosition(position);
}

Thank you for your time

Hi Goulk,

NetProfit should already reflect all the costs deducted:

NetProfit = GrossProfit - Swaps - Comissions

If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.

When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest

 

Hi Goulk,

I am not sure about comissions but swaps are not taken into account when backtesting.

That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.

Ok thanks ncel01.
This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how?
Thank you for your time.

Hi Goulk,

I don't think it is possible to add it directly but it should be possible to somehow account for it.

What I would do:

I'd code the bot to reduce the distance to TP by the number of pips applied to swaps on a daily basis.

Cons:

Costs associated to the swaps will only be reflected when the positions close.

Some brokers apply a 3-day swap on wednesdays. You can also adjust this programmatically.

Alternatively (easier):

I'd increase the commissions to compensate this. I told you I was not sure about comissions but these are definitely considered when backtesting and can be defined by the user.

Cons: not so accurate.

I hope this helped.

Ncel01,

Thanks for the answers,

At this point, I wonder if it is possible to use the . GrossProfit to make the backtest equal to LIVE.

Is SWAP considered in the .GrossProfit "LIVE" ?

Thank you.

Goulk,

GrossProfit is only based on the distance I guess, so the results should match in this case.

Why do you want and exact match between backtest and a real-time run, if I may ask?


@ncel01

ncel01
02 Feb 2023, 13:59

RE:

PanagiotisChar said:

Hi ncel01,

Did you try Force GC? What happens? Sometimes it justs takes time for .Net to release unused resources.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

Hi Panagiotis,

No, I didn't.

I've read about it but I didn't try it yet as I am not sure when to call it nor I am sure what conditionals to use.

I am also not sure if this will work since all the memory is being used by the main process and not by the algohost process.

Any tips?

Thank you!


@ncel01

ncel01
02 Feb 2023, 08:28 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: RE: RE: RE:

Goulk said:

ncel01 said:

Goulk said:

ncel01 said:

Goulk said:

 Hello everyone,
 
 I have a code able to close a group of positions "BUY - SELL" with positive profit.
 Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?


if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0)
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID)
ClosePosition(position);
}

Thank you for your time

Hi Goulk,

NetProfit should already reflect all the costs deducted:

NetProfit = GrossProfit - Swaps - Comissions

If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.

When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest

 

Hi Goulk,

I am not sure about comissions but swaps are not taken into account when backtesting.

That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.

Ok thanks ncel01.
This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how?
Thank you for your time.

Hi Goulk,

I don't think it is possible to add it directly but it should be possible to somehow account for it.

What I would do:

I'd code the bot to reduce the distance to TP by the number of pips applied to swaps on a daily basis.

Cons:

Costs associated to the swaps will only be reflected when the positions close.

Some brokers apply a 3-day swap on wednesdays. You can also adjust this programmatically.

Alternatively (easier):

I'd increase the commissions to compensate this. I told you I was not sure about comissions but these are definitely considered when backtesting and can be defined by the user.

Cons: not so accurate.

I hope this helped.


@ncel01

ncel01
02 Feb 2023, 00:24 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: RE:

Goulk said:

ncel01 said:

Goulk said:

 Hello everyone,
 
 I have a code able to close a group of positions "BUY - SELL" with positive profit.
 Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?


if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0)
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID)
ClosePosition(position);
}

Thank you for your time

Hi Goulk,

NetProfit should already reflect all the costs deducted:

NetProfit = GrossProfit - Swaps - Comissions

If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.

When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest

 

Hi Goulk,

I am not sure about comissions but swaps are not taken into account when backtesting.

That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.


@ncel01

ncel01
01 Feb 2023, 16:39

RE:

Goulk said:

 Hello everyone,
 
 I have a code able to close a group of positions "BUY - SELL" with positive profit.
 Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?


if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0)
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID)
ClosePosition(position);
}

Thank you for your time

Hi Goulk,

NetProfit should already reflect all the costs deducted:

NetProfit = GrossProfit - Swaps - Comissions


@ncel01

ncel01
01 Feb 2023, 14:10

RE:

PanagiotisChar said:

Hi ncel01,

What you describe is a somewhat expected behavior. More activity on the market, more incoming ticks, more bars on the chart, more memory used. Sometimes resources is the price to pay for advanced features and modern technology. Nevertheless there is always some room for improvements. I am sure this will become better and better with every update of cTrader.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

Hi Panagiotis,

Thanks for your feedback.

In one hand I understand the behaviour. On the other hand, I don't see that memory is released in the same proportion when market gets more inactive. As result, memory usage increases over time.

The main issue is not the high memory usage itself but the fact that there is clearly a cumulative trend.

Unfortunately, there is no option to disable features that can mainly contribute for a high memory usage.

For instance, if I only want to run cBots there is no need to have memory resources used on some other features like charts, etc.

It would be nice to have dynamic settings (that can be saved/exported) available in the future, so that you can reduce/optimize the hardware usage by only selecting the features you really need for the purpose. This gets even more relevant when considering a multi-instance app like cTrader.

Additionally, or alternatively, an option to disable any of the main tabs (Trading, Copy, Automate, Analyze) would be also great.

I am aware that asking for improvements is much easier than implementing these, however, suggestions are never too many, I believe.

I obviously do not think that the app is bad. In fact the app is great and I am posting because I also believe it will get better and better. However, I hope that priority will be given to the memory management in the future.

Regards.


@ncel01

ncel01
01 Feb 2023, 11:55

RE:

Spotware said:

Dear trader,

Unfortunately we cannot know what is the exact cause of this behavior on your system. Our team is working on improving memory management for future releases of cTrader.

Best regards,

cTrader Team

Hi team,

Many thanks for the feedback!

I believe this behaviour is not limited to my system but a general issue with cTrader since this is happening in both my laptop and the VPS.

It's really good to know that you're working on this!

Regards.

Tip: I've noticed that memory usage is somehow correlated with the market behaviour, as an increase in RAM usage is more evident in the busiest hours (market opening/closing times).


@ncel01

ncel01
31 Jan 2023, 10:35 ( Updated at: 21 Dec 2023, 09:23 )

RE: cTrader memory leaks (clean run)

ncel01 said:

Hello,

The screenshot below shows the merory used by cTrader over time.
This was a cTrader clean run, without any action taken by the user. No cBots runniung, etc.

It is shown that, after cTrader is lauched, the RAM usage is about 350MB, while after 50 hours 1GB is being used. Memory usage has tripled in only 50 hours without any activity!!
As you might understand, it is impossible to handle such a situation for much longer, even with very kind hardware resources.

  • What's the reason for this?
  • Is there any solution for this?

Thanks for assisting.

cTrader version tested: 4.6.2

Hello,

Is there any update on this?

Thanks.


@ncel01

ncel01
30 Jan 2023, 01:23

RE:

Spotware said:

Hi ncel01,

We can't investigate what happens if we do not receive the information we asked for.

Best regards,

cTrader Team

 

Dear Spotware team,

I see that you hardly consider the scenario in which this can be an issue with the platform itself.

Please refer to the thread below, mentioning the same issue, now on a cTrader clean run (where cbots are no longer part of the equation).

Thank you.

 


@ncel01

ncel01
23 Jan 2023, 16:17

RE:

Spotware said:

Hi ncel01,

No we can't. We can only investigate this if we have the cBot code.

Best regards,

cTrader Team

Dear Spotware,

Any comments on the fact that memory is not released OnStop()? Is this something I should consider in the code?

FYI: I don't have any memory issues when backtesting. RAM usage remains stable (constant).

How can this be an issue with the cBot code then?

Thanks for clarifying.


@ncel01

ncel01
23 Jan 2023, 16:13

RE:

tadas8891 said:

Try running cTrader as "Run as administration" it fixed my problems. Its still freezes sometimes, but like once every 5-6h instead of every 5-15min. 

Hi tadas8891,

Thanks for your post. However, as far as I can see, there were no improvements at all.


@ncel01

ncel01
20 Jan 2023, 13:44

RE:

Spotware said:

Hi ncel01,

No we can't. We can only investigate this if we have the cBot code.

Best regards,

cTrader Team

Hi Spotware,

Let me see what I can do. The code is really huge and I don't really believe that someone will be happy to look at 5k lines of code.

Anyway, I am still wondering if cAlgo methods, OnTick(), OnBar(), etc., are managing memory properly since RAM is not even released OnStop() and, I guess, this should be something for any user not to worry about.

Please provide an option to disable the journal. It would be interesting to see if there is some improvement on memory usage by doing so.

Suggestion: please name the journal folder with the correct broker name (not always Spotware).

Thank you.


@ncel01

ncel01
19 Jan 2023, 13:36

RE:

Spotware said:

Hi ncel01,

Memory leaks in the main process can be caused by an algo too. If you can share the source code with us, we would be happy to have a look and determine the root of the problem.

Best regards,

cTrader Team

Hi Spotware,

Are you able to check if the issue is really caused by any cBots through a troubleshooting?

How do you explain that memory is not even released OnStop()?

Thank you.


@ncel01

ncel01
19 Jan 2023, 10:50 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Spotware said:

Hi to both,

Cross broker cTrader has been updated to v4.5.6. Please let us know if you still experience this issue with the latest version.

Best regards,

cTrader Team

Dear Spotware team,

 

Apparently the issue with high RAM usage does not lie on the cBots but on cTrader itself, since the memory taken by algohost process remains very low, as shown..

Could you please assist with this issue?

Please understand that this is a very limitative issue which invalidates any attempt to perform algorithmic trading.

Thanks for assisting.

cTrader v4.5.7:

 


@ncel01

ncel01
17 Jan 2023, 22:08 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Spotware said:

Hi to both,

Cross broker cTrader has been updated to v4.5.6. Please let us know if you still experience this issue with the latest version.

Best regards,

cTrader Team

 

Dear Sportware Team,

Thanks for your feedback.

About cTrader v4.5.6:

It looks like there is some improvement on RAM management (lower usage/slower increase over time), however, in my opinion, there is still a lot to do:

  • (1): I can still notice an intermitent non-response from cTrader process. Although it is hard to specify how often this happens and its duration, let's say (5sec/min).
  • (2): New (distinct) exceptions popped up:
    • Apparently, these did not cause a major issue (cTrader continued to running), however these are exceptions anyway, meaning that something went wrong.

  • (3): RAM usage is still increasing over time. It looks like RAM is still not being released on an effective/efficient way.
    • Evidence #1: When stoping all the running cBots the RAM usage remains the same.
    • Evidence #2: By opening a new cTrader instance without any activity, it is possible to verify that RAM usage also increases over time. Moreover, the RAM usage is already ~600Mb after the app is launched. As you can imagine, this gets even more critical when running multiple instances of cTrader.

Suggestion:

Why not providing an option to disable some of the features (which are currently enabled by default) to decrease the RAM usage? For instance, it is quite possible that someone only wants to run cBots on a certain instance. In this case, why to have all the features available and taking resources (which will be multiplied by the number of running instances)? If a trader only wants to run cBots on a certain instance of cTrader, the tabs Trade, Copy and Analyse are not exactly a requirement (from the user point of view) and could be suspended/disabled.
In my case, I don't even need any charts to be available on the Automaded section.

Although this can help reducing the RAM usage, it won't solve its growth over time, I am afraid.

So, additionaly to the above, I believe that some improvements are required so that RAM is effectively released, otherwise, it will continue to increase over time to a point where cTrader will inevitably crash.

Please consider RAM management and performance as the highest priorities for the upcoming cTrader updates. After all, this is all about reliability and, as you may know, reliability is one of the main aspects for any app and, when it comes to a trading app, this becomes the core attribute as things can really go wrong!

 

Looking forward to hearing from you.

Thank you once again!


@ncel01

ncel01
12 Jan 2023, 15:09 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: RE: Massive RAM Usage

Hi notzen, David,

I've also noticed an intermittent "not responding" from cTrader process, even if a significant amount of RAM is still available in the system (40%).

Additionally, I often see "DISCONNECTED" mentioned in the journal, although, I don't really think the connection has ever been lost.

Maybe both are related, I don't really know.

Have you also noticed some of these issues?

 

notzen said:

This issue was already posted time ago in the chat , just using netbrains dotmemory you can see the issues , this off course keeps increasing , I reach 14 GB of ram occupied by ctrader at the end ..

 

david.siciliano said:

david.siciliano said:

I can also confirm that since the release of cTrader desktop version 4.2, memory usage has become a critical issue. Just running cTrader desktop alone without executing and running any cBots will see a gradual increase in memory usage until the application becomes unresponsive. Currently I have to restart cTrader at least once a day.

If this issue could be given high priority it would be much appreciated.

Many thanks.

To Spotware,

Just to add, prior to the cTrader 4.2 and above upgrades, I was able to run 5 cBot instances on a Beeks VPS with 2GB RAM running Windows 2012 without any trouble at all. Excessive memory usage wasn't an issue. Has cTrader version 4.2 and above with all the new changes been able to run on Windows 2012 okay when conducting your testing? Not sure if the earlier Windows OS could be the issue.or not. 

Many thanks.

 

 


@ncel01

ncel01
12 Jan 2023, 09:46

RE: RE:

Dear Spotware,

Is the RAM used by the cBots only reflected in the algohost process?

If this is the case, these are definitely not the reason for such high RAM usage, as we can see in the screenshot above.

 

ncel01 said:

Dear Spotware,

I've already submitted this information.

I did this 3 times:

Twice for the issue mentioned above and a third time for an exception that, in the meantime has popped up.

RAM usage seems to get cumulative overtime without any apparent reason, to a point that app gets unresponsive or, eventually, crashes.

Note: This does not take days to happen but only a few hours!

Thank you.

 

Spotware said:

Dear traders,

Please send us troubleshooting information the next time this happens. Please paste a link to this discussion inside the text box.

Best regards,

cTrader Team

 

 


@ncel01

ncel01
12 Jan 2023, 09:29

RE:

Dear Spotware,

I've already submitted this information.

I did this 3 times:

Twice for the issue mentioned above and a third time for an exception that, in the meantime has popped up.

RAM usage seems to get cumulative overtime without any apparent reason, to a point that app gets unresponsive or, eventually, crashes.

Note: This does not take days to happen but only a few hours!

Thank you.

 

Spotware said:

Dear traders,

Please send us troubleshooting information the next time this happens. Please paste a link to this discussion inside the text box.

Best regards,

cTrader Team

 


@ncel01

ncel01
04 Jan 2023, 14:54 ( Updated at: 21 Dec 2023, 09:23 )

RE:

Dear Spotware team,

Thanks for the prompt reply.

1.



2. I've created this from Task Manager (Windows 11) for the following processes:

  • cTrader
  • algohost
  • Console Window Host

3. I'll proceed accordingly when applicable and mention to this thread.

 

Spotware said:

Dear ncel01,

Thank you for reporting this issue to us. Unfortunately we were not able to determine the root cause of the problem. If possible, please follow the steps below and provide us with the requested information

  1. Open a command prompt and run dotnet --list-sdks. Send us a screenshot with the installed SDKs
  2. Configure PC to create dump file for any application error. See https://www.meziantou.net/tip-automatically-create-a-crash-dump-file-on-error.htm
  3. when the error is reproduced, the dump will be automatically saved to the folder specified in the link above. Send this file to us at community@ctrader.com.

Best Regards

cTrader Team

 

 


@ncel01

ncel01
03 Jan 2023, 16:12

RE:

Hi Panagiotis,

Yes, indeed. You've been always so helpful here that I've overlooked that.

I'll suggest for this.

 

PanagiotisChar said:

Hi ncel01,

I don't work for Spotware anymore. You can use the Suggestions section :) 

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@ncel01