Trigger a method call from the set property in the Addon. I am stuck in static and can't get out. Suggestions?
namespace NinjaTrader.NinjaScript.AddOns
{
public partial class MyTestAddon : NinjaTrader.NinjaScript.AddOnBase
{
public static DateTime zoneLastUpdateTime;
public static DateTime ZoneLastUpdateTime
{
get
{
return zoneLastUpdateTime;
}
set
{
zoneLastUpdateTime = value;
NinjaTrader.NinjaScript.Indicators.MyTestAddonUpdate.Indicator_DateChanged();
}
}
}
}
namespace NinjaTrader.NinjaScript.Indicators
{
public class MyTestAddonUpdate : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyTestAddonUpdate";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
}
internal static void Indicator_DateChanged()
{
// How to get out of static? Dispatcher? Create new instance?
NinjaTrader.Code.Output.Process("Indicator_DateChanged()", PrintTo.OutputTab1);
}
}
namespace NinjaTrader.NinjaScript.AddOns
{
public partial class MyTestAddon : NinjaTrader.NinjaScript.AddOnBase
{
public static DateTime zoneLastUpdateTime;
public static DateTime ZoneLastUpdateTime
{
get
{
return zoneLastUpdateTime;
}
set
{
zoneLastUpdateTime = value;
// This is in a new class. Can only call a static method in a class
NinjaTrader.NinjaScript.Indicators.ClassStep1.Method1();
}
}
}
}
namespace NinjaTrader.NinjaScript.Indicators
{
public class MyTestAddonUpdate : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyTestAddonUpdate";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
NinjaTrader.NinjaScript.Indicators.ClassStep2 objectToSubscribeTo = new NinjaTrader.NinjaScript.Indicators.ClassStep2();
objectToSubscribeTo.ZoneHasBeenUpdated += TestAlert;
}
}
protected void TestAlert(object sender, EventArgs e)
{
Print("TestAlert static variable has been updated");
}
protected override void OnBarUpdate()
{
NinjaTrader.NinjaScript.AddOns.MyTestAddon.ZoneLastUpdateTime = Time[0];
}
}
partial class ClassStep1
{
public static void Method1()
{
ClassStep1 classStep1 = new ClassStep1();
classStep1.Method2();
}
public void Method2()
{
ClassStep2 classStep2 = new ClassStep2();
classStep2.CreateEvent(EventArgs.Empty);
}
}
public class ClassStep2
{
public event EventHandler ZoneHasBeenUpdated ;
public void CreateEvent( EventArgs e)
{
NinjaTrader.Code.Output.Process("ClassStep2: CreateEvent()", PrintTo.OutputTab1);
if(ZoneHasBeenUpdated != null)
{
ZoneHasBeenUpdated(this, null);
}
else
NinjaTrader.Code.Output.Process(" IS NULL", PrintTo.OutputTab1);
}
}
Comment