Today the cTrader official version upgraded to 5.0.36, and my indicator encountered an error, after debugging it shows that the issue comes from the running step being disordered, as below screen chop:
Please help and advise, thanksβ¦
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class CurrencyStrengthProject : Indicator
{
private Bars BarsD1;
private bool b_Cal=true;
protected override void Initialize()
{
System.Diagnostics.Debugger.Launch();
if (LoadDailyBar()) { Print("This line should be printed before Calculate() start: Initialize() - End"); }
}
public override void Calculate(int index)
{
if (b_Cal) { Print("Calculate() started"); b_Cal=false; } //Run only once
}
private bool LoadDailyBar() //Load DailyBar
{
BarsD1 = MarketData.GetBars(TimeFrame.Daily, Bars.SymbolName); //Exceptions occurs here, it jumps to Calculate() from here...
Print("This line should be printed before Calculate() start: " + BarsD1.SymbolName + " - " + BarsD1.Count );
return true;
}
}
}
Unfortunately we were not able to reproduce this problem. Can you please record a video demonstrating this happening?
Best regards,
Panagiotis
Here is the video I took, it's not professional looking, please volume up your speaker as my mic works poorly.
Basically, the code should (un)lock the object when it is selected. It works fine on the rectangle and others, but not on Drawing objects.
The drawing objects just disappeared, and not possible to be found or seen on the chart anymore. However, it is still listed in the Object Manager window.
If you close the window, then it does not exist anymore, you would need to reinitialize it. Once a window is closed, the same object instance can't be used to reopen the window.
Best regards,
Panagiotis
Thanks Panagiotis, ChatGPT helped me optimised the code as below, and it works well now:
Here is a method provided by a fellow (@TheLegitT) in the cTrader official group, though I didn't test, I believe it will work as suppose to be:
private TimeSpan GetCurrentTimeSpan()
{
var TimeFrameName = Chart.TimeFrame.ToString();
if (!int.TryParse(Regex.Replace(TimeFrameName, "[^0-9]", ""), out int prefix)) prefix = 1;
if (TimeFrameName.Contains("Minute"))
return TimeSpan.FromMinutes(prefix);
else if (TimeFrameName.Contains("Hour"))
return TimeSpan.FromHours(prefix);
else if (TimeFrameName.Contains("Day") || TimeFrameName.Contains("Daily"))
return TimeSpan.FromDays(prefix);
else if (TimeFrameName == "Weekly")
return TimeSpan.FromDays(7);
else if (TimeFrameName == "Monthly")
return TimeSpan.FromDays(31);
else
return TimeSpan.Zero;
}
Usage:
var CurrentTimeSpan = GetCurrentTimeSpan();
if (CurrentTimeSpan == TimeSpan.Zero) // No supported TimeFrame available on Chart
{
}
// TimeSpan is acquired properly
Sorted by creating a bool scanningComplete where at the beginning of the code and to enter the code is true, at the end of the code is false.
While, it brings another interesting issue, below screen chops are debugging in VS:
At the end of Initialize() the Bars Count is more than 7K of Bars number, but in the Calculate(), when it scans each history bar, the Bars.Count() is far less than 7K. This makes the bool ScanningComplete check many times (2K+) until it reaches 7K+ the same number as in Initialize()...
Sorted, just make a new private integer to record the Bars.Count-2, and then use it in the bool ScanningComplete check (of HistoryBar scanning).
It runs only once and perfectly fits my request now...
Job done!
Ctrl + D to open the object manager, key in the keyword of the object's name, then Ctrl + A to select the relevant objects only.
P.S. However, the keywords 'USD' and 'JPY' don't work in the search bar, if the chart is in 'USDJPY'. All other currencies' names work well. It's bizarre...
Our team has investigated this issue further and it seems that the feature is working as designed. The events are triggered only for interactive objects. If you want to the event to be triggered for an object added by the cBot, you need to set the IsInteractive property to true.
Due to these new rules of listing strategies, there are investors saying they have trouble effectively selecting strategies as their candidate investment. As they can't see those good quality traders as they only trade limited times in a week or month. The new rules are doing actually harm to copy investors. I hope cTrader and Spotware officially respond to our concerns and worries, as soon as you can.
Someone suggests that in Object Manger, the indicators can be hidden, but we just want to hide the indicator panel, not the indicator itself. We still need a control checkbox, to hide the indicator panel. Thanks.
The issue had been identified now: add '#' ahead of color numbers at indicator Output setting, like below
[Output("USD", LineColor = "#DDFF0005"...
I can't imagine that a colour code error will bring trouble to Bars loading, and no error message when compiling. The error message when running was totally not pointing to the actual place.
Capt.Z-Fort.Builder
30 Sep 2024, 13:13
Hello,
Today the cTrader official version upgraded to 5.0.36, and my indicator encountered an error, after debugging it shows that the issue comes from the running step being disordered, as below screen chop:
Please help and advise, thanksβ¦
@Capt.Z-Fort.Builder