Topics
Forum Topics not found
Replies
amusleh
11 Jan 2022, 08:37
RE: Code is crashing cTrader
jani said:
Hello,
I tried to use below in an indicator:
Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count); while (Bars.Count < 10000) { var loadedCount = Bars.LoadMoreHistory(); Print("Loaded {0} bars", loadedCount); if (loadedCount == 0) break; } Print("Finished, total bars {0}", Bars.Count);
and it practically crashed my cTrader every time I compiled the code while the indicator was attached to a 1H chart.
Hi,
I just tested your code on Spotware cTrader beta for EURUSD and GBPUSD H1 and it worked fine.
But there is an issue with your code, what if the symbol doesn't have that number of bars? then you will end up with an infinite loop which will crash your cTrader.
You don't know how many bars are available, so if you use a fixed number and symbol doesn't had that number of bars then it will crash your platform.
@amusleh
amusleh
11 Jan 2022, 08:32
Hi,
Each instance of a cBot runs separate from others, one can't have any effect on other running cBots.
Most probably something is wrong with your cBot code, and its not related to running multiple instances.
You should use unique labels for each of your running cBot instances, and use it to only manage the positions and orders that were opened by that instance.
Please post your cBot code then we will be able to help you.
Regarding debugging multiple running instances, right now there is no feasible way to do this.
@amusleh
amusleh
10 Jan 2022, 16:57
RE: RE:
heinrich.munz said:
amusleh said:
Hi,
Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.
The close time of a bar is the open time of next bar, so there is no need for an extra data collection.
For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.
So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.
>>>"The close time of a bar is the open time of next bar"
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick".So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???
Hi,
This issue will be resolved in cTrader 4.2.
@amusleh
amusleh
10 Jan 2022, 15:00
Hi,
Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.
The close time of a bar is the open time of next bar, so there is no need for an extra data collection.
For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.
So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.
@amusleh
amusleh
10 Jan 2022, 11:09
Hi,
I just tested with our QuickFIX console sample and it didn't got disconnected at all after waiting for more than an hour.
@amusleh
amusleh
10 Jan 2022, 08:38
Hi,
Check here: cAlgo API Reference - MarketDepth Interface (ctrader.com)
@amusleh
amusleh
10 Jan 2022, 08:36
RE: Can I backtest strategy with daily data?
duongphuongtrinh92 said:
Hi Spotware,
I would like to backtest a swing trading strategy using Daily Close Price. And the problem is I do not have 1-minute data csv file, I only have daily data. Can I backtest the strategy using this daily csv file?
No, you can't.
You can only import M1 bars data or use the server data.
@amusleh
amusleh
10 Jan 2022, 08:35
Hi,
Try this:
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }
private RelativeStrengthIndex diffRSI;
private IndicatorDataSeries nasdow;
private Bars _nasdaqSeries, _dowjonesSeries;
protected override void OnStart()
{
_nasdaqSeries = MarketData.GetBars(TimeFrame, "US TECH 100");
_dowjonesSeries = MarketData.GetBars(TimeFrame, "US 30");
nasdow = CreateDataSeries();
diffRSI = Indicators.RelativeStrengthIndex(nasdow, Periods);
}
protected override void OnTick()
{
var index = Bars.Count - 1;
var dowjonesSeriesIndex = _dowjonesSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
var nasdaqSeriesIndex = _nasdaqSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
nasdow[index] = _dowjonesSeries.ClosePrices[dowjonesSeriesIndex] - _nasdaqSeries.ClosePrices[nasdaqSeriesIndex];
}
}
}
The "nasdow" series contains the subtraction result of two other series, and you can use it on any indicators.
@amusleh
amusleh
10 Jan 2022, 08:24
Hi,
You can always get the current time by using Server.Time: cAlgo API Reference - IServer Interface (ctrader.com)
@amusleh
amusleh
07 Jan 2022, 15:07
( Updated at: 07 Jan 2022, 15:08 )
RE: RE:
lukas.ourada said:
amusleh said:
Hi,
Did you tried to uninstall/re-install cTrader?
Hi, thanks for you reply.
Yes a try uninstall all version ctrader (roboforex, icm) and instal now clean version. I try too reinstall visual studio 2019, but still not work :-(
Hi,
Try to uninstall/re-install the Visual Studio cBots/Indicators extension: cBots and Custom Indicators - Visual Studio Marketplace
Guide: Find and install extensions - Visual Studio (Windows) | Microsoft Docs
@amusleh
amusleh
07 Jan 2022, 11:37
Hi,
We are aware of this issue and it will be fixed very soon.
In meantime please use our new .NET library and samples: spotware/OpenAPI.Net: Spotware Open API .NET Rx library (github.com)
@amusleh
amusleh
07 Jan 2022, 07:27
( Updated at: 07 Jan 2022, 07:28 )
Hi,
You should use different values for your cBot "Instance Name" parameter for each instance, otherwise all the instances will only open one position.
Or you should change the code at:
private void OpenPosition(string Label, TradeType TradeDirection)
{
//Calculate Trade Amount base on the ATR
var PrevATR = Math.Round(atr.Result.Last(1) / Symbol.PipSize);
var PerTradeadjust = PerTrade / 100;
var TradeAmount = (Account.Equity * PerTradeadjust) / (PrevATR * Symbol.PipValue);
TradeAmount = Symbol.NormalizeVolumeInUnits(TradeAmount, RoundingMode.Down);
///var cBotPositions = Positions.FindAll(InstanceName); not used
if (Positions.Count(x => x.Label == InstanceName) == 0)
{
ExecuteMarketOrder(TradeDirection, SymbolName, TradeAmount, InstanceName, null, null);
}
}
@amusleh
amusleh
07 Jan 2022, 07:23
( Updated at: 21 Dec 2023, 09:22 )
RE: RE:
TheNiatpac said:
Hi Panagiotis,
I just reinstalled my system and started to use Visual Studio 2022. Would you consider supporting the new version soon? or any advice please
Thanks
PanagiotisCharalampous said:
Hi FireMyst,
No ETA at the moment but it should be in one of the upcoming upcoming updates.
Best Regards,
Panagiotis
Hi,
You can use Visual Studio 2022 on cTrader 4.2 which is the next major version of cTrader.
@amusleh
amusleh
11 Jan 2022, 08:40
Hi,
Does it happen only when you subscribe to 80 symbols or it happens always?
Can you try without subscribing to any symbol or just subscribe to 1 symbol, see if it gets disconnected or not.
@amusleh