Topics
Replies
ctid2948110
05 Oct 2023, 21:07
RE: Here is the source from the cTrader example not working ?
ctid2948110 said:
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 cAlgo
{
// This sample indicator shows how to use IndicatorArea
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class IndicatorAreaSample : Indicator
{
private TextBlock _indicatorAreaNumberTextBlock;
protected override void Initialize()
{
var grid = new Grid(1, 2)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
BackgroundColor = Color.Gold,
Opacity = 0.7,
Width = 200
};
grid.AddChild(new TextBlock { Text = "Indicator Area #", Margin = 5, FontWeight = FontWeight.ExtraBold, ForegroundColor = Color.Black }, 0, 0);
_indicatorAreaNumberTextBlock = new TextBlock
{
Margin = 5,
Text = Chart.IndicatorAreas.Count.ToString(),
FontWeight = FontWeight.ExtraBold,
ForegroundColor = Color.Black
};
grid.AddChild(_indicatorAreaNumberTextBlock, 0, 1);
// SHOW GRID ##########################################################################
// Chart.AddControl(grid);
IndicatorArea.AddControl(grid);
Chart.IndicatorAreaAdded += Chart_IndicatorAreaAdded;
Chart.IndicatorAreaRemoved += Chart_IndicatorAreaRemoved;
}
private void Chart_IndicatorAreaRemoved(IndicatorAreaRemovedEventArgs obj)
{
_indicatorAreaNumberTextBlock.Text = Chart.IndicatorAreas.Count.ToString();
}
private void Chart_IndicatorAreaAdded(IndicatorAreaAddedEventArgs obj)
{
_indicatorAreaNumberTextBlock.Text = Chart.IndicatorAreas.Count.ToString();
}
public override void Calculate(int index)
{
}
}}
Test
@ctid2948110
ctid2948110
04 Oct 2023, 07:12
( Updated at: 04 Oct 2023, 15:24 )
Panagiotis - Actually this code sample only has problems when "IsOverlay = false"
Hi Panagiotis, thanks for looking at this, I couldn't see any exceptions debugging in VS2022 or the cTrader > Tradewatch > Automate tab ?
(Which Log did you view and which exception did you see ?. I couldn't see what you mentioned :( )
When "IsOverlay = false" and you add this Custom Indicator to a Chart it doesn't display correctly.
But if you close cTrader (with this Indicator active) & re-open it, this Custom Indicator displays correctly ?
Any ideas ??
@ctid2948110
ctid2948110
03 Oct 2023, 19:59
( Updated at: 05 Oct 2023, 18:21 )
Here is the source from the cTrader example not working ?
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 cAlgo
{
// This sample indicator shows how to use IndicatorArea
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class IndicatorAreaSample : Indicator
{
private TextBlock _indicatorAreaNumberTextBlock;
protected override void Initialize()
{
var grid = new Grid(1, 2)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
BackgroundColor = Color.Gold,
Opacity = 0.7,
Width = 200
};
grid.AddChild(new TextBlock { Text = "Indicator Area #", Margin = 5, FontWeight = FontWeight.ExtraBold, ForegroundColor = Color.Black }, 0, 0);
_indicatorAreaNumberTextBlock = new TextBlock
{
Margin = 5,
Text = Chart.IndicatorAreas.Count.ToString(),
FontWeight = FontWeight.ExtraBold,
ForegroundColor = Color.Black
};
grid.AddChild(_indicatorAreaNumberTextBlock, 0, 1);
// SHOW GRID ##########################################################################
// Chart.AddControl(grid);
IndicatorArea.AddControl(grid);
Chart.IndicatorAreaAdded += Chart_IndicatorAreaAdded;
Chart.IndicatorAreaRemoved += Chart_IndicatorAreaRemoved;
}
private void Chart_IndicatorAreaRemoved(IndicatorAreaRemovedEventArgs obj)
{
_indicatorAreaNumberTextBlock.Text = Chart.IndicatorAreas.Count.ToString();
}
private void Chart_IndicatorAreaAdded(IndicatorAreaAddedEventArgs obj)
{
_indicatorAreaNumberTextBlock.Text = Chart.IndicatorAreas.Count.ToString();
}
public override void Calculate(int index)
{
}
}
}
@ctid2948110
ctid2948110
05 Oct 2023, 21:15 ( Updated at: 21 Dec 2023, 09:23 )
RE: Custom Indicator - IndicatorAreaSample not working on cTrader 4.8.25 ?
PanagiotisChar said:
Hi Again,
I was unable to reproduce the exception you confirmed, but thanks for explaining how you debugged it.
Here is a Link to my code with source of IndicatorAreaSample from the cTrader help, compiled in VS2022 for Debug with .Net 6.0.
Btw I noticed your running cTrader 4.8.28 while I'm on 4.8.25 both with Pepperstone Europe, could this be a problem ?
Any help would be appreciated ;)
@ctid2948110