I want to use help-classes/generic classes when developing indicators. I have not found out a recommended way to do this within Ninjatrader environment, so my approach is to use generic classes as “help-indicators”. I will be thankful if anyone in the forum can recommend other ways of using generic classes
I run into problem when my “help-indicator” ( public class GetChartControlData : Indicator ) is called from my indicator ( public class ClickEvent : Indicator).
The help-indicator will return some Chartpanel and ChartControl values:
Code in help-indicator:
if ((indicatorObj.ChartPanel != null) && (indicatorObj.ChartControl != null))
{
Print(indicatorObj.ToString());
MinX = indicatorObj.ChartPanel.X;
MaxX = MinX + indicatorObj.ChartPanel.W;
MinY = indicatorObj.ChartPanel.Y;
MaxY = MinY + indicatorObj.ChartPanel.H;
Height = (int) indicatorObj.ChartControl.AxisXHeight;
}
(the last line “Height = … “ compile, but gives a runtime error: “Indicator 'ClickEvent': Error on calling 'OnBarUpdate' method on bar 0: The calling thread cannot access this object because a different thread owns it.” If I remove this line, everything works fine …)
The help class is used like this in my “main-indicator”:
private GetChartControlData GetChartControlData_Obj; // at variable decl
…
GetChartControlData_Obj = new GetChartControlData(this); // at State.SetDefaults
…
GetChartControlData_Obj.GetData(); // at OnBarUpdate()
1. How should I do to avoid the runtime error?
2. Any ideas of different ways of using generic classes?
Thank you, AndBro, using: 8.0.0.11 64-bit (Multi-Broker) - BETA
Comment