• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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)
    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 safbrathpro, Today, 05:51 AM
          0 responses
          4 views
          0 likes
          Last Post safbrathpro  
          Started by abfefmu, Today, 05:33 AM
          0 responses
          4 views
          0 likes
          Last Post abfefmu
          by abfefmu
           
          Started by bbdjad, Today, 04:36 AM
          0 responses
          4 views
          0 likes
          Last Post bbdjad
          by bbdjad
           
          Started by mittie3, Today, 03:33 AM
          0 responses
          7 views
          0 likes
          Last Post mittie3
          by mittie3
           
          Started by Againmain1, Today, 03:04 AM
          0 responses
          10 views
          1 like
          Last Post Againmain1  
          Working...
          X