Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawTextFixed help

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

    DrawTextFixed help

    Hello,

    I am a newbie in NT and need to convert my Strategy Trader code to NT code. Will you please show the proper syntax for displacing the chart position in this code. I get errors but not sure what to correct. I need the values to be displayed on the chart (left top) like these:

    Position: Long
    Spread: 0.00023
    Hi: 0.12345 Lo: 0.12245

    Thank you,
    traderjh

    ST code:
    Code:
    DrwText.Create(new DrwCoordinate(Environment.DisplayedLeft, (Environment.DisplayedTop - 5) ),"Position: " + StrategyInfo.MarketPosition);
    DrwText.Create(new DrwCoordinate(Environment.DisplayedLeft, (Environment.DisplayedTop - 6) ),"Spread: " + Math.Round(showSpread,digitSize).ToString());
    DrwText.Create(new DrwCoordinate(Environment.DisplayedLeft, (Environment.DisplayedTop - 7) ),"High: "+Math.Round(Bars.High[0],5).ToString() +" Low: "+ Math.Round(Bars.Low[0],5).ToString());
    NT code:
    Code:
    DrawTextFixed("show" + CurrentBar, ("Position: " + Math.Round(GetAtmStrategyMarketPosition(),5).ToString()), (TextPosition.TopLeft + 0));
    DrawTextFixed("show" + CurrentBar, ("Spread: " + Math.Round(mySpread,5).ToString()), (TextPosition.TopLeft + 1));
    DrawTextFixed("show" + CurrentBar, ("Hi: " + Math.Round(High[0],5).ToString()) + "Hi: " + Math.Round(Low[0],5).ToString()) , (TextPosition.TopLeft + 2));

    #2
    Hello traderjh,

    Welcome to the NinjaTrader Support Forums!

    I looking at your code I do see a few things.

    Originally posted by traderjh View Post
    Hello,

    NT code:
    Code:
    DrawTextFixed("show" + CurrentBar, ("Position: " + Math.Round(GetAtmStrategyMarketPosition(),5).ToString()), (TextPosition.TopLeft + 0));
    DrawTextFixed("show" + CurrentBar, ("Spread: " + Math.Round(mySpread,5).ToString()), (TextPosition.TopLeft + 1));
    DrawTextFixed("show" + CurrentBar, ("Hi: " + Math.Round(High[0],5).ToString()) + "Hi: " + Math.Round(Low[0],5).ToString()) , (TextPosition.TopLeft + 2));
    1. The code in pink, GetAtmStrategyMarketPosition(), requires the AtmStrategyID to be passed to it, and returns a string not a double so you would not be able to use the Math.Round for it. You may want to view Help Guide that goes over the Different ATM Strategy Methods to see which one you would like to use.

    2. In the last line you have an extra ")" that stops your text short that you may want to remove. It is highlighted in yellow above.
    JCNinjaTrader Customer Service

    Comment


      #3
      DrawTextFixed help

      Thanks for your reply.

      My mistake. I meant for Position.MarketPosition not GetATMMarketPosition. I corrected this code and it works fine except for the chart position for each draw text value. All of them are overlapping each other. Can you tell me how to put them in line by line only on the upper left area?

      By the way, what does CurrentBar has to do with in these DrawTextFixed?

      Thanks again,
      traderjh

      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion
      
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          /// <summary>
          /// Display spread on the chart
          /// </summary>
          [Description("Display spread on the chart")]
          public class ShowSpread2 : Strategy
          {
              #region Variables
              // Wizard generated variables
              // User defined variables (add any user defined variables below)
              #endregion
      
              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
      	
              protected override void Initialize()
              {
                  CalculateOnBarClose = false;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      		double mySpread = (GetCurrentAsk() - GetCurrentBid());
      		DrawTextFixed("show" + CurrentBar, "Position: " + Position.MarketPosition.ToString(), TextPosition.TopLeft);
         	        DrawTextFixed("show" + CurrentBar, "Spread: " + Math.Round(mySpread,5).ToString(), TextPosition.TopLeft + 1);
      		DrawTextFixed("show" + CurrentBar, "Hi: " + Math.Round(High[0],5).ToString() + "Lo: " + Math.Round(Low[0],5).ToString() , TextPosition.TopLeft + 2); 
      			
      	}
      
              #region Properties
              #endregion
          }
      }

      Comment


        #4
        Hello traderjh,

        If a Drawing Object has the same string "tag" then the new one would over write the old one so the Current Bar is to make it so it give the "tag" a different name for each bar so that you have multiple drawing objects. Using "+ CurrentBar" is not something that you would typically use with DrawTextFixed as it would place the text over another causing the text to become unreadable.

        Looking at your code if you want all of the DrawFixedText() to fit on your seen you will want to either change how you are calling them or use the DrawText() method.

        Note as well, adding an integer to the TextPostion will just move it to another enum TextPosition parameter.

        Code:
        double mySpread = (GetCurrentAsk() - GetCurrentBid());
        DrawTextFixed("Show Position", "Position: " + Position.MarketPosition.ToString(), TextPosition.TopLeft);
        DrawTextFixed("Show Spread", "Spread: " + Math.Round(mySpread,5).ToString(), TextPosition.BottomLeft);
        DrawTextFixed("Show Hi&Lo", "Hi: " + Math.Round(High[0],5).ToString() + "Lo: " + Math.Round(Low[0],5).ToString() , TextPosition.TopRight);
        JCNinjaTrader Customer Service

        Comment


          #5
          DrawTextFixed help

          Ok. Thanks for the answer on Currentbar.

          But, I do not wish the text to be placed on each corner of the chart. Let me show you what I need for my code. I attached the screenshot for your review.

          Is there a way to code the texts in line by line instead of in each corner of the chart? Help Guide(DrawText or DrawTextFixed) doesn't explain how to position the texts in the chart unless I overlook something?

          Thanks,
          traderjh
          Attached Files
          Last edited by traderjh; 01-17-2013, 05:19 PM.

          Comment


            #6
            Hello traderjh,

            Thanks for the screenshot.

            You will want to use the new line (\n) method when working with strings to be able to accomplish this. It is a method native to working with C# strings. For example:

            Code:
            DrawTextFixed("Show Position", "Position: " + Position.MarketPosition.ToString()
            			+"\nSpread: " + Math.Round(mySpread,5).ToString()
            			+"\nHi: " + Math.Round(High[0],5).ToString() + "Lo: " + Math.Round(Low[0],5).ToString(), TextPosition.TopLeft);
            You may view the following link that goes over using strings in C# for more information and examples.

            http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx
            JCNinjaTrader Customer Service

            Comment


              #7
              Yes! Beautiful!

              Thank you for your direction to this.

              Regards,
              traderjh

              Comment


                #8
                Stumped!

                It was working fine until something came up and now there is no displays on the chart. I tried to figure out what was happening. I selected True for 'Enabled' and it will not stick to True. Now I am stumped. Perhaps you can shed some lights on this? Help will be much appreciated. See code and screenshot.

                What does (D) stand for?

                Thanks,
                -traderjh

                Code:
                #region Using declarations
                using System;
                using System.ComponentModel;
                using System.Diagnostics;
                using System.Drawing;
                using System.Drawing.Drawing2D;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Data;
                using NinjaTrader.Indicator;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Strategy;
                #endregion
                
                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                    /// <summary>
                    /// 
                    /// </summary>
                    [Description("")]
                    public class ShowData : Strategy
                    {
                        #region Variables
                        // Wizard generated variables
                        // User defined variables (add any user defined variables below)
                        #endregion
                
                        /// <summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        /// </summary>
                        protected override void Initialize()
                        {
                            CalculateOnBarClose = false;
                        }
                
                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                			double mySpread = (GetCurrentAsk() - GetCurrentBid());
                			DrawTextFixed("Show Position", 
                			"Position: "+ Position.MarketPosition.ToString()
                			+"\nSpread: " + Math.Round(mySpread,5).ToString()
                			+"\nHi: " + Math.Round(High[0],5).ToString() + " Lo: " + Math.Round(Low[0],5).ToString() 
                			+"\nHi: " + Math.Round(Highs[1][0],5).ToString() + " Lo: " + Math.Round(Lows[1][0],5).ToString()
                			,TextPosition.TopLeft);
                        }
                
                        #region Properties
                        #endregion
                    }
                }
                Attached Files

                Comment


                  #9
                  D means it is disabled. If you cannot set it to true, there is some sort of error on startup that is preventing it from working. You should be able to find an error on the Log tab of the control center from the time you tried to start the strategy.
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Ah! The error says Index was outside the bounds of the array. I got it fixed.

                    Thank you for your help!
                    -traderjh

                    Comment


                      #11
                      Overload?? Meaning?

                      I tried to add color to the text and couldn't get it right.

                      Code:
                      DrawTextFixed("Show data",Instrument.FullName,TextPosition.TopLeft,Color.Blue);
                      The error says "No overload for method 'DrawTextFixed' takes '4' arguments. Does this message mean I put too many arguments in that line?

                      Thanks again,
                      -traderjh

                      Comment


                        #12
                        Originally posted by traderjh View Post
                        I tried to add color to the text and couldn't get it right.

                        Code:
                        DrawTextFixed("Show data",Instrument.FullName,TextPosition.TopLeft,Color.Blue);
                        The error says "No overload for method 'DrawTextFixed' takes '4' arguments. Does this message mean I put too many arguments in that line?

                        Thanks again,
                        -traderjh
                        NT Help shows that the method uses either 3 or 8 parameters. Whichever signature you use, you MUST provide ALL the parameters. ref: http://www.ninjatrader.com/support/h...wtextfixed.htm

                        Intellisense should help prompt you for the correct parameters.

                        Comment


                          #13
                          Need clarifcation

                          Originally posted by koganam View Post
                          NT Help shows that the method uses either 3 or 8 parameters. Whichever signature you use, you MUST provide ALL the parameters. ref: http://www.ninjatrader.com/support/h...wtextfixed.htm

                          Intellisense should help prompt you for the correct parameters.
                          Ok, I did what you just indicated. Please bear with me. I coded here and I still didn't get it right:

                          Code:
                          DrawTextFixed("try",Instrument.FullName,TextPosition.TopLeft,Color.Blue,Font.ReferenceEquals,Color.Red,Color.Yellow,10);
                          Thanks again,
                          -traderjh

                          Comment


                            #14
                            Hello traderjh,

                            That is because of how you are calling the "Font" parameter. You may want to change it to something like "new Font("Arial", 15)".

                            You may view the following link for an example and description on how to use Font.

                            http://msdn.microsoft.com/en-us/library/164w6x6z.aspx
                            JCNinjaTrader Customer Service

                            Comment


                              #15
                              It works!

                              Originally posted by NinjaTrader_JC View Post
                              Hello traderjh,

                              That is because of how you are calling the "Font" parameter. You may want to change it to something like "new Font("Arial", 15)".

                              You may view the following link for an example and description on how to use Font.

                              http://msdn.microsoft.com/en-us/library/164w6x6z.aspx
                              Thank you for clarifying this. I wouldn't be able to find that "new Font("Arial", 15)" easily!

                              -traderjh

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mattdowns1234, Today, 06:57 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post mattdowns1234  
                              Started by dgee949, Today, 06:26 PM
                              0 responses
                              19 views
                              0 likes
                              Last Post dgee949
                              by dgee949
                               
                              Started by dgee949, Today, 05:58 PM
                              0 responses
                              26 views
                              0 likes
                              Last Post dgee949
                              by dgee949
                               
                              Started by thepcmd, Today, 05:14 PM
                              0 responses
                              31 views
                              0 likes
                              Last Post thepcmd
                              by thepcmd
                               
                              Started by xmess777, Today, 04:58 PM
                              0 responses
                              22 views
                              0 likes
                              Last Post xmess777  
                              Working...
                              X