cBots loading other Symbols' Bars causes CPU in usage even nothing run OnTick() ?
cBots loading other Symbols' Bars causes CPU in usage even nothing run OnTick() ?
08 May 2022, 00:37
Hello,
I have the below code which my cBots need to load other symbols' data OnStart(), and no lines OnTick(). However...
I found my CPU is in steady high (not bursting) usage when I launched 2 cBots in different charts, even when the market is closed. After taking out other lines of the codes, I found that loading other symbols data might be the reason. See below 2 screen chops of comparison. (My CPU is a bit old i7 7th generation, but not the reason causing the issue.)
Can you confirm my guess, and advise any optimising method to reduce CPU usage?
Thanks in advance.
P.S. the test is in TimeFrame.Minute
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TestGroupA : Robot
{
[Parameter("Reset Date", DefaultValue = "2022-05-06", Group = "Alignment" )] public string ResetDate { get; set; }
[Parameter("Reset Time", DefaultValue = "04:29:00", Group = "Alignment" )] public string ResetTime { get; set; }
//Bars to load for Calculate
private Bars EURUSD, EURGBP, EURAUD, EURNZD, EURCAD, EURCHF, EURJPY;
private Bars GBPUSD, GBPAUD, GBPNZD, GBPCAD, GBPCHF, GBPJPY;
private Bars AUDUSD, AUDNZD, AUDCAD, AUDCHF, AUDJPY;
private Bars NZDUSD, NZDCAD, NZDCHF, NZDJPY;
private Bars USDCAD, CADCHF, CADJPY;
private Bars USDCHF, CHFJPY;
private Bars USDJPY;
//Index at OpenTime of LastBar of EachSymbol;
private int in_EURUSD, in_EURGBP, in_EURAUD, in_EURNZD, in_EURCAD, in_EURCHF, in_EURJPY;
private int in_GBPUSD, in_GBPAUD, in_GBPNZD, in_GBPCAD, in_GBPCHF, in_GBPJPY;
private int in_AUDUSD, in_AUDNZD, in_AUDCAD, in_AUDCHF, in_AUDJPY;
private int in_NZDUSD, in_NZDCAD, in_NZDCHF, in_NZDJPY;
private int in_USDCAD, in_CADCHF, in_CADJPY;
private int in_USDCHF, in_CHFJPY;
private int in_USDJPY;
protected override void OnStart()
{
//1.GetBars for EachSymbol
EURUSD = MarketData.GetBars(Bars.TimeFrame, "EURUSD"); GBPUSD = MarketData.GetBars(Bars.TimeFrame, "GBPUSD"); AUDUSD = MarketData.GetBars(Bars.TimeFrame, "AUDUSD"); NZDUSD = MarketData.GetBars(Bars.TimeFrame, "NZDUSD");
EURGBP = MarketData.GetBars(Bars.TimeFrame, "EURGBP"); GBPAUD = MarketData.GetBars(Bars.TimeFrame, "GBPAUD"); AUDNZD = MarketData.GetBars(Bars.TimeFrame, "AUDNZD"); NZDCAD = MarketData.GetBars(Bars.TimeFrame, "NZDCAD");
EURAUD = MarketData.GetBars(Bars.TimeFrame, "EURAUD"); GBPNZD = MarketData.GetBars(Bars.TimeFrame, "GBPNZD"); AUDCAD = MarketData.GetBars(Bars.TimeFrame, "AUDCAD"); NZDCHF = MarketData.GetBars(Bars.TimeFrame, "NZDCHF");
EURNZD = MarketData.GetBars(Bars.TimeFrame, "EURNZD"); GBPCAD = MarketData.GetBars(Bars.TimeFrame, "GBPCAD"); AUDCHF = MarketData.GetBars(Bars.TimeFrame, "AUDCHF"); NZDJPY = MarketData.GetBars(Bars.TimeFrame, "NZDJPY");
EURCAD = MarketData.GetBars(Bars.TimeFrame, "EURCAD"); GBPCHF = MarketData.GetBars(Bars.TimeFrame, "GBPCHF"); AUDJPY = MarketData.GetBars(Bars.TimeFrame, "AUDJPY");
EURCHF = MarketData.GetBars(Bars.TimeFrame, "EURCHF"); GBPJPY = MarketData.GetBars(Bars.TimeFrame, "GBPJPY"); USDCAD = MarketData.GetBars(Bars.TimeFrame, "USDCAD");
EURJPY = MarketData.GetBars(Bars.TimeFrame, "EURJPY"); USDCHF = MarketData.GetBars(Bars.TimeFrame, "USDCHF"); CADCHF = MarketData.GetBars(Bars.TimeFrame, "CADCHF");
USDJPY = MarketData.GetBars(Bars.TimeFrame, "USDJPY"); CHFJPY = MarketData.GetBars(Bars.TimeFrame, "CHFJPY"); CADJPY = MarketData.GetBars(Bars.TimeFrame, "CADJPY");
//2.Get Index# for EachSymbol at Reset-DateTime
DateTime dateTime = DateTime.Parse(ResetDate + " " + ResetTime).Add(-Application.UserTimeOffset); //Convert to ServerTime
in_EURUSD = EURUSD.OpenTimes.GetIndexByTime(dateTime); in_GBPUSD = GBPUSD.OpenTimes.GetIndexByTime(dateTime); in_AUDUSD = AUDUSD.OpenTimes.GetIndexByTime(dateTime); in_NZDUSD = NZDUSD.OpenTimes.GetIndexByTime(dateTime);
in_EURGBP = EURGBP.OpenTimes.GetIndexByTime(dateTime); in_GBPAUD = GBPAUD.OpenTimes.GetIndexByTime(dateTime); in_AUDCAD = AUDCAD.OpenTimes.GetIndexByTime(dateTime); in_NZDCAD = NZDCAD.OpenTimes.GetIndexByTime(dateTime);
in_EURAUD = EURAUD.OpenTimes.GetIndexByTime(dateTime); in_GBPCAD = GBPCAD.OpenTimes.GetIndexByTime(dateTime); in_AUDNZD = AUDNZD.OpenTimes.GetIndexByTime(dateTime); in_NZDCHF = NZDCHF.OpenTimes.GetIndexByTime(dateTime);
in_EURCAD = EURCAD.OpenTimes.GetIndexByTime(dateTime); in_GBPNZD = GBPNZD.OpenTimes.GetIndexByTime(dateTime); in_AUDCHF = AUDCHF.OpenTimes.GetIndexByTime(dateTime); in_NZDJPY = NZDJPY.OpenTimes.GetIndexByTime(dateTime);
in_EURNZD = EURNZD.OpenTimes.GetIndexByTime(dateTime); in_GBPCHF = GBPCHF.OpenTimes.GetIndexByTime(dateTime); in_AUDJPY = AUDJPY.OpenTimes.GetIndexByTime(dateTime);
in_EURCHF = EURCHF.OpenTimes.GetIndexByTime(dateTime); in_GBPJPY = GBPJPY.OpenTimes.GetIndexByTime(dateTime); in_USDCAD = USDCAD.OpenTimes.GetIndexByTime(dateTime);
in_EURJPY = EURJPY.OpenTimes.GetIndexByTime(dateTime); in_USDCHF = USDCHF.OpenTimes.GetIndexByTime(dateTime); in_CADCHF = CADCHF.OpenTimes.GetIndexByTime(dateTime);
in_USDJPY = USDJPY.OpenTimes.GetIndexByTime(dateTime); in_CHFJPY = CHFJPY.OpenTimes.GetIndexByTime(dateTime); in_CADJPY = CADJPY.OpenTimes.GetIndexByTime(dateTime);
//Debugging:
string msg = string.Format("At the Reset-DateTime: {0}", dateTime.Add(Application.UserTimeOffset).ToString("yyyy-MM-dd HH:mm:ss"));
msg += string.Format("\nEURUSD's Index#: {0}", in_EURUSD);
msg += string.Format("\nGBPUSD's Index#: {0}", in_GBPUSD);
msg += string.Format("\n\nCPU is 12% used, even no calculation OnTick()...?");
Chart.DrawStaticText("msg", msg, VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.Aquamarine);
//Debugging END
}
protected override void OnTick()
{
}
protected override void OnStop()
{
}
}
}
Replies
Capt.Z-Fort.Builder
09 May 2022, 11:50
RE:
Thanks for your reply. Your explanation makes sense.
Interestingly, I found if I minimize the window, the CPU usage gets back to a normal level, when cBots keeps on. Anyway, it's not a big issue.
Thanks again.
amusleh said:
Hi,
CPU usage can be related to lots of things, and you can't micro manage it.
When you load the bars of multiple symbols it subscribes to their incoming bars and that can increase slightly the CPU usage even if market is closed.
The cTrader CPU usage on Task manager is not just the amount of CPU cycles that is used by your cBot.
@Capt.Z-Fort.Builder
amusleh
09 May 2022, 08:59
Hi,
CPU usage can be related to lots of things, and you can't micro manage it.
When you load the bars of multiple symbols it subscribes to their incoming bars and that can increase slightly the CPU usage even if market is closed.
The cTrader CPU usage on Task manager is not just the amount of CPU cycles that is used by your cBot.
@amusleh