Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Combine multiple strategies / indicators into a host script.

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

    Combine multiple strategies / indicators into a host script.

    I want to know if it is possible to do this:

    host script initializes script x, script x calculates things and adds things to a List, host script can now use script x logic to execute trades.

    I want to be able to change the timeframes between such scripts and at the moment, combining all the methods in one script creates errors in calculations and identification.

    #2
    Hello olisav57,

    Thanks for your post.

    Something you could consider is having the script write information to a file using a StreamWriter and then other scripts could read information from that file using a StreamReader.

    StreamWriter: https://ninjatrader.com/support/help...o_write_to.htm
    StreamReader: https://ninjatrader.com/support/help...o_read_fro.htm

    If you want to expose values in an indicator that are not plots, you could view this reference sample from the help guide demonstrating how this would be done: https://ninjatrader.com/support/help...alues_that.htm

    If you have methods or variables you want to access/use in multiple NinjaScripts, you could consider creating an addon that uses partial classes to accomplish this.

    You could find information about partial classes and sample code on the help guide page below.
    https://ninjatrader.com/support/helpGuides/nt8/index.html?code_breaking_changes.htm#Implementatio nChangesOverview

    Information about creating partial classes in C# could also be found on the forum thread linked below.

    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I think partial classes would be best. But here is the thing, my indicator finds three candle patterns, and stores variables in a public list that are defined through a class. For example, it has a high, a low, and a bar index. Would it be possible to simply take the methods within my indicator and create a partial class add on that would incorporate them, and then simply, in a strategy script, tell it use this data series. Then I could access the results from the lest?

      Comment


        #4
        Hello olisav57,

        Thanks for your notes.

        You could use the sample provided in post # 2 detailing how to expose values in an indicator that are not plots.

        The double example in that sample is what you would do with a list. You would make the exposed type the lists type. If the list is in a class you would have to make a get with a body to return the value if not null. For example: { get { if(myClass != null && myClass.MyList != null) return myClass.MyList; else return null; } }

        The reference sample from the help guide could be found here: https://ninjatrader.com/support/help...alues_that.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello olisav57,

          Thanks for your notes.

          You could use the sample provided in post # 2 detailing how to expose values in an indicator that are not plots.

          The double example in that sample is what you would do with a list. You would make the exposed type the lists type. If the list is in a class you would have to make a get with a body to return the value if not null. For example: { get { if(myClass != null && myClass.MyList != null) return myClass.MyList; else return null; } }

          The reference sample from the help guide could be found here: https://ninjatrader.com/support/help...alues_that.htm
          I looked at the example quickly and it used series, i dont understand what those are, is it possible to do it without?

          Comment


            #6
            Hello olisac57,

            Thanks for your notes.

            The example demonstrates exposing a Series<bool> and it demonstrates exposing a double value called "exposedVariable".

            You would follow the double example in that sample to expose a public list in the indicator. You would make the exposed type the lists type.

            As noted in post # 4, if the list is in a class you would have to make a get with a body to return the value if not null. For example: { get { if(myClass != null && myClass.MyList != null) return myClass.MyList; else return null; } }
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Originally posted by NinjaTrader_BrandonH View Post
              Hello olisac57,

              Thanks for your notes.

              The example demonstrates exposing a Series<bool> and it demonstrates exposing a double value called "exposedVariable".

              You would follow the double example in that sample to expose a public list in the indicator. You would make the exposed type the lists type.

              As noted in post # 4, if the list is in a class you would have to make a get with a body to return the value if not null. For example: { get { if(myClass != null && myClass.MyList != null) return myClass.MyList; else return null; } }
              It does not work with a list, telling me the type list cannot be found. It's also telling me that the type FairValueGaps (name of my indicator) is a method which is not valid in the current context.

              public list FVGS
              {
              get { if(FairValueGaps(true, true, true, true, 3, true, true, true) != null && FairValueGaps.fvgs != null) return FairValueGaps.fvgs; else return null; }
              }​

              Comment


                #8
                Originally posted by olisav57 View Post
                I think partial classes would be best.

                Although not endorsed by NinjaTrader support,
                you can use an abstract base class rather than
                (or in addition to) the partial class idea.

                I have posted about this technique before.

                Good reading here, here, and here.

                Comment


                  #9
                  Originally posted by bltdavid View Post

                  Although not endorsed by NinjaTrader support,
                  you can use an abstract base class rather than
                  (or in addition to) the partial class idea.

                  I have posted about this technique before.

                  Good reading here, here, and here.

                  And how would i access the data later? Do you have an example implementation?

                  Comment


                    #10
                    Originally posted by olisav57 View Post
                    Do you have an example implementation?
                    Yes.

                    See inside the first post.

                    Comment


                      #11
                      Hello olisav57,

                      Thanks for your notes.

                      A simple example of creating a public List property in a NinjaScript could be seen below.

                      Code:
                      //class level variable
                      private List<int> myList = new List<int>();
                      
                      //Properties section of code
                      #region] Properties
                      public List<int> MyList
                      {
                      // We need to call the Update() method to ensure our exposed list is in up-to-date.
                      get { Update(); return myList; }
                      }
                      #endregion​


                      You could then access the List in a strategy by calling something like IndicatorName().ListName.

                      For example, to get the count of the list from the indicator in the strategy the code would look somthing like this: Print("IndicatorName().ListName.Count is " + IndicatorName().ListName.Count);

                      If you are seeing error messages, we would need to know exactly how you are defining the list in the code and how you are setting up the public property in the script. You could create a simple reduced test script that contains only the code used to reproduce the behavior and share the .cs file with us so we may take a look at it.

                      Indicators are located in the Documents\NinjaTrader 8\bin\Custom\Indicators directory. Strategies are located in the Documents\NinjaTrader 8\bin\Custom\Strategies folder.
                      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Yesterday, 05:17 AM
                      0 responses
                      66 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      141 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      76 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      47 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      51 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X