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.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ngchun1, Today, 09:05 PM
    0 responses
    4 views
    0 likes
    Last Post ngchun1
    by ngchun1
     
    Started by xfactscout, 07-22-2024, 09:01 PM
    1 response
    25 views
    0 likes
    Last Post xfactscout  
    Started by Chrisnasdaq, 08-26-2023, 08:37 PM
    4 responses
    1,405 views
    0 likes
    Last Post pierodicarlo  
    Started by GillRymhes, 06-23-2022, 09:16 AM
    13 responses
    746 views
    5 likes
    Last Post pierodicarlo  
    Started by aligator, 06-22-2022, 01:10 PM
    13 responses
    1,823 views
    0 likes
    Last Post pierodicarlo  
    Working...
    X