Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy/indicator startup sequence is different when...

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

    Strategy/indicator startup sequence is different when...

    There are 3 main ways I start/restart a strategy:
    1) Add a strategy for first time and enable it through Strategy Dialog
    2) Refresh chart that has running strategy on it by pressing F5.
    3) Using Strategies Tab of ControlPanel. Clicking on Enable checkbox to stop/start the strategy.

    I have found that the indicators that the strategy loads do not get initialized the same way in each of these scenarios.

    The attached sample strategy shows that in scenario 3 (Strategies Tab of ControlPanel) , the ChartPanel property of each indicator is null when the strategy is started from the Strategies Tab, when in the other two scenarios, it is correctly initialized.

    Seems like a bug because the code goes through all the states as expected and the ChartPanel is still null in the OnBarUpdate method.

    Gary
    Attached Files

    #2
    Hello GaryAlbers,

    Thank you for your note.

    Aspects related to visual display and or the chart, are going to be ignored when applying a strategy directly to the strategies tab, as it has no chart to be associated with. Only strategies applied directly to a chart, will such calls as AddChartIndicator be relevant.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      The 3 scenarios I listed in my first post all started by simply adding the Strategy to a chart.
      So the exclusion you mention does not apply to this situation.

      To recap:
      - I added the enabled strategy to a chart (the strategy shows up in the strategies tab)
      - I turn the strategy off/on via the Enable check box.
      - The indicator(s) are not properly initialized.

      If the strategy is hosted by a chart (so clearly not the excluded scenario you mention) then when it is enabled via the check box on the strategies tab, the life cycle of the indicators and strategy should be the same as if it was enabled from the chart.


      Gary

      Comment


        #4
        Hello GaryAlbers,

        So I can best answer your question, may I confirm you're seeing what I pointed out in the screen shot?

        That is, if in all cases the strategy was applied to a chart. 1) Enabling from the chart , ChartPanel will be null 2) If reenabling from the strategies tab, ChartPanel will be null. 3) If reloading NinjaScript with F5, chart control will not be null?

        I look forward to your reply.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Yes, your screen shot is what I get also.

          Comment


            #6
            Hello GaryAlbers,

            When initially applying the strategy there are no existing ChartPanels, at least at the time of the print.

            When disabling the strategy, plots/indicators are removed, upon reapplying their are none existing at the time of the print.

            However when reloading NS with F5, ChartPanels already exist, thus when your print statements run, these are not null.

            Please let us know if this is unclear or if you need further information.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Alan,
              You are missing the point. From a developers point of view, I just want to know that no matter how the strategy/indicator is started from within Ninja, my code is doing the right thing in the right place so that I properly utilize the features provided by ninjascript.

              In this case, the ChartPanel was needed so I could set a property. I just want to know where is the proper place (state) to do that. According to the doc, it seems like state==CONFIGURE would be the correct place. However, this test shows ninja does not have all the stuff initialized at that time.

              I think that is a bug because they all seem to logically be doing the same thing: starting my indicator.
              However, it could mean there is just some other state when this can be safely done. What is the correct way or correct state to consistently set ChartPanel attributes?

              Gary

              Comment


                #8
                Hello GaryAlbers,

                You should reference ChartIndicators[int index], rather than the indicator object which looks to be null until OBU.

                In the attached screen shot, I call AddChartIndicator in DataLoaded and print the indicators panel in State.Historical.

                Please see,
                https://ninjatrader.com/support/help...indicators.htm

                Please let us know if you need further assistance.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Alan,

                  Your code also did not demonstrate any improved access to the indicator.ChartPanel by waiting until the DataLoaded or Historical state. The result is the same: in OnBarUpdate, the indicator.ChartPanel is still null in scenarios 1 and 3.

                  I will say again, I believe that Ninja is not initializing the UI elements of the indicator in the same way for the 3 scenarios, but it should be.

                  Gary

                  Comment


                    #10
                    Hello GaryAlbers,

                    What is it you are trying to do exactly, what property are you trying to set?

                    I look forward to you reply.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      I will set any property needed to programatically get two indicators to show up on the same panel. Tell me which I should use.
                      The 'Panel' property seemed logical so I tried that.
                      Code:
                      macd = MACD(12,26,9);
                      macd.Panel = 2;
                      macd.ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Left;			
                      stoc = Stochastics(7,14,3);
                      stoc.Panel = 2;
                      AddChartIndicator(macd);
                      AddChartIndicator(stoc);
                      A screen shot of what I am expecting is attached.

                      Gary
                      Attached Files

                      Comment


                        #12
                        Hello GaryAlbers,

                        The same issue you posted about in the following thread for which I said I would update you when I had more information.
                        https://ninjatrader.com/support/foru...d.php?t=106089

                        I am still waiting to hear from development on whether this is a bug or not.

                        Going forward it would be appreciated if you didn't open more than one thread with the same issue.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Alan,

                          My apologies. When you asked 'what property am I setting' I responded thinking that this was the thread regarding that issue because it is all about setting a property and and not getting the expected result.

                          Regarding this thread, the issue is that the different ways of starting a strategy have different internal results and make it tricky to program correctly.
                          I wanted to set a property but depending on how the strategy is started up, the property may be null. The example code I posted is the same but it demonstrates the two different issues. I have had this issue in the past on other properties, but just posted this example because I already had the sample that showed it.

                          I viewed this issue as a strategy 'life cycle' question, so different in my mind.

                          Gary

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by 7robert, Today, 07:48 PM
                          1 response
                          14 views
                          0 likes
                          Last Post NinjaTrader_EricB  
                          Started by saltminer, Today, 06:32 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post saltminer  
                          Started by caveat_lector, Today, 06:13 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post caveat_lector  
                          Started by patricia70, Today, 06:07 AM
                          8 responses
                          36 views
                          0 likes
                          Last Post bltdavid  
                          Started by MatthewLesko, Today, 04:19 PM
                          2 responses
                          5 views
                          0 likes
                          Last Post MatthewLesko  
                          Working...
                          X