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

Defective code from Strategy Builder

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

    Defective code from Strategy Builder

    I wrote a sample strategy to make sure I understood how to use the builder. Maybe not. Attempting to compile the code threw a bunch of error messages. The problem section below was copied from Strategy Builder, not retyped. I appreciate your help.

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (EMA(9)[1] < EMA(18)[1]
    && Close[1] > Open[1]
    && Low[0] < Low[1])
    {
    EnterShort(DefaultQuantity, "Short1");
    }
    }

    Line 49 is the sixth line down, the second beginning with double ampersands. Here are the error messages:
    NinjaScript File Error Code Line Column
    Strategy\TutorialSMA.cs Invalid expression term '&&' CS1525 - click for info 49 53
    Strategy\TutorialSMA.cs ; expected CS1002 - click for info 49 56
    Strategy\TutorialSMA.cs ; expected CS1002 - click for info 49 79
    Strategy\TutorialSMA.cs Invalid expression term ')' CS1525 - click for info 49 79
    Strategy\TutorialSMA.cs ; expected CS1002 - click for info 49 81
    Strategy\TutorialSMA.cs Invalid expression term ')' CS1525 - click for info 49 81
    Strategy\TutorialSMA.cs ; expected CS1002 - click for info 49 82

    #2
    Hello PBreen,

    Is this strategy still being opened with the Builder or has the strategy been unlocked and opened in the NinjaScript Editor?

    What code are on lines 48 - 49?

    May we have a screenshot so we may see the line numbers?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It's in the NinjaScript Editor now.

      Whenever I try to attach a screenshot,

      Comment


        #4
        Hello PBreen,

        I am seeing the syntax is not coded properly on line 49.

        There are 3 opening parenthesis and 5 closing parenthesis.

        Each closing parenthesis must have an opening parenthesis.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Dear God. What I get for doing no coding since qbasic. Sorry to bother you with something so stupid. Then, most of my questions are. Thanks.

          Comment


            #6
            I retract that last. It's what I get for being incompetent with Windows 10. Sincere apologies, but that turns out to have been the wrong screenshot. Here's the one I should have sent. Can't figure out why it is complaining about the ampersands on line 49 when it has no problem with those on 48, and those column numbers baffle me completely. Thanks for your help.

            Comment


              #7
              Hello PBreen,

              The errors are in a different file.

              The script open in the screenshot is UniRenkoEntries.

              The error is in the script TutorialSMA as shown in the NinjaScript File column in the screenshot.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks, but as my previous note said TutorialSMA was the wrong screenshot. My bad. It's UniRenkoEntries I have been working with, and that's the file throwing error messages I don't understand.

                Comment


                  #9
                  Hello PBreen,

                  Originally posted by PBreen View Post
                  Thanks, but as my previous note said TutorialSMA was the wrong screenshot. My bad. It's UniRenkoEntries I have been working with, and that's the file throwing error messages I don't understand.
                  This incorrect.

                  The NinjaScript File column shows the error is in the script TutorialSMA. The error is not in the UniRenkoEntries script.

                  The TutorialSMA script will need to be corrected for any script to compile.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Please let me make sure I understand. I am working with UniRenkoEntries, but the... Oh. This explains why I did not understand what was going wrong. Unobservant of me. But why on Earth does the compiler care about a file I'm not working with?

                    Never mind. Enough to know that it does.

                    Thanks for your help.

                    Comment


                      #11
                      Hello PBreen,

                      In C# if there are any errors in any files no scripts will compile.

                      I recommend the NinjaScript Editor 401 course which talks about error messages.
                      Below is a public link.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by PBreen View Post
                        But why on Earth does the compiler care about a file I'm not working with?
                        Every time you invoke the NinjaScript compiler, the compiler automatically compiles every NinjaScript file
                        and reports any error in any file that fails the compilation.

                        It does not matter which file you are editing in the NinjaScript editor, when you invoke the compiler, like I said,
                        all NinjaScript files are compiled. This includes indicators, strategies, bartypes, market analyzer scripts, etc.
                        This will even include all the standard "factory supplied" NinjaScript files that start with the '@' character.
                        Basically, every NinjaScript file anywhere in "NinjaTrader 7/bin/Custom/<subfolder>" is recompiled.

                        It does this because NinjaTrader designed it that way. On purpose. Why? To bring to your attention errors in
                        other files you may not be aware of -- uh, such as the exact situation you're in now -- but really because it wants
                        to create a single valid assembly, called NinjaTrader.Custom.dll, and that assembly can only be created to contain
                        all your NinjaScript files if all NinjaScript files successfully compile.

                        Comment


                          #13
                          Many thanks for explaining the origin of this and other issues. Unfortunately, understanding does not improve my satisfaction with the inconveniences Strategy Builder--deliberately, I now recognize--inflicts upon its users. If code doesn't work, it's because I deliberately moved on before completing it. Fortunately, fixing the irrelevant strategy to my satisfaction required only commenting out everything but the #endregion. I will use this technique from now on.

                          I may be--incontestably am--a lousy coder, but as of last January I had been coping with people's software designs for 39 years. WADR to those who created a generally excellent piece of trading software despite being, so far as I can tell, not traders themselves, I have lost track of how many design decisions involved with NinjaScript strike me as being unmitigatedly hammer-headed. If I ever switch to, say, TradeStation, this obstructive, strait-jacketed facility will be the cause.

                          Comment


                            #14
                            If I may elaborate even more, the situation is not as cumbersome as you imply.

                            You should only import .zip files to install additional NinjaScript (which is the way NinjaTrader recommends).
                            This is the safe way to augment NinjaTrader -- Why? When importing, NinjaTrader attempts to compile
                            the files inside the .zip file (if any exist) and fails the import process if any part of compilation fails. But
                            this failure is a good thing. A failed import is safe and does not affect further compiling. How? Because
                            the compiler failure means the import failed -- and thus the installation failed, too, meaning (and here is
                            critical part) extracting the bad NinjaScript files to bin/Custom/Indicator did not execute. So, you're safe.

                            If you manually copy .cs files into your bin/Custom/Indicator folder, or you manually make any changes
                            to any of those files, and if the compiler fails, you will have to manually remove the files you copied there,
                            or manually fix the changes that you made.

                            See the difference? If you had dealt with .zip files only, you would never have the compiling problem
                            frustrations you're experiencing. This is by design.

                            Remember, dealing with .cs files is much closer to the metal, fewer protections, lots of power, but very
                            much a wild west of lawlessness, full of gotchas, such as compiler errors. Soooo, If you choose to deal with
                            these .cs files directly -- then you have chosen the path of the programmer, and you really do need to know
                            what you're doing.

                            If you don't know how to patrol your system and fix the bad .cs files, you will be impacted by the bad
                            apples in the NinjaScript universe much more severely.

                            Moral of story:
                            1. As much as possible, import with NinjaScript .zip files only.
                            2. As much as possible, avoid directly installing & editing & compiling .cs files.

                            The #2 path is there for everyone, but you have to respect the tremendous power it affords you,
                            otherwise, you may experience tremendous frustration.



                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by TraderBCL, Today, 04:38 AM
                            2 responses
                            8 views
                            0 likes
                            Last Post TraderBCL  
                            Started by martin70, 03-24-2023, 04:58 AM
                            14 responses
                            105 views
                            0 likes
                            Last Post martin70  
                            Started by Radano, 06-10-2021, 01:40 AM
                            19 responses
                            606 views
                            0 likes
                            Last Post Radano
                            by Radano
                             
                            Started by KenneGaray, Today, 03:48 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post KenneGaray  
                            Started by thanajo, 05-04-2021, 02:11 AM
                            4 responses
                            471 views
                            0 likes
                            Last Post tradingnasdaqprueba  
                            Working...
                            X