Ugh! V3.7 changes! Now string parameters are checked and a new copy of the indicator made with every keystroke?!
Created at 05 Feb 2020, 16:35
Ugh! V3.7 changes! Now string parameters are checked and a new copy of the indicator made with every keystroke?!
05 Feb 2020, 16:35
Team Spotware / @Panagiotis:
In addition to this issue:
https://ctrader.com/forum/indicator-support/22812?page=1#1
Now there's this issue: string parameters cause a new copy of the indicator on every keystroke? It used to be they didn't do anything until someone clicked outside of the input field.
Take this example:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
/// <summary>
/// Add this indicator to the US30 M1 chart.
/// Change the Symbol in the text area. Notice it throws an exception on every keystroke!
/// Prior to V3.7, this used to work where it wouldn't check or do anything until the
/// user clicked outside the input area.
/// Expected behavior: wait until the input area loses focus before doing a check as it
/// was in v3.6! Otherwise this is ridiculous that cTrader is going to make a new copy
/// of the indicator for every keystroke with textual string input fields!
/// </summary>
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Test : Indicator
{
[Parameter("Symbols.Enter Whatever", DefaultValue = "US30")]
public string TheSymbols { get; set; }
[Output("Main", LineColor = "Green", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 3)]
public IndicatorDataSeries Result { get; set; }
private Bars[] _marketSeries;
private int z = 0;
private int _lastIndex = 0;
protected override void Initialize()
{
_marketSeries = new Bars[1];
int x = 0;
try
{
_marketSeries[x] = MarketData.GetBars(Bars.TimeFrame, TheSymbols);
z = _marketSeries[x].OpenTimes.Count - (_marketSeries[x].OpenTimes.GetIndexByExactTime(_marketSeries[x].OpenTimes.Last(_marketSeries[x].ClosePrices.Count - 1)));
for (int y = 0; y < z; y++)
{
Result[y] = 0;
IndicatorArea.DrawStaticText("Result", "y:" + y + ", z:" + z + ",", VerticalAlignment.Top, HorizontalAlignment.Left, Color.Goldenrod);
}
}
catch (Exception e)
{
IndicatorArea.DrawStaticText("Exception", "Exception! " + e.Message, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Red);
}
}
public override void Calculate(int index)
{
}
}
}