Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using CurrentBars in an AddOn/Seperate File

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

    Using CurrentBars in an AddOn/Seperate File

    Hi,

    I'm trying to create new files that will be used in my indicator but having trouble writing the inner methods.

    I have this File with this code inside:

    Code:
    #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.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.Gui.Tools;
    #endregion
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    
    public partial class Indicator
    {
    
    public class ExampleAddOnIndicatorClass: NinjaTrader.NinjaScript.AddOnBase
    {
    
    public static void exampleAddOnMethod(CurrentBars currentBars, int dataSeriesToUse)
    {
    
    }
    
    
    private void Log(object message)
    {
    Print(message);
    NinjaTrader.Code.Output.Process(message.ToString() , PrintTo.OutputTab1);
    }
    }
    
    }
    
    
    
    }
    "CurrentBars" cannot be found, is there a "using declarative" for this?.

    CS0120 error is spitting out when trying to use the Print method unless my ExampleAddOnIndicatorClass extends NinjaTrader.NinjaScript.AddOnBase?

    Any help would be great!

    Thank you

    #2
    Hello tarikmedjber,

    CurrentBars is not a property that can be used in an addon, that applies to scripts which use bar data for processing and have the OnBarUpdate override. .

    The code you provided is not valid, it looks like you are trying to combine and indicator and an addon but those are two separate types. You can make indicators that apply to charts or could be used with strategies, you can also make addons which would generally be used for custom tools like new windows or modifying exiting windows. Those two types are different though and cannot be combined, an addon does not have specific bars for processing like an indicator would.


    Comment


      #3
      Morning Jesse,

      That makes sense I just thought I'd be able to pass CurrentBars from my indicator to a method in an addon class.

      What should I be using if I wanted to make my scripts more OOP, I've read around it and people have said to create new files and add them into the addons folder but this seems to be not perfect if i can't pass ninjascript type properties like current bars to this.

      But I do understand the code above is a bit crazy, I didn't know whether I need to add my add on class inside the Indicators namespace to be sued within my Indicator.

      Thanks,

      Tarik

      Comment


        #4
        Hello tarikmedjber,

        If you are looking to learn about OOP I would not suggest to use NinjaScript documentation but instead just learn from outside C# tutorials. NinjaScript is just C# and the C# language features and structure apply within NinjaTrader.

        If you are trying to break parts of your code off into other files you would generally need to create a C# class and put it inside a file. That file could go in the indicators or addons folder but would not have any Addon or Indicator code like a normal indicator, just your C# class instead. That brings up a lot of complexities and also requires you know about C# topics like Scope, Instances, Classes, Public vs Private. This is a good point to do some research on C# object oriented programming. NinjaTrader is just compiling the C# source code you have.

        Comment


          #5
          Great thanks for the help Jesse!

          Have a nice day

          Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 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
          554 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