Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Text help to display a value on chart.

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

    Draw.Text help to display a value on chart.

    I've been playing around with the options in the strategy builder and am looking to output a value on my chart. I've managed to get it to draw arrows etc. but struggling to get an actual value to be displayed.

    Below is the code I'm using which compiles fine but doesn't output anything on my chart. I've checked to make sure it's enabled.

    Any suggestions?

    Thanks
    Tim

    Code:
    //This namespace holds Strategies in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class FTB3 : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "FTB3";
                    Calculate                                    = Calculate.OnBarClose;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0) 
                    return;
    
                if (CurrentBars[0] < 1)
                    return;
    
                 // Set 1
                if (Close[0] >= Close[1])
                {
                    Draw.Text(this, CurrentBars[0].ToString() + @" Text_1", (Close[0] + (5 * (TickSize * 10))) .ToString(), 0, 0);
                }
    
            }
        }
    }

    #2
    Hello timcjpfx,

    Thanks for your reply.

    It looks like the code is drawing text at the Y value (Price level) of 0. If you move your chart vertically to see the zero price level I suspect you will find the text.

    To draw the text nearer the chart bars, you can enter a Y value using the Price of Low[0] or High[0] and then offset by adding ticks or subtracting ticks (to move the text away from the chart bars)

    Comment


      #3
      Oh, and I was looking to have the value shown to 2 decimal places, if possible.
      Thanks.

      Comment


        #4
        Hello timcjpfx,

        Thanks for your reply.

        You could use String.Format() which is a C# .Net use. Here is a quick reference: https://www.c-sharpcorner.com/Upload...ng-in-C-Sharp/

        Here is an example to get you going.

        string myText = string.Format("{0,0:N2}", (Close[0] + (5 * (TickSize * 10))));

        Draw.Text(this, CurrentBars[0].ToString() + @" Text_1",myText , 0, Low[0] - 5 * TickSize);

        Comment


          #5
          Thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          55 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X