Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Vertical Text

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

    Vertical Text

    I am looking to have vertical text written at a specific bar location and as the bars keep coming in that it would shift to the left with the bars.

    I do not think that there is a Draw. option for this so it would most likely need to be OnRender

    The issue with that is OnRender has a limitation that if the indicator is on a separate chart panel there is not a inherent way to say to have the plots draw on the second panel and the text object through onrender draw on price panel correct?

    #2
    You can add /n after every letter to make the text vertical. Example:

    PHP Code:
    using System;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    using System.Windows.Media;
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class LowDifferenceIndicator : Indicator
    {
    private int verticalOffset = 5; // Default offset in pixels
    
    [NinjaScriptProperty]
    public int VerticalOffset
    {
    get { return verticalOffset; }
    set { verticalOffset = value; }
    }
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Displays the absolute number of ticks difference between the current bar's low and the previous bar's low at the bottom of the current bar with adjustable vertical positioning, shown in vertical orientation. Negative differences are shown in red.";
    Name = "LowDifferenceIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true; // Draw directly on the chart.
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return; // Ensure there is at least one previous bar to compare with.
    
    // Calculate the difference in lows between the current bar and the previous bar.
    double difference = Low[0] - Low[1];
    
    // Convert the difference from points to the number of ticks.
    int ticksDifference = (int)(difference / TickSize);
    
    // Use the absolute value for display.
    int absTicksDifference = Math.Abs(ticksDifference);
    
    // Convert the absolute ticks difference to a vertical text string.
    string verticalText = String.Join("\n", absTicksDifference.ToString().ToCharArray());
    
    // Calculate the position for the text based on the low of the current bar minus the vertical offset in pixels.
    double textPosition = Low[0] - (TickSize * VerticalOffset);
    
    // Set the color based on whether the original ticks difference is negative
    Brush textColor = ticksDifference < 0 ? Brushes.Red : Brushes.Black;
    
    // Draw the vertical text at the calculated position.
    Draw.Text(this, "diffText" + CurrentBar, verticalText, 0, textPosition, textColor);
    }
    }
    }&#8203; 
    

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NeoTraderBot, Yesterday, 10:55 PM
    0 responses
    6 views
    0 likes
    Last Post NeoTraderBot  
    Started by OliverWaters, Yesterday, 10:35 PM
    0 responses
    6 views
    0 likes
    Last Post OliverWaters  
    Started by Graci117, 07-06-2024, 09:32 AM
    6 responses
    37 views
    0 likes
    Last Post Graci117  
    Started by AdamDJ8, 07-01-2024, 06:50 PM
    2 responses
    123 views
    0 likes
    Last Post AdamDJ8
    by AdamDJ8
     
    Started by AdamDJ8, 07-01-2024, 05:55 PM
    3 responses
    32 views
    0 likes
    Last Post AdamDJ8
    by AdamDJ8
     
    Working...
    X