Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddOns

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

    AddOns

    Is it possible to have a method in the AddOns folder than can be used by both a strategy and an indicator ?

    #2
    Hello spottysallrite,

    Thank you for your post.

    Yes, this may be done by creating a partial class in the NinjaTrader.NinjaScript.AddOns namespace. Then, you could access the method via any script type (such as strategies and indicators) by using the fully qualified namespace such as NinjaTrader.NinjaScript.AddOns.MySharedMethods.Sha redDouble from the MySharedMethodsAddOnExample posted here:
    https://forum.ninjatrader.com/forum/...245#post712245

    That example is a shared double; you could change it to a custom method instead and use the fully qualified namespace when using the method in other scripts. The following information should be kept in mind as well:
    https://forum.ninjatrader.com/forum/...13#post1131313

    Please let us know if we may be of further assistance.

    Comment


      #3
      Ok, I'm not quite following. How would such a method that exists in the AddOns folder in be called from within an indicator ? (Pseudo code is fine.)

      Comment


        #4
        Originally posted by spottysallrite View Post
        Ok, I'm not quite following. How would such a method that exists in the AddOns folder in be called from within an indicator ? (Pseudo code is fine.)
        A full-fledged example may be found by downloading the "MySharedMethodsAddonExample.zip" at the first link I shared:


        The .zip contains an AddOn, Indicator, and Strategy. The AddOn has a shared double in the AddOn namespace that may be accessed in both the indicator and strategy as well as a method in the indicator class only and one in the strategy class only. The code comments explicitly explain this as well.

        Here is a more simple example of a custom method that could be created in a partial class in an AddOn script:
        Code:
        //This namespace holds Add ons in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.AddOns
        {
            public partial class MySharedMethods : NinjaTrader.NinjaScript.AddOnBase
            {
                // This double can be accessed from within another addon with MySharedMethods.SharedDouble
                // or can be accessed from any script using NinjaTrader.NinjaScript.AddOns.MySharedMethods.SharedDouble
                public static void PrintString(String stringToPrint)
                {
                    NinjaTrader.Code.Output.Process(stringToPrint, PrintTo.OutputTab1);
                }
            }
        }​
        Then, from an indicator or strategy script, you could call this method as follows:
        Code:
                protected override void OnBarUpdate()
                {
                    NinjaTrader.NinjaScript.AddOns.MySharedMethods.PrintString("this is the string to print");
                }​
        Hopefully this helps to clarify. Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        23 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X