I've got a weird thing going and wanted to bounce this off you.
protected override void OnBarUpdate()
public class KalmanFilter : Indicator
{
private double DeltaK;
private double Smooth;
private Series<double> Velocity;
public int xSlope = 0;
private const double radToDegrees = 180 / Math.PI;
private int shallowAngle = 30;
private int steepAngle = 60;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Kalman Filter.";
Name = "KalmanFilter";
Calculate = Calculate.OnPriceChange;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = false;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
Gain = 200;
UseAngle = true;
fontSize = 12;
AddPlot(Brushes.Red, "GainLevel");
Plots[0].Width = 2;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
Velocity = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
var simpleFont = new SimpleFont("Arial", fontSize) { Size = fontSize, Bold = false };
if (CurrentBar == 0)
{
GainLevel[0] = Input[0];
Velocity[0] = 0;
return;
}
DeltaK = Input[0] - GainLevel[1];
Smooth = GainLevel[1] + DeltaK * Math.Sqrt((Gain / 10000) * 2);
Velocity[0] = Velocity[1] + ((Gain / 10000) * DeltaK);
GainLevel[0] = Smooth + Velocity[0];
xSlope = (int)(radToDegrees * (Math.Atan((GainLevel[0] - (GainLevel[1]) / 2) / 1.56 / TickSize)));
[B]THIS WORKS [/B] Draw.TextFixed(this, "Gain", GainLevel[0] + " - Gain Level", TextPosition.BottomRight);
[B]THIS DOES NOT WORK[/B] Draw.TextFixed(this, "Slope", xSlope + " - Current Slope", TextPosition.BottomLeft);
Print("\tSlope @ : " + xSlope);
if (IsRising(GainLevel))
{
}
}
}
I must be missing something really obvious here...

Comment