• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to put some methods into a shared file, and let my indicator and strategy refer

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

    how to put some methods into a shared file, and let my indicator and strategy refer

    Hi,

    I have finished programming an indicator. The indicator basically contains a bunch of conditions and outputs some bool type variables to indicate entry/exit.

    Now I'm programming a strategy. I wonder if you can briefly teach me how to put some functions that output bool type in a separate file, and let my indicator refer to it. That way if I need to change my method, I don't need to change both indicator and strategy files.

    #2
    You will need to expose these bools publicly which can then be read directly from the strategy. You would not need to write to a separate file with this method.

    Please see our Reference Sample on Exposing indicator values that are not plots

    http://www.ninjatrader.com/support/f...ead.php?t=4991
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hi Thanks for reply.

      I tried the same as the example below.

      Code:
                  Add(MACD(12, 26, 9));
                  Add(SampleBoolSeries());
      But the problem is that my strategy is a multi-timeframe strategy.

      I can only add indicator to the primary data series, but can't add to my secondary data series.

      Is there a way to work around this?

      Comment


        #4
        Hi Leon, what you experience is expected - if you wish to Add() an indicator working on another series, please do those calcs in the added indicator itself.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          if you wish to Add() an indicator working on another series, please do those calcs in the added indicator itself.
          Sorry, what does this mean?

          So say if I firstly added a secondary series by:
          Add(PeriodType.Ticks, 500);

          Then how do I run the indicator SampleBoolSeries() on that secondary series?

          Comment


            #6
            Hello,

            The Add() method would only be used for visual charting purposes. If you wanted to visualize this indicator on the chart from a secondary data series, you would need to manually add the indicator to your chart.

            However you can still reference the indicator methods in your strategy and specify which data series it is being calculated from

            Taking the SampleBoolSeries for example, the conditional logic would read:

            Code:
            if(SampleBoolSeries(BarsArray[1]).BullIndication[0])
            				EnterLong();
            By using BarsArray[1], we are specifying that this indicator is calculated from the first Add() data series you have in your strategy.

            More information on BarsArray can be found below:

            http://www.ninjatrader.com/support/h.../barsarray.htm
            MatthewNinjaTrader Product Management

            Comment


              #7
              Hi I think my question would really be: how to build a strategy and indicator referencing a external library? Is there an example for it?

              Comment


                #8
                Hello,

                It is possible to have your indicator or strategy read from an external file.

                Please see our Reference Sample on Using StreamReader to read from a text file


                http://www.ninjatrader.com/support/f...ead.php?t=3476
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Originally posted by NinjaTrader_Matthew View Post
                  Hello,

                  The Add() method would only be used for visual charting purposes. If you wanted to visualize this indicator on the chart from a secondary data series, you would need to manually add the indicator to your chart.

                  However you can still reference the indicator methods in your strategy and specify which data series it is being calculated from

                  Taking the SampleBoolSeries for example, the conditional logic would read:

                  Code:
                  if(SampleBoolSeries(BarsArray[1]).BullIndication[0])
                                  EnterLong();
                  By using BarsArray[1], we are specifying that this indicator is calculated from the first Add() data series you have in your strategy.

                  More information on BarsArray can be found below:

                  http://www.ninjatrader.com/support/h.../barsarray.htm
                  Thank you. So does it mean that it does not matter whether "Add(SampleBoolSeries());" is added into Initialize(), the strategy will work the same?


                  Code:
                          protected override void Initialize()
                          {
                              // Add our indicators to the strategy for charting purposes
                              Add(MACD(12, 26, 9));
                              Add(SampleBoolSeries());
                              
                              CalculateOnBarClose = true;
                          }

                  Comment


                    #10
                    Hello leontancfa,
                    Thanks for your note and I am replying for Matthew.

                    Yes, the strategy will work fine even if you do not Add the indicator in the initialize section of the strategy.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      what is the benefit of having a private variable,
                      Code:
                              #region Variables
                              private BoolSeries aBC;
                              #endregion
                      and then have a public property?
                      Code:
                              public BoolSeries ABC
                              {
                                  get { return aBC; }
                              }
                      what could go wrong if I just make the variable public, and get the bool value by MyIndicator.aBC[0]?

                      Comment


                        #12
                        Originally posted by leontancfa View Post
                        what is the benefit of having a private variable,
                        Code:
                                #region Variables
                                private BoolSeries aBC;
                                #endregion
                        and then have a public property?
                        Code:
                                public BoolSeries ABC
                                {
                                    get { return aBC; }
                                }
                        what could go wrong if I just make the variable public, and get the bool value by MyIndicator.aBC[0]?
                        Mainly because it is the best practice in most cases.

                        ref: http://msdn.microsoft.com/en-us/library/w86s7x04.aspx

                        Comment


                          #13
                          Thank you. so I read that reference. I saw one reason is to let outside the indicator only read, but not set the value of the inner variable.

                          Did I miss other reasons?

                          Comment


                            #14
                            Originally posted by leontancfa View Post
                            Thank you. so I read that reference. I saw one reason is to let outside the indicator only read, but not set the value of the inner variable.

                            Did I miss other reasons?
                            That main import of separating Properties from the value of the backing store is in this paragraph:

                            "Properties have many uses: they can validate data before allowing a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields."

                            The funny thing about programming is that you may think at this time that you do not need any of those abilities, so you can dispense with them and just use a public variable. In my experience, however, sooner or later, if one continues development, one will find that he/she wants to do something which would be very easy to do, if only Properties had been used in the first place.

                            Best practices get dubbed as such, because the collective wisdom of those who have come before us, have found out the hard way, that not doing things in that manner, often causes regrets down the road.

                            Just my $0.02.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by dltharpe, Today, 09:17 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post dltharpe  
                            Started by HiddenPhilosopher, Today, 06:45 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post HiddenPhilosopher  
                            Started by PG7940, Today, 04:26 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post PG7940
                            by PG7940
                             
                            Started by marcus2300, Today, 02:25 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post marcus2300  
                            Started by drpapp, 01-24-2019, 06:57 AM
                            5 responses
                            69 views
                            0 likes
                            Last Post pjsmith
                            by pjsmith
                             
                            Working...
                            X