Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Customizable Parabolic Sar Indicator

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

    Customizable Parabolic Sar Indicator

    Hi,

    How do I create an indicator with code from an indicator on Tradingview?

    Thanks

    #2
    Hello hhoyle,

    NinjaTrader uses C# .NET 4.8 and is not the same language as used by TradingView from my understanding.

    You will need to create a new indicator in the NinjaScript Editor and code this in C# using the external indicator as a guide.

    Below is a link to a support article with helpful resources on getting started with C# and NinjaScript.


    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      I have this code for a bar timer indicator I'm trying to create:

      region Using declarations
      using System;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript.Strategies;
      using NinjaTrader.NinjaScript.Indicators;
      using System.Windows.Media;
      #endregion

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class BarTimerWithEST : Indicator
      {
      private DateTime barCloseTime;
      private TimeSpan timeRemaining;
      private SimpleFont textFont;

      [NinjaScriptProperty]
      [Display(Name = "Font Name", GroupName = "Appearance", Order = 1)]
      public string FontName { get; set; } = "Arial";

      [NinjaScriptProperty]
      [Display(Name = "Font Size", GroupName = "Appearance", Order = 2)]
      public int FontSize { get; set; } = 14;

      [NinjaScriptProperty]
      [Display(Name = "Font Color", GroupName = "Appearance", Order = 3)]
      public Brush FontColor { get; set; } = Brushes.White;

      [NinjaScriptProperty]
      [Display(Name = "X Position", GroupName = "Placement", Order = 4)]
      public int XPos { get; set; } = 50;

      [NinjaScriptProperty]
      [Display(Name = "Y Position", GroupName = "Placement", Order = 5)]
      public int YPos { get; set; } = 50;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "Displays a bar timer and EST time.";
      Calculate = Calculate.OnEachTick;
      IsOverlay = true;
      AddPlot(Brushes.Transparent, "DummyPlot");
      }
      else if (State == State.Configure)
      {
      textFont = new SimpleFont(FontName, FontSize);
      }
      }

      protected override void OnBarUpdate()
      {
      if (Bars == null || Bars.Count < 1) return;

      // Calculate bar close time based on the selected timeframe
      barCloseTime = Times[0][0].Add(BarsPeriod.Value);
      DateTime estNow = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
      timeRemaining = barCloseTime - estNow;

      if (timeRemaining < TimeSpan.Zero)
      timeRemaining = TimeSpan.Zero;
      }

      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      base.OnRender(chartControl, chartScale);

      if (ChartBars == null || Bars == null)
      return;

      DateTime estNow = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
      string displayText = $"EST Time: {estNow:HH:mm:ss} \nBar Time Left: {timeRemaining:mm\\:ss}";

      // Draw text on chart
      RenderTarget.DrawText(displayText, textFont, FontColor, new SharpDX.Vector2(XPos, YPos));
      }
      }
      }

      and I'm getting the following error codes:
      cs0246
      cs1503

      Thanks

      Comment


        #4
        Hello hhoyle,

        Note:
        "barCloseTime = Times[0][0].Add(BarsPeriod.Value);"

        A <DateTime>.Add() call requires a timespan to add to the datetime.
        Returns a new DateTime that adds the value of the specified TimeSpan to the value of this instance.


        Where you trying to add a number of minutes?

        Use <DateTime>.AddMinutes().



        May I have you provide a screenshot of the full error message?

        This should show the filename with the error message in the Error column expanded as much as possible and the NinjaScript File column and the line number still visible.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        557 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X