Below is the code I have been trying, without success
Thanks for any help
namespace NinjaTrader.NinjaScript.Indicators
{
public class LiveBarText : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Displays text on live bars based on bar color.";
Name = "LiveBarText";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
}
}
protected override void OnBarUpdate()
{
// Ensure this runs only on the live bar
if (CurrentBar < BarsRequiredToPlot || IsFirstTickOfBar)
return;
// Determine bar color and display corresponding text
string displayText = "";
Brush barBrush = Close[0] > Open[0] ? Brushes.Green : Brushes.Red;
// Set text based on bar direction
if (Close[0] > Open[0])
displayText = "Green Bar";
else if (Close[0] < Open[0])
displayText = "Red Bar";
// Draw text on the chart
Draw.TextFixed(this, "tag1", "Text to draw", TextPosition.TopRight);
//Draw.TextFixed(this, "LiveBarInfo", displayText, TextPosition.TopRight, barBrush, new SimpleFont("Arial", 12), Brushes.Transparent, Brushes.Transparent, 0);
}
}
}
Comment