Topics
Replies
guillermo
03 Oct 2020, 23:26
RE: RE:
fernandopaivabr said:
I've already posted there but I can't get a solution. Could you help me ?
Hi,
this is the way I do it. I do not know if there is a better way, but this works for me.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
public class Trinity : Indicator
{
[Parameter("Thickness", DefaultValue = 3, MinValue = 1, MaxValue = 5)]
public int Thickness { get; set; }
private WeightedMovingAverage trendWma;
private WeightedMovingAverage slowWma;
private HullMovingAverage fastHma;
protected override void Initialize()
{
this.trendWma = Indicators.WeightedMovingAverage(Bars.ClosePrices, 500);
this.slowWma = Indicators.WeightedMovingAverage(Bars.ClosePrices, 100);
this.fastHma = Indicators.HullMovingAverage(Bars.ClosePrices, 30);
for (int index = 0; index < Bars.Count; index++)
{
Chart.RemoveObject("trendup" + index);
Chart.RemoveObject("trenddown" + index);
Chart.RemoveObject("slowup" + index);
Chart.RemoveObject("slowdown" + index);
Chart.RemoveObject("fastup" + index);
Chart.RemoveObject("fastdown" + index);
}
}
public override void Calculate(int index)
{
if (index > 0)
{
if (this.trendWma.Result[index] > this.trendWma.Result[index - 1])
{
Chart.RemoveObject("trendup" + index);
Chart.DrawTrendLine("trendup" + index, index - 1, this.trendWma.Result[index - 1], index, this.trendWma.Result[index], Color.Lime, this.Thickness);
}
if (this.trendWma.Result[index] < this.trendWma.Result[index - 1])
{
Chart.RemoveObject("trenddown" + index);
Chart.DrawTrendLine("trenddown" + index, index - 1, this.trendWma.Result[index - 1], index, this.trendWma.Result[index], Color.Red, this.Thickness);
}
if (this.slowWma.Result[index] > this.slowWma.Result[index - 1])
{
Chart.RemoveObject("slowup" + index);
Chart.DrawTrendLine("slowup" + index, index - 1, this.slowWma.Result[index - 1], index, this.slowWma.Result[index], Color.Lime, this.Thickness);
}
if (this.slowWma.Result[index] < this.slowWma.Result[index - 1])
{
Chart.RemoveObject("slowdown" + index);
Chart.DrawTrendLine("slowdown" + index, index - 1, this.slowWma.Result[index - 1], index, this.slowWma.Result[index], Color.Red, this.Thickness);
}
if (this.fastHma.Result[index] > this.fastHma.Result[index - 1])
{
Chart.RemoveObject("fastup" + index);
Chart.DrawTrendLine("fastup" + index, index - 1, this.fastHma.Result[index - 1], index, this.fastHma.Result[index], Color.Lime, this.Thickness);
}
if (this.fastHma.Result[index] < this.fastHma.Result[index - 1])
{
Chart.RemoveObject("fastdown" + index);
Chart.DrawTrendLine("fastdown" + index, index - 1, this.fastHma.Result[index - 1], index, this.fastHma.Result[index], Color.Red, this.Thickness);
}
}
}
}
}
@guillermo
guillermo
26 Aug 2019, 10:49
This is the workaround I am using until they fix this bug:
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.WEuropeStandardTime, AccessRights = AccessRights.None)] public class xxx : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } private DateTime lastOpenTime; protected override void OnStart() { this.lastOpenTime = MarketSeries.OpenTime.LastValue; Print("start " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } protected override void OnTick() { if (!MarketSeries.OpenTime.LastValue.Equals(this.lastOpenTime)) { myOnBar(); this.lastOpenTime = MarketSeries.OpenTime.LastValue; } } private void myOnBar() //protected override void OnBar() { Print("onbar " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } } }
@guillermo
guillermo
21 Aug 2019, 13:16
This issue occurs when I run the robots on a demo account. On a live account it works fine.
@guillermo
guillermo
20 Aug 2019, 10:02
In my previous post I forgot to mention that I am using the broker IC Markets.
I left the program running overnight, and this is the printout that I get for M5. Very weird.
Time (UTC+2) | Message 20/08/2019 08:30:00.401 | onbar 22:05 20/08/2019 08:25:00.401 | onbar 22:05 20/08/2019 07:35:01.974 | onbar 22:05 20/08/2019 07:30:03.740 | onbar 22:05 20/08/2019 06:35:01.044 | onbar 22:05 20/08/2019 06:30:04.231 | onbar 22:05 20/08/2019 06:25:00.280 | onbar 22:05 20/08/2019 06:20:07.967 | onbar 22:05 20/08/2019 06:15:00.264 | onbar 22:05 20/08/2019 06:05:02.747 | onbar 22:05 20/08/2019 05:35:00.724 | onbar 22:05 20/08/2019 04:35:03.562 | onbar 22:05 20/08/2019 04:10:11.098 | onbar 22:05 20/08/2019 04:00:01.602 | onbar 22:05 20/08/2019 03:50:00.788 | onbar 22:05 20/08/2019 03:45:00.460 | onbar 22:05 20/08/2019 03:35:04.917 | onbar 22:05 20/08/2019 02:35:00.220 | onbar 22:05 20/08/2019 02:30:00.612 | onbar 22:05 20/08/2019 02:15:03.082 | onbar 22:05 20/08/2019 01:15:04.469 | onbar 22:05 20/08/2019 00:50:01.335 | onbar 22:05 20/08/2019 00:45:01.022 | onbar 22:05 20/08/2019 00:40:03.272 | onbar 22:05 20/08/2019 00:15:00.496 | onbar 22:05 19/08/2019 23:55:00.583 | onbar 22:05 19/08/2019 23:50:04.451 | onbar 22:05 19/08/2019 23:35:06.280 | onbar 22:05 19/08/2019 22:55:01.386 | onbar 22:05 19/08/2019 22:35:00.585 | onbar 22:05 19/08/2019 21:50:00.205 | onbar 21:50 19/08/2019 21:20:01.076 | onbar 21:20 19/08/2019 20:55:03.213 | onbar 20:55 19/08/2019 20:05:00.159 | onbar 20:05 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:45:03.054 | onbar 19:45 19/08/2019 18:40:02.484 | onbar 18:40 19/08/2019 18:16:19.350 | start 18:15 19/08/2019 18:16:19.334 | cBot "xxx" was started successfully for EURUSD, m5.
This is the printout for M15
Time (UTC+2) | Message 20/08/2019 08:30:00.401 | onbar 6:15 20/08/2019 07:30:03.740 | onbar 6:15 20/08/2019 06:30:04.231 | onbar 6:15 20/08/2019 06:15:00.264 | onbar 6:15 20/08/2019 04:00:01.602 | onbar 2:15 20/08/2019 03:45:00.460 | onbar 2:15 20/08/2019 02:30:00.612 | onbar 2:15 20/08/2019 02:15:03.082 | onbar 2:15 20/08/2019 01:15:04.469 | onbar 1:15 20/08/2019 00:45:01.022 | onbar 0:45 20/08/2019 00:15:00.496 | onbar 0:15 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:45:03.054 | onbar 19:45 19/08/2019 18:16:20.194 | start 18:15 19/08/2019 18:16:20.194 | cBot "xxx" was started successfully for EURUSD, m15.
@guillermo
guillermo
19 Aug 2019, 21:24
Hello,
I am having the same problem as described above.
Today I noticed that my robots did not work properly.
The OnBar event waS not triggered on each and every bar.
I have prepared a little test program as follows:
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.WEuropeStandardTime, AccessRights = AccessRights.None)] public class xxx : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { Print("start " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } protected override void OnBar() { Print("onbar " + MarketSeries.OpenTime.LastValue.ToShortTimeString()); } } }
The output of this program in EURUSD M2 is as follows:
Time (UTC+2) | Message 19/08/2019 20:04:00.191 | onbar 20:04 19/08/2019 20:02:01.956 | onbar 20:02 19/08/2019 20:00:00.300 | onbar 20:00 19/08/2019 19:54:02.644 | onbar 19:54 19/08/2019 19:46:02.429 | onbar 19:46 19/08/2019 19:42:01.663 | onbar 19:42 19/08/2019 19:38:00.145 | onbar 19:38 19/08/2019 19:34:05.167 | onbar 19:34 19/08/2019 19:28:13.683 | onbar 19:28 19/08/2019 18:58:01.341 | onbar 18:58 19/08/2019 18:54:01.640 | onbar 18:54 19/08/2019 18:48:05.593 | onbar 18:48 19/08/2019 18:46:00.890 | onbar 18:46 19/08/2019 18:44:00.234 | onbar 18:44 19/08/2019 18:40:02.484 | onbar 18:40 19/08/2019 18:32:04.031 | onbar 18:32 19/08/2019 18:24:00.471 | onbar 18:24 19/08/2019 18:16:18.006 | start 18:16 19/08/2019 18:16:17.944 | cBot "xxx" was started successfully for EURUSD, m2.
As you can see many bars are missing.
The same problem happens in M1, M5 and M15. I did not try other timeframes.
Running several instances of the robot in different timeframes,
it seems that when a candle is missing, it is missing in all
timeframes that apply; and when a candle is not missing, it is
not missing in all timeframes that apply.
I have run the program on two different instances of ctrader,
on different computers on different locations. The issue is
present in both instances of ctrader, and it seems that
on both computers the printout is missing the same candles.
I have restarted the ctrader platform and the computer, but the problem is still there.
I have never noticed this issue before today.
Any help would be very much appreciated.
Regards
@guillermo
guillermo
07 Jun 2019, 02:11
( Updated at: 21 Dec 2023, 09:21 )
To illustrate further this issue, in the image bellow I have loaded the indicator in four H4 charts
of EURUSD, USDCAD, XAUUSD and AUDJPY. The line is different in all four charts, and only the one of XAUUSD is correct.
Please let us know if we are doing anything wrong in the use of MarketData.GetSeries or instead this is a bug that can be fixed in due course.
Thanks a lot,
Guillermo
@guillermo
guillermo
26 Jun 2021, 00:36
RE:
I agree with this request. When the number of bots or indicators grows beyond a certain number it becomes very cumbersome to navigate the list of bots and to look up things.
An alternative or addition to the original request:
-- The possibility to organize bots and indicators in folders and subfolders, like in Metatrader 4.
-- Even better than folders, the possibility to assign labels and sublabels to bots and indicators (0, 1 or more labels for every bot or indicator), and then filter by label, like the messages in Gmail. Also, it would be nice to have some sort of archival feature or label, where I can send the bots that I don't want to see again (for example, ideas that didn't work) but that I don't want to delete for good. There should be a feature to manage labels (create, delete, etc), like in Gmail.
Regards,
@guillermo