Grids not showing
Grids not showing
11 Nov 2023, 15:28
Preexisting custom indicators not showing Grids when indicator is added on NewPanel.
This behavior was introduced with one of the latest versions, one or two months ago.
Please note that if the workspace is re-loaded the grids are shown but changing any parameter repeats the issue.
Regards
Takis
Replies
gennimatas
12 Nov 2023, 09:54
RE: Grids not showing
PanagiotisCharalampous said:
Hi Takis,
Can you please record a video demonstrating the steps that lead to this behavior?
Best regards,
Panagiotis
Hi Panagiotis,
Here is some minimum code extracted from my indicators to help reproduce the issue.
Adding the indicator in a NewPanel, Grid does not show.
Saving and reloading the workspace, it will show.
Move it on Chart, then back to NewPanel and it's hidden again.
I was expecting that with given code the Result output would work correctly even with IsOverlay = false
And indi placed on Chart but this does not happen. My expectation was based on the assumption that after the
addition of Chart/NewPanel the IsOverlay
would become obsolete. Anyway, this case is not very important.
Regards
Takis
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace TestGrid
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class TestGrid : Indicator
{
[Parameter("periods", DefaultValue = 7)]
public int periods { get; set; }
[Parameter("hAlign", DefaultValue = HorizontalAlignment.Left)]
public HorizontalAlignment hAlign { get; set; }
[Parameter("vAlign", DefaultValue = VerticalAlignment.Bottom)]
public VerticalAlignment vAlign { get; set; }
[Parameter("setYRange", DefaultValue = 0, MinValue = 0)]
public int setYRange { get; set; }
[Output("Result", LineColor = "White")]
public IndicatorDataSeries Result { get; set; }
ChartArea Area;
TextBlock tb;
protected override void Initialize()
{
Area = IndicatorArea is null ? Chart : IndicatorArea;
AddControls();
if (Area is IndicatorArea)
Area.DrawHorizontalLine("zero", 0, Color.Cyan);
}
public override void Calculate(int index)
{
Result[index] = Bars.ClosePrices.TakeLast(periods).Average();
if (Area is IndicatorArea)
Result[index] -= Bars.ClosePrices.TakeLast(periods * 2).Average();
tb.Text = Result[index].ToString("F2");
if (Area is IndicatorArea && setYRange > 0)
Area.SetYRange(-setYRange, setYRange);
}
public void AddControls()
{
ScrollViewer sv = new ScrollViewer
{
HorizontalAlignment = hAlign,
VerticalAlignment = vAlign,
BackgroundColor = Color.Black
};
Area.AddControl(sv);
StackPanel panel = new StackPanel();
sv.Content = panel;
panel.AddChild(new TextBlock() { Text = Area == IndicatorArea ? "Oscillator" : "Chart", TextAlignment = TextAlignment.Center, BackgroundColor = Color.Blue });
Border border = new Border
{
BorderColor = Color.Yellow,
BorderThickness = 1,
Margin = new Thickness(2, 2, 2, 2)
};
panel.AddChild(border);
Grid grid = new Grid
{
BackgroundColor = Color.Black,
Margin = new Thickness(2, 2, 2, 2)
};
grid.AddColumns(2);
grid.AddRows(1);
border.Child = grid;
string[] labels = { "V" };
for (int r = 0; r < labels.Length; r++)
{
var bt = new Button
{
Margin = new Thickness(0, 0, 5, 0),
Text = labels[r]
};
grid.AddChild(bt, r, 0);
tb = new TextBlock
{
Margin = new Thickness(0, 0, 5, 0),
VerticalAlignment = VerticalAlignment.Center
};
grid.AddChild(tb, r, 1);
}
}
}
}
@gennimatas
gennimatas
13 Nov 2023, 14:30
RE: Grids not showing
Panagiotis,
Another thing that i observe is that when placing two or more indicators on the same area
the indicators are rescaled individually regardless of the AutoRescale property.
This can be clearly seen scrolling back.
Regards
@gennimatas
PanagiotisCharalampous
13 Nov 2023, 14:53
Hi Takis,
Unfortunately I cannot reproduce such an issue. I will have to ask you one more time to share a video demonstrating the problem.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Nov 2023, 06:20 ( Updated at: 12 Nov 2023, 06:25 )
Hi Takis,
Can you please record a video demonstrating the steps that lead to this behavior?
Best regards,
Panagiotis
@PanagiotisCharalampous