Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart Indicator Text Display Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Chart Indicator Text Display Issue

    The indicator I created below uses the Draw.TextFixed command for both logic's (SL_TREND and SL_CYCLE_K) to display the proper text on the top left of the chart. Problem is on the chart they display on top of each other instead of left to right in a line, equally spaced. I know that the command line should probably be Draw.Text command with Y offsets but every time I try to code it with a draw.Text command, I get errors.


    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TPTEST : Indicator
    {
    private Stochastics stochasticsK;
    private SMA sma;
    private Brush upBrush;
    private Brush downBrush;
    private Brush neutralBrush;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"TPTEST";
    Name = "TPTEST";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;

    }
    else if (State == State.Configure)
    {
    stochasticsK = Stochastics(14, 5, 2);
    sma = SMA(50);

    }
    else if (State == State.DataLoaded)
    {
    upBrush = Brushes.Green;
    downBrush = Brushes.Red;
    neutralBrush = Brushes.Purple;
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return;

    double stochasticK = stochasticsK.K[0];
    double prevStochasticK = stochasticsK.K[1];
    double smaValue = sma[0];
    double prevSmaValue = sma[1];



    // SL_CYCLE_K Logic
    if (stochasticK > prevStochasticK)
    {
    Draw.TextFixed(this, "stochDirectionK", "%K UP", TextPosition.TopLeft, upBrush, new SimpleFont("Arial", 15), Brushes.Transparent, Brushes.Transparent, 100);
    }
    else if (stochasticK < prevStochasticK)
    {
    Draw.TextFixed(this, "stochDirectionK", "%K DOWN", TextPosition.TopLeft, downBrush, new SimpleFont("Arial", 15), Brushes.Transparent, Brushes.Transparent, 100);
    }

    // SL_TREND Logic
    if (smaValue > prevSmaValue)
    {
    Draw.TextFixed(this, "smaDirection", "TREND UP", TextPosition.TopLeft, upBrush, new SimpleFont("Arial", 15), Brushes.Transparent, Brushes.Transparent, 100);
    }
    else if (smaValue < prevSmaValue)
    {
    Draw.TextFixed(this, "smaDirection", "TREND DOWN", TextPosition.TopLeft, downBrush, new SimpleFont("Arial", 15), Brushes.Transparent, Brushes.Transparent, 100);

    }
    }
    }
    }




    #2
    Hello Skatester,

    Thank you for your post.

    This would be expected. Draw.TextFixed() draws text in one of 5 available pre-defined fixed locations on panel 1 (price panel) of a chart. You have specified all of these Draw.TextFixed() calls to be drawn in the Top Left corner, so they will overlap on top of each other.

    This method does not adjust or provide a parameter to adjust where the text will be placed, this object can only be placed in one of the five pre-defined fixed locations.

    If you would like more control over where the text is displayed, you can use SharpDX to custom render text on the chart:



    Please let us know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    46 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    141 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X