Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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,


                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.


                        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 bmartz, 03-12-2024, 06:12 AM
                          5 responses
                          32 views
                          0 likes
                          Last Post NinjaTrader_Zachary  
                          Started by Aviram Y, Today, 05:29 AM
                          4 responses
                          13 views
                          0 likes
                          Last Post Aviram Y  
                          Started by algospoke, 04-17-2024, 06:40 PM
                          3 responses
                          28 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by gentlebenthebear, Today, 01:30 AM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by cls71, Today, 04:45 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X