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

string text question

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

    string text question

    can anybody tell me why the following does not work?

    Code:
    private string path = Cbi.Core.UserDataDir.ToString() + "tradingDay";
    the idea is to add a property with enumerator including monday-friday.

    text files are located on hard drive and will be named monday, tuesday,..., friday

    thanks

    #2
    Originally posted by duck_CA View Post
    can anybody tell me why the following does not work?

    Code:
    private string path = Cbi.Core.UserDataDir.ToString() + "tradingDay";
    the idea is to add a property with enumerator including monday-friday.

    text files are located on hard drive and will be named monday, tuesday,..., friday

    thanks
    What is it doing? using "tradingDay" in the path? Crashing?


    Read up on this:



    That should give you Monday-Friday.

    Comment


      #3
      it's not reading or working the way i anticipated.

      i can't seem to include a drop down menu that would offer 5 options (mon-fri)

      my thinking is that selecting one of the noted options above would modify the current string text that locates the files on hard drive.

      attached is the indicator that i'm working on.

      line 33 is where i'm trying to create a way to select the 5 options inside the indicator window.

      thanks
      Attached Files

      Comment


        #4
        Hello duck_CA,

        Thank you for writing in.

        We do have a reference sample on our support forum showing how you can create a drop down menu with an enum: http://ninjatrader.com/support/forum...ead.php?t=3420

        I have created a sample that will print out the day selected as well as the path to the user data directory to a file named (Day).txt.

        Please, let us know if we may be of further assistance.
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          thank you for providing the indicator.

          getting an error with the following code

          Code:
          private string path = Cbi.Core.UserDataDir.ToString() + day.ToString() + ".txt";
          was hoping the code said " using path + find the day selected inside indicator window + find the text file that corresponds with day selected;

          the following code works so I believe the string path is correct
          Code:
          private string path = Cbi.Core.UserDataDir.ToString() + "Friday.txt";
          thanks

          Comment


            #6
            Originally posted by duck_CA View Post
            thank you for providing the indicator.

            getting an error with the following code

            Code:
            private string path = Cbi.Core.UserDataDir.ToString() + day.ToString() + ".txt";
            was hoping the code said " using path + find the day selected inside indicator window + find the text file that corresponds with day selected;

            the following code works so I believe the string path is correct
            Code:
            private string path = Cbi.Core.UserDataDir.ToString() + "Friday.txt";
            thanks
            Open the Output Window and put a Print in to see what it is doing.


            Code:
            private string path = Cbi.Core.UserDataDir.ToString() + day.ToString() + ".txt";
            
            ...
            OnBarUpdate
            ...
            
            Print ("path=" + path );

            Comment


              #7
              Open the Output Window and put a Print in to see what it is doing.

              it prints fine, it just doesn't locate and use the data inside the selected file.

              the idea is to have 5 text files located in folder each labeled mon-fri.

              the string will then use the selected enum to locate that particular file and use the data within to plot on charts.


              everything works like mentioned above when using the following code, but i was trying to find a way other than keeping the indicator file open and changing the text, then compiling

              Code:
              private string path = Cbi.Core.UserDataDir.ToString() + "Friday.txt";

              Comment


                #8
                Originally posted by duck_CA View Post
                thank you for providing the indicator.

                getting an error with the following code

                Code:
                private string path = Cbi.Core.UserDataDir.ToString() + day.ToString() + ".txt";
                was hoping the code said " using path + find the day selected inside indicator window + find the text file that corresponds with day selected;

                the following code works so I believe the string path is correct
                Code:
                private string path = Cbi.Core.UserDataDir.ToString() + "Friday.txt";
                thanks
                Where and how are you getting the value of "day"?

                Comment


                  #9
                  Originally posted by koganam View Post
                  Where and how are you getting the value of "day"?
                  I gave up at "It prints fine". I mean it can't print the same as the other and not work.

                  I'm not sure why the need for enum if you can just get the current day of week from a .net function. (Unless you want to run Monday on a Friday then you need a selector).

                  Comment


                    #10
                    Originally posted by koganam View Post
                    Where and how are you getting the value of "day"?
                    i'm not a programmer and really don't understand how to build code.

                    feel free to look at the attached indicator
                    Attached Files

                    Comment


                      #11
                      Hello duck_CA,

                      Thank you for your response.

                      Using the sample NinjaTrader_ZacharyG linked to you would set up a case and switch. For example:
                      Code:
                              protected override void Initialize()
                              {
                                  Overlay = true;
                      			CalculateOnBarClose	= true;
                      
                      			// We use a switch which allows NinjaTrader to only execute code pertaining to our case
                      			switch (day)
                      			{
                      				case Day.Monday:
                      					{
                      						path = Cbi.Core.UserDataDir.ToString() + "Monday.txt";
                      						break;
                      					}
                      				case Day.Tuesday:
                      					{
                      						path = Cbi.Core.UserDataDir.ToString() + "Tuesday.txt";
                      						break;
                      					}
                      			}
                      			// Continue for each day.
                      		}

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello duck_CA,

                        Thank you for your response.

                        Using the sample NinjaTrader_ZacharyG linked to you would set up a case and switch. For example:
                        Code:
                                protected override void Initialize()
                                {
                                    Overlay = true;
                        			CalculateOnBarClose	= true;
                        
                        			// We use a switch which allows NinjaTrader to only execute code pertaining to our case
                        			switch (day)
                        			{
                        				case Day.Monday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Monday.txt";
                        						break;
                        					}
                        				case Day.Tuesday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Tuesday.txt";
                        						break;
                        					}
                        			}
                        			// Continue for each day.
                        		}

                        getting several errors, here is the complete code
                        Code:
                         #region Variables
                        		private Days day = Day.Monday;
                        		private Days day = Day.Tuesday;
                        		private Days day = Day.Wednesday;
                        		private Days day = Day.Thursday;
                        		private Days day = Day.Friday;
                                #endregion
                        
                                /// <summary>
                                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                                /// </summary>
                                protected override void Initialize()
                                {
                                    Overlay = true;
                        			CalculateOnBarClose	= true;
                        
                        			// We use a switch which allows NinjaTrader to only execute code pertaining to our case
                        			switch (day)
                        			{
                        				case Day.Monday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Monday.txt";
                        						break;
                        					}
                        				case Day.Tuesday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Tuesday.txt";
                        						break;
                        					}
                        					case Day.Wednesday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Wednesday.txt";
                        						break;
                        					}
                        				    case Day.Thursday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Thursday.txt";
                        						break;
                        					}
                        					case Day.Friday:
                        					{
                        						path = Cbi.Core.UserDataDir.ToString() + "Friday.txt";
                        						break;
                        					}
                        			}
                        			// Continue for each day.
                        		}
                        
                                /// <summary>
                                /// Called on each bar update event (incoming tick)
                                /// </summary>
                                protected override void OnBarUpdate()
                                {
                        			Print("Day chosen is: " + day.ToString());
                        			Print(Cbi.Core.UserDataDir.ToString() + day.ToString() + ".txt");
                                }
                        
                                #region Properties
                                [Description("")]
                                [GridCategory("Parameters")]
                                public Days Day
                                {
                                    get { return day; }
                                    set { day = value; }
                                }
                                #endregion
                            }
                        }
                        
                        public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday };

                        Comment


                          #13
                          You would only need to define day once. So the following would not be correct:
                          Code:
                          		private Days day = Day.Monday;
                          		private Days day = Day.Tuesday;
                          		private Days day = Day.Wednesday;
                          		private Days day = Day.Thursday;
                          		private Days day = Day.Friday;
                          Instead go back to using one:
                          Code:
                          		private Days day = Day.Monday;

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            You would only need to define day once. So the following would not be correct:
                            Code:
                            		private Days day = Day.Monday;
                            		private Days day = Day.Tuesday;
                            		private Days day = Day.Wednesday;
                            		private Days day = Day.Thursday;
                            		private Days day = Day.Friday;
                            Instead go back to using one:
                            Code:
                            		private Days day = Day.Monday;
                            yes, i tried that first off and was getting errors.

                            Comment


                              #15
                              Hello duck_CA,

                              Thank you for your post.

                              Attached is the full script that works on my end.

                              Please let me know if you have any questions.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Irukandji, Today, 09:34 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by RubenCazorla, Today, 09:07 AM
                              1 response
                              5 views
                              0 likes
                              Last Post RubenCazorla  
                              Started by TraderBCL, Today, 04:38 AM
                              3 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              11 responses
                              1,423 views
                              0 likes
                              Last Post jculp
                              by jculp
                               
                              Working...
                              X