Topics
Forum Topics not found
Replies
amusleh
04 May 2022, 09:00
Hi,
I tested on Spotware cTrader beta nd IC Markets cTrader, both loaded more than 1000 bars on first GetBars call, so there was not even a need for running the loop.
If the LoadMoreHistory returns 0 then it means you already loaded all available bars data from your broker, each broker has different amount of historical data.
@amusleh
amusleh
02 May 2022, 08:49
RE:
seankiaa said:
I have been using:
ClosePosition(position, volume);
Could you clarify if this is supported in back test and has already been implemented?
Hi, Partial close is working fine, use ModifyPosition method:
using cAlgo.API;
using cAlgo.API.Internals;
namespace NewcBot
{
[Robot(AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
protected override void OnStart()
{
var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin * 2);
if (result.IsSuccessful)
{
Print("Order successfully placed, modifying volume");
ModifyPosition(result.Position, result.Position.VolumeInUnits / 2);
}
else
{
Print("Order placement failed");
}
}
protected override void OnStop()
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
}
}
@amusleh
amusleh
28 Apr 2022, 09:21
Hi,
You should declare text box as a field of your cBot/Indicator class, then you will be able to access it from anywhere and change its properties, example:
using cAlgo.API;
namespace NewcBot
{
[Robot(AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
private TextBlock _textBlock;
protected override void OnStart()
{
_textBlock = new TextBlock
{
Text = "Initial text",
ForegroundColor = Color.Red,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Chart.AddControl(_textBlock);
}
protected override void OnTick()
{
_textBlock.Text = "New text";
_textBlock.ForegroundColor = Color.Green;
}
}
}
@amusleh
amusleh
27 Apr 2022, 08:26
Hi,
That error appears because you haven't referenced the GannHighLow indicator, you have to reference it then you will be able to use it on your cBot.
Here is the referencing guide: https://help.ctrader.com/ctrader-automate/guides/indicators#referencing-custom-indicators
@amusleh
amusleh
27 Apr 2022, 08:24
( Updated at: 28 Apr 2022, 09:15 )
Hi,
The code I posted does the same thing but without suspending the thread or causing any delay, that's the fastest possible solution.
Regarding time delay, no there is no such function in API and I don't think there is a need for something like that.
@amusleh
amusleh
27 Apr 2022, 08:22
Hi,
List is part of .NET BCL collections, you can find all you need here: List<T> Class (System.Collections.Generic) | Microsoft Docs
For Linq: Language-Integrated Query (LINQ) (C#) | Microsoft Docs
@amusleh
amusleh
27 Apr 2022, 08:21
Hi,
Try this:
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SampleTrendcBot : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("Source", Group = "Moving Average")]
public DataSeries SourceSeries { get; set; }
[Parameter("Slow MA Sigma", DefaultValue = 0.65, Group = "Moving Average")]
public double SlowMaSigma { get; set; }
[Parameter("Fast MA Sigma", DefaultValue = 0.65, Group = "Moving Average")]
public double FastMaSigma { get; set; }
[Parameter("Slow Periods", Group = "Moving Average", DefaultValue = 10)]
public int SlowPeriods { get; set; }
[Parameter("Fast Periods", Group = "Moving Average", DefaultValue = 5)]
public int FastPeriods { get; set; }
private Vidya slowMa;
private Vidya fastMa;
private const string label = "Sample Trend cBot";
protected override void OnStart()
{
fastMa = Indicators.Vidya(SourceSeries, FastPeriods, FastMaSigma);
slowMa = Indicators.Vidya(SourceSeries, SlowPeriods, SlowMaSigma);
}
protected override void OnTick()
{
var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);
var currentSlowMa = slowMa.Result.Last(0);
var currentFastMa = fastMa.Result.Last(0);
var previousSlowMa = slowMa.Result.Last(1);
var previousFastMa = fastMa.Result.Last(1);
if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
{
if (shortPosition != null)
ClosePosition(shortPosition);
ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
}
else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
{
if (longPosition != null)
ClosePosition(longPosition);
ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
}
}
private double VolumeInUnits
{
get { return Symbol.QuantityToVolumeInUnits(Quantity); }
}
}
}
@amusleh
amusleh
26 Apr 2022, 10:35
RE: RE:
ctid2032775 said:
Hi,
just to eliminate that this is caused by the virtual machine I installed the same version on a dedicated Windows 10 Pro notebook and had exactly the same issue...
So just a few question:
- What are the "minimum requirements" to run cBots compiled with .NET 6 on a "clean" Windows 10 installation?
- Are there logs available to find out the reason of this behavior? (keep in mind that in my case the log tab doesn't show any information)
- What could be the reason that the frondend can be closed after a cBot compiled with .NET 6 was started but the process itself isn't terminated?
- How can I provide you with more detailed information to reproduce the issue and find a fix?
- And finally, does this mean that the current beta version was deployed to be tested by the users and only the "official" broker version will be stable and fully functioning?
Many thanks and regards,
Christian
Hi,
There is no minimum requirements for running or compiling a cBot, as long as cTrader desktop works on your system you should be able to compile and run cBots.
The beta version is for testing, cTrader 4.2 stable version is not released yet for brokers.
Regarding your issue:
1. Which edition of Windows you are using? x64/x86?
2. Rebuild, and run the cBot instance, then submit a troubleshoot report by pressing Ctrl+Alt+Shift+T and paste the forum thread URL on the report text box.
@amusleh
amusleh
26 Apr 2022, 10:18
RE: RE:
firemyst said:
amusleh said:
Hi,
I did understood your point, what I was trying to explain was there is no way to accurately know when a tick will result in formation of a new bar.
Regarding your issue, you can do something like this:
Okay. Cool. Thanks for that and your sample code. I haven't looked at the sample code, but had another question -- with cTrader shouldn't it (or is it already) programmed up to open a new bar regardless of whether or not a tick comes through?
It it takes the timing of a tick to actually open a new bar, then hypothetically bars could open up halfway through their time period, or even not at all.
If it is set to open a new bar regardless of whether a tick or not happens, then the example I provided seems to illustrate a bug where ticks happen before the bar is actually opened.
Thank you.
Hi,
If there is no tick then there will be no bars, cTrader only creates bars if there are any ticks otherwise it will not form any bar and the OnBar method will not be called.
@amusleh
amusleh
04 May 2022, 09:08
Hi,
I was not able to replicate the issue, I back tested the cBot from 17/10/2021 to now, and all placed orders and filled positions had stop loss.
Please post the DOWNTRADEI indicator code, and on which broker you tested the cBot? tick data or m1 bars?
@amusleh