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

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)
    Paul H.NinjaTrader Customer Service

    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);
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:10 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          9 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Working...
          X