Indicator Parameters are not updated when set in code.
Indicator Parameters are not updated when set in code.
06 Jan 2020, 11:05
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
//Unexpected behavior in cTrader?
//Add this indicator to any chart.
//Leave the parameter blank. It should "set" the value to "Hello" in the Initialize method.
//Call up the parameter window again for this indicator
//the value "Hello" isn't displayed even though it has been set.
//Why not?
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Test : Indicator
{
[Parameter("Test Parameter")]
public string Parameter { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
protected override void Initialize()
{
if (string.IsNullOrEmpty(Parameter))
Parameter = "Hello";
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] = ...
}
}
}
When the code runs, the parameter isn't updated if you call up the parameters to the indicator again:
Why not?
Replies
firemyst
07 Jan 2020, 11:02
RE:
PanagiotisCharalampous said:
Hi firemyst,
Because this part of the code was not executed. The indicator is initialized only after it has been added on the chart. If you need the parameter to show a value, you need to put a default value.
Best Regards,
Panagiotis
I'm confused@Panagiotis, because I do add it to the chart as I said in the comments in the code. Let me repeat them here:
//Unexpected behavior in cTrader?
//Add this indicator to any chart.
//Leave the parameter blank. It should "set" the value to "Hello" in the Initialize method.
//Call up the parameter window again for this indicator
//the value "Hello" isn't displayed even though it has been set.
//Why not?
After it's added to the chart, if you call up the indicator to view the properties, it's blank.
Hence why the cTrader window says, "Modify indicator" instead of "Add indicator" (when it's first being addedto the chart).
@firemyst
firemyst
12 Jan 2020, 17:36
RE: RE:
firemyst said:
PanagiotisCharalampous said:
Hi firemyst,
Because this part of the code was not executed. The indicator is initialized only after it has been added on the chart. If you need the parameter to show a value, you need to put a default value.
Best Regards,
Panagiotis
I'm confused@Panagiotis, because I do add it to the chart as I said in the comments in the code. Let me repeat them here:
//Unexpected behavior in cTrader? //Add this indicator to any chart. //Leave the parameter blank. It should "set" the value to "Hello" in the Initialize method. //Call up the parameter window again for this indicator //the value "Hello" isn't displayed even though it has been set. //Why not?
After it's added to the chart, if you call up the indicator to view the properties, it's blank.
Hence why the cTrader window says, "Modify indicator" instead of "Add indicator" (when it's first being addedto the chart).
Any updates @Panagiotis? Have you been able to reproduce the issue with the code I've provided above?
@firemyst
PanagiotisCharalampous
13 Jan 2020, 08:48
Hi firemyst,
This is by design. The form does not display the parameter value as modified during execution. It shows only the default value.
Best Regards,
Panagiotis
@PanagiotisCharalampous
firemyst
21 Jan 2020, 03:56
RE:
PanagiotisCharalampous said:
Hi firemyst,
This is by design. The form does not display the parameter value as modified during execution. It shows only the default value.
Best Regards,
Panagiotis
Hi @Panagiotis:
This isn't entirely true. If a user edits the parameters during execution, they are remembered. Take the above indicator code for example.
Add the indicator to a chart.
Now open the indicator, edit the value, and close the properties window.
Then, open the properties window back up of the indicator and the value is there. Eg, it's "saved" when changed manually by the user.
So it doesn't only show the "default" value, right?
Thus if it can save the value during execution by the user by changing the value in the properties manually, then it should be able to be saved when changed programmatically by the indicator itself.
@firemyst
PanagiotisCharalampous
21 Jan 2020, 08:57
Hi firemyst,
Maybe I did not explain it well. The form keeps the value set by the user in the form when the indicator is initialized. When you modify an indicator, what actually happens is that the indicator is actually recreated.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
07 Jan 2020, 09:36
Hi firemyst,
Because this part of the code was not executed. The indicator is initialized only after it has been added on the chart. If you need the parameter to show a value, you need to put a default value.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous