Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Remove Decimals

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

    Remove Decimals

    Hello,
    I'm trying to remove the Decimals from the text that is printing on the screen. I can't seem to figure out where to put the FormatPrice script (not sure if this is what I really need to use).
    Any help would be greatly appreciated.
    Thank you for your time.
    James

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class myATR : Strategy
    {
    private double CurrentATR;

    private ATR ATR1;
    private Gui.Tools.SimpleFont textFont;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "myATR";
    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;
    ATRperiod = 5;
    textFont = new Gui.Tools.SimpleFont("Arial", 14);
    TextColor = Brushes.Red;
    TextBackColor = Brushes.Yellow;
    myTextBox = TextPosition.BottomRight;
    CurrentATR = 0;



    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    ATR1 = ATR(Close, Convert.ToInt32(ATRperiod));
    }
    }


    // FormatPriceMarker method of a custom indicator
    public override string FormatPriceMarker(double price)
    {
    // Formats price marker values to 4 decimal places
    return price.ToString("N0");
    }

    protected override void OnBarUpdate()


    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;




    // Set 1



    if (ATR1[0] > 0)
    {



    CurrentATR = ATR1[0];
    Draw.TextFixed(this, @"myATR", Convert.ToString(CurrentATR), myTextBox, TextColor, TextFont, Brushes.Transparent, TextBackColor, 100 );
    }
    }




    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="ATRperiod", Order=1, GroupName="Parameters")]
    public int ATRperiod
    { get; set; }

    [Display(Name="Text box location", Description="Select text location", Order=1, GroupName="Parameters")]
    public TextPosition myTextBox
    { get; set; }

    [Display(Name = "Text Font", Description= "Select font, style, size to display on chart", GroupName= "Parameters", Order= 2)]
    public Gui.Tools.SimpleFont TextFont
    {
    get { return textFont; }
    set { textFont = value; }
    }

    [XmlIgnore]
    [Display(Name="Text Color", Description="Text color ", Order=3, GroupName="Parameters")]
    public Brush TextColor
    { get; set; }

    [Browsable(false)]
    public string TextColorSerializable
    {
    get { return Serialize.BrushToString(TextColor); }
    set { TextColor = Serialize.StringToBrush(value); }
    }



    [XmlIgnore]
    [Display(Name="Text Background color", Description="Background color ", Order=4, GroupName="Parameters")]
    public Brush TextBackColor
    { get; set; }

    [Browsable(false)]
    public string TextBackColorSerializable
    {
    get { return Serialize.BrushToString(TextBackColor); }
    set { TextBackColor = Serialize.StringToBrush(value); }
    }


    #endregion

    }
    }

    #2
    Hello laoshr,

    If you mean to format the Draw.Text text then you need to format the number you pass to it.

    That would either be:

    Code:
    CurrentATR.ToString("specify a C# number format")
    or
    Code:
    Math.Round(CurrentATR, 0).ToString()
    or

    Code:
    string myString = ((int)CurrentATR).ToString();
    There are also instrument specific rounding functions if you were looking for the tick size. https://ninjatrader.com/support/help...toticksize.htm


    Please let me know if I may be of further assistance.

    Comment


      #3
      Hello Jesse.
      Thank you for your reply. I'm a total noob here with the ninjascript (all coding that is).
      I've tried putting CurrentATR.ToString("N2") everywhere it doesn't error and can't seem to figure out where to put it.

      Sorry for my lack of knowledge here. Any help would be appreciated.

      Thank you again for any help and your time.
      James

      Comment


        #4
        Hello laoshr,

        You would use that as the string for the drawing object. ToString makes whatever object you do .ToString on into a string. You would use that in the Draw.TextFixed syntax where it asks for the string you wanted to display in place of what you previously used Convert.ToString(CurrentATR).

        Please let me know if I may be of further assistance.

        Comment


          #5
          Thanks Jesse.
          That makes sense. I was complicating it way beyond what was needed. Everything looking good now.
          Thanks again for your help and education.
          James

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          576 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X