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

Drawing a line

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

    Drawing a line

    Hello,

    I'm trying to draw a line as outlined in the NinjaTrader manual https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?draw_line.htm

    ​However, when I attempted to compile the code, I encountered errors stating : "resource does not contain a definition for NinjaScriptIndicatorDescriptionONELINE" and "resource does not contain a definition for NinjaScriptIndicatorNameONELINE."

    Any assistance in resolving this issue would be greatly appreciated

    Thank you

    Here the code :
    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        
        public class ONELINE : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionONELINE;
                    Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameONELINE;
                    IsSuspendedWhileInactive    = true;        
                }            
            }
            
            protected override void OnBarUpdate()
            {
                // Draws a dotted lime green line from 10 bars back to the current bar
                // with a width of 2 pixels
           Draw.Line(this, "tag1", false, 10, 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
    
            }
        }
    
    }​
    Last edited by kiro1000; 02-08-2024, 04:35 AM.

    #2
    Hello kiro1000,

    The language resource dictionaries are used to translate to other languages.

    The resource dictionary does not have key for NinjaScriptIndicatorDescriptionONELINE or NinjaScriptIndicatorNameONELINE.

    You will need to use your own string instead.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for your guidance. I followed your instructions, but unfortunately, I'm still encountering the same errors. Appreciate your assistance.

      here the updated code

      Code:
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          
          public class MYOWNSTRING : Indicator
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionMYOWNSTRING;
                      Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameMYOWNSTRING;
                      IsSuspendedWhileInactive    = true;        
                  }            
              }
              
              protected override void OnBarUpdate()
              {
                  // Draws a dotted lime green line from 10 bars back to the current bar
                  // with a width of 2 pixels
             Draw.Line(this, "tag1", false, 10, 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
      
              }
          }
      
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
              private MYOWNSTRING[] cacheMYOWNSTRING;
              public MYOWNSTRING MYOWNSTRING()
              {
                  return MYOWNSTRING(Input);
              }
      
              public MYOWNSTRING MYOWNSTRING(ISeries<double> input)
              {
                  if (cacheMYOWNSTRING != null)
                      for (int idx = 0; idx < cacheMYOWNSTRING.Length; idx++)
                          if (cacheMYOWNSTRING[idx] != null &&  cacheMYOWNSTRING[idx].EqualsInput(input))
                              return cacheMYOWNSTRING[idx];
                  return CacheIndicator<MYOWNSTRING>(new MYOWNSTRING(), input, ref cacheMYOWNSTRING);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
              public Indicators.MYOWNSTRING MYOWNSTRING()
              {
                  return indicator.MYOWNSTRING(Input);
              }
      
              public Indicators.MYOWNSTRING MYOWNSTRING(ISeries<double> input )
              {
                  return indicator.MYOWNSTRING(input);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
              public Indicators.MYOWNSTRING MYOWNSTRING()
              {
                  return indicator.MYOWNSTRING(Input);
              }
      
              public Indicators.MYOWNSTRING MYOWNSTRING(ISeries<double> input )
              {
                  return indicator.MYOWNSTRING(input);
              }
          }
      }
      
      #endregion
      ​
      I encountered errors stating :
      "resource does not contain a definition for NinjaScriptIndicatorDescriptionMYOWNSTRING"
      and
      "resource does not contain a definition for NinjaScriptIndicatorNameMYOWNSTRING"

      ​Thanks

      Comment


        #4
        Hello kiro1000,

        The effected code is the same in post # 3 as it is in post # 1 and the direction was not followed.

        Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMYOWNSTRING;
        Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMYOWNSTRING;​

        NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMYOWNSTRING doesn't exist.
        NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMYOWNSTRING doesn't exist.

        Use your own string as directed in post # 2.


        Description = "My description here";
        Name = "Name of my script here";
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          I appreciate your guidance on using my own string for the indicator description and name. However, I encountered a challenge while updating the code. All the indicators I've come across in the NinjaTrader Library follow a specific naming convention, as shown in the examples below:​

          Code:
          SUM indicator
          public class SUM : Indicator
              {
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionSUM;
                          Name                        = NinjaTrader.Custom.Resource.
          
          
          **********
          VOL Indicator
          public class VOL : Indicator
              {
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                    = Custom.Resource.NinjaScriptIndicatorDescriptionVOL;
                          Name                        = Custom.Resource.NinjaScriptIndicatorNameVOL;
          
          *************​
          I've updated the code as per your instructions, modifying the name because I couldn't find information about the description in the NinjaTrader manual. However, I encountered an error: "Cannot convert method group 'ONELINE' to non-delegated type 'string'. Did you intend to invoke the method?"

          Any assistance in resolving this issue would be greatly appreciated.

          Thank you.

          Here the updated code :​

          Code:
          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          
          
          namespace NinjaTrader.NinjaScript.Indicators
          {
              
              public class ONELINE : Indicator
              {
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          //Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionMYOWNSTRING;
                          Name                        = ONELINE;
                          IsSuspendedWhileInactive    = true;        
                      }            
                  }
                  
                  protected override void OnBarUpdate()
                  {
                      // Draws a dotted lime green line from 10 bars back to the current bar
                      // with a width of 2 pixels
                 Draw.Line(this, "tag1", false, 10, 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
          
                  }
              }
          
          }
          ​
          Error : "Cannot convert method group 'ONELINE' to non-delegated type 'string'. Did you intend to invoke the method?"

          Comment


            #6
            Hello kiro1000,

            As mentioned in post # 2, NinjaTrader has a resource dictionary to translate our system indicator names and descriptions to other languages. Our resource dictionary does not have your custom translations.

            Your class is ONELINE. This is not a string.

            A string is text between quotation marks.

            See post # 4 where I have suggested using strings (not the class object).

            Description = "My description here";
            Name = "Name of my script here";
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              I apologize for any confusion earlier. I've successfully compiled the code after implementing your suggestions and using strings for the Description and Name. However, I've encountered an issue where the dotted line is not being plotted as expected.

              Click image for larger version  Name:	2024-02-09 20_16_54-Chart - MNQ MAR24.png Views:	0 Size:	23.9 KB ID:	1290665

              Here's the updated code:
              Code:
              #region Using declarations
              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.ComponentModel.DataAnnotations;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using System.Windows;
              using System.Windows.Input;
              using System.Windows.Media;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Gui;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Gui.SuperDom;
              using NinjaTrader.Data;
              using NinjaTrader.NinjaScript;
              using NinjaTrader.Core.FloatingPoint;
              using NinjaTrader.NinjaScript.DrawingTools;
              #endregion
              
              
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  
                  public class ONELINE : Indicator
                  {
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description = "Draws a dotted line";
                              Name = "ONELINE";        
                          }            
                      }
                      
                      protected override void OnBarUpdate()
                      {
                          // Draws a dotted lime green line from 10 bars back to the current bar
                          // with a width of 2 pixels
                     Draw.Line(this, "tag1", false, 10, 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
              
                      }
                  }
              
              } 
              ​
              Thank you
              Last edited by kiro1000; 02-09-2024, 01:22 PM.

              Comment


                #8
                Hello kiro1000,

                On each new bar the object is moved to the last bar (as you are not using unique tag names.

                The line is being drawn at a price of 1000 which is not in range of the price scale. I recommend you set isAutoScale to true so that you can see where this is being drawn.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea,

                  I've made the adjustments as per your recommendations, and here is the updated code:
                  Code:
                  #region Using declarations
                  using System;
                  using System.Collections.Generic;
                  using System.ComponentModel;
                  using System.ComponentModel.DataAnnotations;
                  using System.Linq;
                  using System.Text;
                  using System.Threading.Tasks;
                  using System.Windows;
                  using System.Windows.Input;
                  using System.Windows.Media;
                  using System.Xml.Serialization;
                  using NinjaTrader.Cbi;
                  using NinjaTrader.Gui;
                  using NinjaTrader.Gui.Chart;
                  using NinjaTrader.Gui.SuperDom;
                  using NinjaTrader.Data;
                  using NinjaTrader.NinjaScript;
                  using NinjaTrader.Core.FloatingPoint;
                  using NinjaTrader.NinjaScript.DrawingTools;
                  #endregion
                  
                  
                  namespace NinjaTrader.NinjaScript.Indicators
                  {
                      
                      public class ONELINE : Indicator
                      {
                          protected override void OnStateChange()
                          {
                              if (State == State.SetDefaults)
                              {
                                  Description = "Draws a dotted line";
                                  Name = "ONELINE";        
                              }            
                          }
                          
                          protected override void OnBarUpdate()
                          {
                              // Draws a dotted lime green line from 10 bars back to the current bar
                              // with a width of 2 pixels
                         Draw.Line(this, "tag1",true, 10, 17800, 0, 18200, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                        
                          }
                      }
                  
                  }​

                  However, despite these changes, I'm still unable to see the line being drawn on the chart.
                  Thank you for your continued support.​

                  Comment


                    #10
                    Hello kiro1000,

                    After making changes may I confirm you have compiled and reloaded the script?

                    May I have an updated screenshot with the chart showing the last bar on the chart?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      Yes, I have compiled the script and reloaded it into NinjaTrader. Here is the updated screenshot with the chart:​


                      Click image for larger version

Name:	22_44_44-Chart - MNQ MAR24.png
Views:	62
Size:	26.1 KB
ID:	1290679

                      Comment


                        #12
                        Hello kiro1000,

                        The line is drawn at 17800 and is below the price range of the chart.

                        Click the F to return to autoscaling and it should be at the bottom of the chart.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          Thank you for your continued assistance. I recompiled the code, added it to the chart, and clicked on the F to return to autoscaling, but unfortunately, the line is still not appearing at 17800.

                          Here is the updated screenshot with the chart:


                          Comment


                            #14
                            Hello kiro1000,

                            May I have an export of the test script to test on my end?

                            To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                            1. Click Tools -> Export -> NinjaScript Add-on...
                            2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                            3. Click the 'Export' button
                            4. Enter the script name in the value for 'File name:'
                            5. Choose a save location -> click Save
                            6. Click OK to clear the export location message
                            By default your exported file will be in the following location:
                            • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                            Below is a link to the help guide on Exporting NinjaScripts.


                            Once exported, please attach the file as an attachment to your reply.​
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Chelsea,

                              Certainly, I appreciate your willingness to assist. I have exported the test script as instructed. Here is the attached file named "OneLine.zip"

                              Please let me know if there's anything else needed for further analysis.​
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,982 views
                              3 likes
                              Last Post jhudas88  
                              Working...
                              X