Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator inside a Strategy

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

    Indicator inside a Strategy

    I have a self written indicator that gives an external bool signal which I have referenced in my strategy. When i run tho the strategy in Visual Studio I dont see it go tho the indicator code and the bool from the indicator is returning false as it dosent apear to be checking the indictor logic for true. Hope this makes sense. when would the code for the indicator be run?

    When the strategy gets to :-

    Code:
    this.MyIndicator.ExternalSignal
    I expected it to run the code and equate to true but it is just reading it as false and continuing?

    Also when I run the code on historical data I am seeing no executions while I am on the same data when run live. I have no filters in place for if(Historical).

    #2
    GKonheiser, how is the bool variable exactly exposed for access? Did you include an Update() call in the property getter as shown here in our sample? http://www.ninjatrader.com/support/f...ead.php?t=4991

    For the executions it would be coming down to debug what exactly is differently evaluated then in both environments (so historical vs live) - do you change the CalculateOnBarClose setting here or is it kept the same for your script?

    Comment


      #3
      Hi bertrand,

      I am not using a bool series just a public bool like this:-

      I am adding the indicator:-

      Code:
      private PrimeDivergence pDiv;
      then checking the logic here:-

      Code:
      if([U]this.pDiv.longDiv[/U] && oscSignalLong == false )   // logic for DivOsc signal
      					{
      						oscSignalLong = true;		
      					}
      so how would I implement the update method in this case?

      Or should I just integrate the indicator code in the strategy?

      Thanks for you help and merry christmas

      Comment


        #4
        Hi GKonheiser,

        Is this the call you make from the external indicator or strategy you are calling this indicator with?

        May I see your public bool code in the indicator?

        Even if you are returning bool and not a bool series, the Update() call causes OnBarUpdate to run and make sure it returns you and updated value.

        For example:

        public bool MyBool
        {
        get { Update(); return myBool; }
        set { }
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea

          In my indicator I have the public bool,

          Code:
          	public bool longDiv,shortDiv;
          In my strategy I call it with,

          Code:
           this.pDiv.longDiv

          Comment


            #6
            Hi GKonheiser,

            Please try using a get and set with the public bool that returns and sets a private variable.

            In the get, run Update() before returning the private variable.

            Let me know if this does not work.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Sorry for the delay in getting back to you.

              I use the update() method in the properties of the Indicator not the strategy right?

              Comment


                #8
                That's correct in understanding GKonheiser

                Comment


                  #9
                  If I use the Update() method in my strategy for my indicators public variables, does the code run from the top of the OnBarUpdate code until it reaches the Update() method in the Strategy code, THEN run tho all the OnBarUpdate code in the Indicator, THEN continue on with the strategy code?

                  I ask because when I move thou the code with Visual Studio, the public bool is true in the Indicator but sometime false in the Strategy?

                  Comment


                    #10
                    Hello GKonheiser,

                    When adding Update() to the public variable declaration get { } section (before the returned variable), this will cause OnBarUpdate to be run before the variable is returned giving the variable a chance to update before it is returned to the script calling this indicators value.

                    Adding Update() to a strategy directly will not have any affect on updating the indicator before variable is returned.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Sorry yes I have the Update method in my Indicator not the strategy but I am still getting a discrepancy between what im seeing in the indicator and the strategy?

                      IE I have a variable that shows true in the indicator and false in the strategy despite an Update call in the indicator.

                      Comment


                        #12
                        Hello GKonheiser,

                        Can you isolate this and make an example strategy and indicator that just updates this value with no other code?

                        Then please attach an export so that I may test.

                        To export your script do the following:
                        1. Click File -> Utilities -> Export NinjaScript
                        2. Enter a unique name for the file in the value for 'File name:'
                        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                        By default your exported file will be in the following location:
                        • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                        Below is a link to the help guide on Exporting NinjaScripts.
                        http://www.ninjatrader.com/support/h...nt7/export.htm
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          For now I've just gone ahead and combined the indicator and the strategy to make things easier. Thanks for the help.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          650 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          577 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X