Is there a way to hide the indicator from the button I created on the chart?
Is there a way to hide the indicator from the button I created on the chart?
21 Apr 2022, 04:57
Hello guys
I am looking for a way to hide the indicator from the button I created on the chart.
I have created the button on the chart, but do not know where to go from there.
Can someone please tell me how to do this?
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 SampleSMA : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter(DefaultValue = 14)]
public int Periods { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
private ToggleButton togglebutton;
private bool hideshow = true;
protected override void Initialize()
{
buttonDraw();
}
private void buttonDraw()
{
var stackPanel = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
Margin = 20
};
togglebutton = new ToggleButton
{
Text = "Hide",
Width = 80
};
togglebutton.Click += togglebuttonclick;
stackPanel.AddChild(togglebutton);
Chart.AddControl(stackPanel);
}
private void togglebuttonclick(ToggleButtonEventArgs arg)
{
if (togglebutton.IsChecked)
{
hideshow = false;
togglebutton.Text = "Show";
}
else
{
hideshow = true;
togglebutton.Text = "Hide";
}
}
public override void Calculate(int index)
{
if (hideshow)
{
double sum = 0.0;
for (int i = index - Periods + 1; i <= index; i++)
{
sum += Source[i];
}
Result[index] = sum / Periods;
}
}
}
}
Replies
yomm0401
21 Apr 2022, 11:14
RE:
amusleh said:
Hi,
Try this:
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 SampleSMA : Indicator { [Parameter("Source")] public DataSeries Source { get; set; } [Parameter(DefaultValue = 14)] public int Periods { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } private ToggleButton togglebutton; private bool hideshow = true; protected override void Initialize() { buttonDraw(); } private void buttonDraw() { var stackPanel = new StackPanel { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Margin = 20 }; togglebutton = new ToggleButton { Text = "Hide", Width = 80 }; togglebutton.Click += togglebuttonclick; stackPanel.AddChild(togglebutton); Chart.AddControl(stackPanel); } private void togglebuttonclick(ToggleButtonEventArgs arg) { if (togglebutton.IsChecked) { hideshow = false; togglebutton.Text = "Show"; for (int i = 0; i < Result.Count; i++) { Result[i] = double.NaN; } } else { hideshow = true; togglebutton.Text = "Hide"; for (int i = 0; i < Result.Count; i++) { Calculate(i); } } } public override void Calculate(int index) { if (hideshow) { double sum = 0.0; for (int i = index - Periods + 1; i <= index; i++) { sum += Source[i]; } Result[index] = sum / Periods; } } } }
Dear amusleh
you are great!
Thank you very much.
@yomm0401
amusleh
21 Apr 2022, 10:42
Hi,
Try this:
@amusleh