Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Syntax Problems

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Thanks for your help. I have left the Wizard and compiled and have errors but can't correct them because the code won't let me change anything. How do I correct errors?

    Comment


      #17
      skat100,
      Did you click "View Code" or "Unlock Code"? To edit the code I believe you need to click on "Unlock Code". Remember that once you unlock the code on a strategy you can NOT reopen that strategy in the wizard. Other Strategies should not be effected by using the "Unlock Code" (you can still use the Wizard on Strategies that have not been unlocked).

      Comment


        #18
        You can also just go to Edit NinjaScript and open any other indicator or strategy. Press F5 to compile and it will show you any errors across all files. You can fix it from there then.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          This produces Error 0021:
          && Position.GetProfitLoss(Close[
          0], PerformanceUnit.Currency) < BSEp)

          Apparently a Method parameter is missing. How do I correct?

          Comment


            #20
            You will need to provide the complete line as well as the complete error message.
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              I sent the complete line and the error message. Did you receive it?

              Comment


                #22
                Stan,

                My colleague already responded to you via your email.
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  Thanks for the reply. I don't understand what I am to do to correct.

                  Following are code lines in question. The two "Close" words which I have printed in red contained red underlines to indicate where the error is.

                  The actual error message for each of the two lines containing the red Close is "Cannot apply indexing with [] to an expression of type 'double'. (I typed Close as Double because I didn't find a type called currency.)

                  I don't know what "indexing" means and I don't know how to correct the error in each of the two places.

                  I'd appreciate your help. Thank you.
                  // Condition set 4
                  if (Position.MarketPosition == MarketPosition.Long
                  && BarsSinceEntry() >= BSE
                  && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
                  {
                  ExitLong("BSE.S", "");
                  }

                  // Condition set 5
                  if (Position.MarketPosition == MarketPosition.Short
                  && CrossAbove(LinReg(Length), BuffetLong, 1))
                  {
                  ExitShort("CS.LRC", "");
                  }

                  // Condition set 6
                  if (Position.MarketPosition == MarketPosition.Short
                  && BarsSinceEntry() >= BSE
                  && Position.GetProfitLoss(Close[0],PerformanceUnit.Currency) < BSEp)
                  {
                  ExitShort("BSE.SS", "");
                  }

                  Comment


                    #24
                    skat100,

                    I am out of ideas because the code you have should work. Please ensure you are on NT6.5.1000.7. I suggest you try from scratch with a very basic case. Something else in that strategy may have become corrupt that is interfering with the code.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #25
                      Thanks, Josh. Does the word indexing refer to the [] brackets after the word Close? I assume it means defining the number of bars back for Close. Is this correct? If so, is it proper to assign the Double type to Close? If I change the type to Currency or to int, perhaps that will solve the error problem. Should I try that?

                      This strategy produces a huge number of trades which I will have to whittle down but I don't think that is causing the error message.

                      Comment


                        #26
                        More questions

                        When I compile, I get this message:

                        "Enabling “Debug Mode” should only be used by advanced programmers that intend to debug their Ninja Script in Visual Studio.

                        "Compiling Ninja Script objects with this mode enabled will result in runtime performance penalty.

                        "Please make sure you disable this mode once you are complete with your debugging and recompile your Ninja Script objects."

                        How do I make sure I am not in Debug Mode?

                        Comment


                          #27
                          Hi skat100,

                          Yes indexing refers to the [ ] brackets, you may try changing the variables type.

                          The exit the debug mode, simply right click in your code and uncheck 'Debug Mode'.

                          Comment


                            #28
                            Syntax Errors

                            Following is a portion of my code. In the bold red lines in Condition Set 4 and in Condition Set 6, the compiler has indicated Error CS0021, marking the word Close in red.


                            // Condition set 4
                            if (Position.MarketPosition == MarketPosition.Long
                            && BarsSinceEntry() >= BSE
                            && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
                            {
                            ExitLong("BSE.S", "");
                            }


                            // Condition set 6
                            if (Position.MarketPosition == MarketPosition.Short
                            && BarsSinceEntry() >= BSE
                            && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
                            {
                            ExitShort("BSE.SS", "");
                            }


                            The text explaining Error CS0021 is as follows:
                            “This is a common error when calling indicator methods. It occurs when an indicator is called without its required parameter arguments before accessing an indexed value.
                            “To fix this error you will need to first pass to the indicator method all the necessary parameter arguments. You can do this with “()” after the indicator name. Please note that you will still need to pass an empty parameter argument list even if your indicator requires no arguments.”

                            Erroneous Sample Code – SMA is an indicator and requires parameter arguments:
                            Double value = SMA[0] ;

                            Resolution Sample Code – SMA properly called:
                            Double value = SMA(14)[0]


                            I don’t see how to insert () after the indicator name. I can’t correct the code directly. Any attempt to change the code jumps me back to the graphic where I can only access the choices presented that do not include the ability to insert ().

                            I’d appreciate it if you would tell me how to make this correction.
                            Thank you for your help.

                            Comment


                              #29
                              skat100,

                              Just upload your complete file. There is likely something gone awry elsewhere. We cannot help you from these snippets alone.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                Complete code attached

                                Complete code attached as zip file.

                                I've had trouble sending this because message was considered too long. I'd appreciate receivng confirmation of receipt.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                629 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                362 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                564 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                568 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X