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

Draw.TextFixed in indicator not diplayed by strategy

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

    Draw.TextFixed in indicator not diplayed by strategy

    Ok, another code migration from NT 7 and NT 8 and difference in behavior.

    In my NT 7 indicator code I had the following code to display the 'settings' in the Bottom Left of the chart:
    protected override void OnStartUp()
    {
    infoText = " indicators settings list"
    DrawTextFixed("IndicatorParameters", infoText, TextPosition.BottomLeft, Color.Gray, new Font("Arial",8,FontStyle.Bold), Color.Black, Color.Black, 15);

    }

    when I called the indicator from the strategy I had the settings always displayed in the charts so I always know which settings are being used by the strategy.

    In my NT 8 indicator code I have the following:

    ... else if (State == State.DataLoaded)
    {
    infoText = " indicators settings list"
    Draw.TextFixed(this, "IndicatorParameters", infoText, TextPosition.BottomLeft);
    }


    What is happening is that now the strategy calling the code above is not displaying the settings (infoText) in the chart anymore. The indicator shows infoText, but the strategy calling the indicator does not. The strategy is calling the indicator correctly and working correctly, but the 'infoText" is not being displayed anymore.
    Can you let me know what am I doing wrong?

    Thanks!

    #2
    Where did you add the strategy? The chart or control center?

    Comment


      #3
      The chart.

      Comment


        #4
        Hello ds1111,

        Thanks for your post.

        Try moving the Draw.Text() to the OnBarUpdate() method.

        Something like:

        if (CurrentBar == 0)
        {
        Draw.Text(....
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I moved the 'infotext' code to the "OnBarUpdate" method of the indicator using the CurrentBar == 0 as you described.

          The strategy still doesn't display 'infotext'.

          I still don't like this approach (besides not working) because I like to avoid unnecessary checks under OnBarUpdate as I run most strategies on each tick.

          What is the equivalent of OnStartUp() on NT 8?
          When the strategy calls the indicator (and of course I added the indicator in the strategy using AddChartIndicator) isn't the (State == State.DataLoaded) structure in the indicator called?
          In NT 7 when I called my indicator from the strategy, OnStartUp() was executed and infoText was displayed.
          I'm trying to understand why the same behavior is not seen on NT 8.

          Comment


            #6
            Hello ds1111,

            Thanks for your reply.

            What version of NinjaTrader8 are you using? (found in Help>about)

            If you run the indicator standalone, does it display infotext as expected?

            Do you see any error messages in the NinjaTrader control center's "Log" tab related to the strategy or indicator?
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              This is the version: 8.0.4.0 64-bit

              And yes, it displays infotext when using the indicator alone. When I add the indicator in the strategy as I used to do in NT 7 it doesn't display anymore.

              There are no errors on the log. As I said, the strategy works as expected.

              What is the equivalent of "OnStartUp" on NT 8?

              Thanks.

              Comment


                #8
                Hello ds1111,

                Thanks for your reply.

                Yes, NT7s OnStartUp() would be State.DataLoded in NT8. Please see: http://ninjatrader.com/support/helpG..._practices.htm

                Can you provide a small example of the code you are using that is not providing the information you are looking to display?

                Alternatively, if you would prefer, feel free to write into PlatformSupport[at]Ninjatrader[dot]com with your source files and mark the e-mail atten:Paul and a link to this thread.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  The code in the indicator is in my first post.

                  The code in the strategy is as follows:
                  -----------------------------
                  ... else if (State == State.DataLoaded) // add indicators
                  {

                  PivotIndicatorC = PivotC(indicator_setting_1, indicator_setting_2, etc);
                  AddChartIndicator(PivotIndicatorC);


                  }
                  -----------------------------


                  The indicator is receiving the correct setting list to be displayed in infotext, because the strategy works fine. It seems that "Draw.TextFixed(this, "IndicatorParameters", infoText, TextPosition.BottomLeft); " in the indicator fails when called from the strategy for some reason. Could it be because of the owner "this"?

                  Any suggestion? Again, this code worked perfectly on NT 7.

                  An easy way to reproduce would be to create an indicator called mySMA, code Draw.TextFixed to print the period, and then code a strategy to call mySMA and see if Draw.TextFixed would print the period on the chart. I didn't have time to do that, but I may do that tomorrow if you don't have any suggestions meanwhile. It seems to be a bug with Draw.TextFixed rendering.

                  Comment


                    #10
                    Hello ds1111,

                    Thanks for your reply.

                    I followed your directions and repeated the results you have observed where DrawTextFixed does not display. However, if you move the DrawTextFixed() in the indicator into the OnbarUpdate() section it will work.

                    Indicator code:
                    Code:
                    			else if (State == State.Configure)
                    			{
                    				priorSum	= 0;
                    				sum			= 0;
                    			}
                    //			else if (State == State.DataLoaded)
                    //			{
                    //				infoText = Period.ToString();
                    //				Draw.TextFixed(this, "IndicatorParameters", "Test: "+infoText, TextPosition.BottomLeft);							
                    //			}
                    
                    		}
                    
                    		protected override void OnBarUpdate()
                    		{
                    			if (CurrentBar == 0)
                    			{
                    				infoText = Period.ToString();
                    				Draw.TextFixed(this, "IndicatorParameters", "Test: "+infoText, TextPosition.BottomLeft);							
                    			}

                    Strategy code:

                    Code:
                    			else if (State == State.Configure)
                    			{
                    				testSMA = mySMA(21);
                    			}
                    			else if (State == State.DataLoaded)
                    			{
                    				AddChartIndicator(testSMA);
                    			}
                    			
                    		}
                    
                    		protected override void OnBarUpdate()
                    		{
                    Attached Files
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for doing this, I really appreciate.

                      I find this odd and inefficient. I need this check just at start up, I don't need it for every tick doing it at OnBarUpdate.

                      Is there another way to do this? maybe on state=historical? That also seems to imply that DataLoaded is not the same as "OnStartup" on NT 7. Can you check with your engineers?

                      In the end I'm finding the new state implementation much harder than the simple NT 7 implementation using Initialize, etc. In all the upgrades of code that's where I'm finding the most problems. I hope a great guideline comes out comparing both architectures (NT 7 and NT 8).

                      Thanks again.

                      Comment


                        #12
                        Hello,

                        Thanks for your reply.

                        While I used if(CurrentBar==0) you do not have to use that as what is important for you is that when your strategy starts that your indicator information appear. You might look at other areas of your code where you are already performing a check of some type and add in your drawtext statement. For example does your code do a minimum current bars check? If so, you can easily add your statement there.

                        If you like I could write up a feature request to add the ability to use DrawText from OnStateChange().

                        If you haven't already reviewed, here are a few links that may help on NT8:
                        http://ninjatrader.com/support/helpG...tatechange.htm
                        http://ninjatrader.com/support/helpG...fecycle_of.htm
                        http://ninjatrader.com/support/helpG...ng_changes.htm
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          DrawTextFixed in Strategy kills Strategy Analyzer

                          @NinjaTrader_Paul ,

                          Trying to do a simple Drawtextfixed in STRATEGY AND have Strategy Analyzer backtest.

                          Draw works fine in the if(currentbar==0) for printing on chart.


                          BUT Strategy Analyzer fails doing the back testing. I had also been successful putting the DrawTextFixed in various other place like onbarupdate. Unfortunately even placing there kills the strategy analyzer.

                          When code is in the strategy - no backtest works, comment the line and the analyzer works.

                          It seems to be such as minor item to do a draw text in a strategy -- can you help?


                          UPDATE UPDATE UPDATE:

                          My final effort is looking to place the Draw.Text within if statements BUT for now I just want Draw.Text to work and not kill the strategy Analyzer. So only using this basic line of code:

                          Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + " IS SIM" + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0); // S/A NOT WORKING

                          Went back through this thread and again tried placing it:

                          if (State == State.SetDefaults)
                          if (State == State.Configure)
                          if( State == State.DataLoaded ) WHERE SUGGESTED IN THREAD
                          if (State == State.Historical)
                          protected override void OnBarUpdate()
                          protected override void OnMarketData(MarketDataEventArgs e)


                          Strategy Analyzer woks if placed here But then the Draw.Text is not drawn
                          if (State == State.Terminated)


                          Once I find a place to do a Draw.TextFixed AND Strategy Analyzer works the actual code I hope to use which includes a bool:

                          #region Acct Posting

                          if ((ACCTnamed == true) || (Account.Name == "Sim101"))
                          {
                          Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + " IS SIM" + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0);
                          }

                          else
                          if (ACCTnamed == true)
                          {
                          Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + ".", TextPosition.Center, ChartControl.Properties.ChartText, myFont, Brushes.Blue, Brushes.Transparent, 0);
                          }

                          #endregion


                          Thank you for your assistance.
                          Last edited by JMont1; 07-21-2018, 12:01 PM.

                          Comment


                            #14
                            Hello JMont1,

                            Thank you for the reply.

                            The problem here is that you are referencing properties of the chart when it is not present and creating an error situation which stops the analyzer. If you plan to use the ChartControl you need to ensure to check if it is null or not, I do not see you have done this in the sample you provided.

                            Code:
                            ChartControl.Properties.ChartText
                            ChartControl is null when you run the backtest, and is only available when a regular chart tab is opened and the script is processed. To avoid the problem, you should either check if ChartControl == null to use a backup brush, or just avoid using ChartControl and use defined brushes or input brushes.

                            Code:
                            Brush chartText = Brushes.Red;
                            if (ChartControl != null)
                            { 
                                chartText = ChartControl.Properties.ChartText; 
                            }
                            Draw.TextFixed(this, "strategyAccountName", "" + Account.Name + ".", TextPosition.Center, [B]chartText[/B], new SimpleFont(), Brushes.Blue, Brushes.Transparent, 0);
                            I look forward to being of further assistance.
                            Last edited by NinjaTrader_Jesse; 07-23-2018, 07:31 AM.
                            JesseNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Mizzouman1, Today, 07:35 AM
                            4 responses
                            18 views
                            0 likes
                            Last Post Mizzouman1  
                            Started by philmg, Today, 01:17 PM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_ChristopherJ  
                            Started by cre8able, Today, 01:01 PM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by manitshah915, Today, 12:59 PM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by ursavent, Today, 12:54 PM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X