I would like to create an object that knows how to print itself (it's attributes) on the primary chart when it is created. My object, when called, does not have/refer-to the same CurrentBar value as it's parent.
Here is sample code that reproduces my problem.
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("This is the main Strat...the 'parent' class")]
public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
MyClass myClass;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
//Print(CurrentBar);
if(CurrentBar == 25){
Print("From OnBarUpdate() CurrentBar is:" + CurrentBar);
myClass = new MyClass();
}
}
#region Properties
#endregion
}
//this is the object, instansiated by MyCustomStrategy, that should
//be able to draw itself when created via "new"...
public class MyClass : Strategy
{
public MyClass(){
Print("Why is this not 25 as well??");
Print("From MyClass() CurrentBar is:" + CurrentBar);
}
}
}
From OnBarUpdate() CurrentBar is:25
Why is this not 25 as well??
From MyClass() CurrentBar is:0
Thank you for any guidance you can provide,
-Billy

Comment