Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Syntax Problems

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

    Syntax Problems

    In the following code, I am getting "where expected" and "identifier expected" error messages for the line marked ***** and "class member declaration" error for the line marked #####. How do I correct?

    protected override void Initialize()
    *****
    Add(linReg (Close, 34) );
    #####
    SetTrailStop("TS.pp", CalculationMode.Ticks, sacrifice(0) ) ;
    CalculateOnBarClose = false;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1

    #2
    linReg should be capitalized as LinReg. See if that helps.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Transmittal for code submitted separately.

      Separately I am submitting my first strategy (translated from Easy Language to Ninja Script (C#). I have not yet compiled the code. The Forum does not accept my code because there are too many characters. I will try to send the code as an attachment to an email and hope it will be able to be forwarded to the Forum or edited separately.

      Although the functionality seems correct, I am very unsure about the following issues:

      1-There is no MAIN() method. Does every application have to have a MAIN()?

      2-Is my use of Public and Private correct?

      3-Are the various sections categorized correctly? For example,
      Declarations, Initializations, Procedures?

      4-Are the various sections in the proper order?

      5-There are two variables (LinReg and LinRegDelta).
      In Easy Language and in most languages, Variables need to be defined after they are declared. In my Ninja Script they are not explicitly defined. Is this OK?

      I hope I am not asking too much. I have been studying C# and hope to be pretty independent not too far down the road.

      In the meantime, I’m very appreciative for all the help Ninja is giving me. The word “Thanks” is inadequate to express my gratitude.

      I have been trading for over 40 years, in the late 60’s and 70’s as a commodity and stock broker with top firms and ever since as an independent trader.

      My first attempt at an automated system has been created as a programming exercise. I have created more sophisticated systems in other languages and expect to use them in C# as soon as I have learned to automate this one.

      P.S. After running, if I want to change the value of an Input, do I have to access the code or is there some place where the Inputs are available for modification?

      Comment


        #4
        1. You do not need to use MAIN() in NinjaScript.
        2. I do not know because there is no code here that uses either.
        3. Not sure what you mean, but please see the tutorials in the Help Guide that go through the breakdown of where things should go when coding.


        Review the self-programming pages.
        4. Not sure what you mean. Whatever is generated by the Wizard template is always in order.
        5. Not sure what you mean again. LinReg is not a variable. LinReg is the method for the indicator named LinReg. I do not know what LinRegDelta is, but it is most likely another custom indicator you have installed.

        You can create user definable parameters from the Strategy Wizard. There is a page called "User Defined Variables" that allows you to create these. In programming you can see any of the pre-packaged indicators to see how it is done. Open up the SMA indicator and scroll down and expand the Variables and the Properties section of the code. Those lines are the ones that create the user definable variable that you can change on the fly when you run your strategy/indicator.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the quick reply. I appreciate the great service!

          Re 2-(Private vs. Public) : The Class name is Public. The Inputs (Variables) are Private. Although I believe I understand that Private is accessible only within the Class, I really don't know when to make something Private or Public.

          Re 5-I used LinReg in Easy Language to return the value of a linear regression. This is what I am trying to do in this Strategy. Will it work as I have written it in the editor? (I have unlocked the code and am now in the editor not in the Wizard.)

          In Easy Language, I used LinReg as a variable. In my Ninja code, I want to accomplish the same thing. That is use the change in LinReg to trigger bye or sell.
          Will this work as I have written it in the code I sent you?

          Although you call LinReg a method, the formula behind the method has to exist somewhere. Is that true in Ninja, or do I have to provide the formula?

          Comment


            #6
            skat100,

            1. Just as a rule of thumb you would want everything as private. The only times you want to make something public is if you want to be able to access a variable outside of the indicator. Naturally, everything that is set to public by default from the Wizard you would want to leave those as public.

            2. To get the value of the linear regression you would want to be inside the OnBarUpdate() calling the indicator.
            Code:
            double value = LinReg(Close, 34)[0]; 
            Print("The current LinReg value is " + value.ToString());
            Your Add(LinReg(Close, 34)); line just adds the indicator onto the chart for you when you run your strategy.

            The formula exists in the LinReg indicator. You can open and check them out by going Tools->Edit NinjaScript->Indicator->LinReg
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Re 5-Although you refer to LinRegDelta as an indicator, I want to use it as a variable in this manner: LinRegDelta = (AbsValue(LinReg - LinReg[SlopeLookBack]) * 10000), where SlopeLookBack is an Input (Variable?)

              Is AbsValue the correct syntax for Absolute Value or is this a Math. item?

              Comment


                #8
                skat100,

                I do not know what LinRegDelta is. I assumed it was an indicator you have. If it is not you can use it however you want.

                In the Variables region of your code declare out the variable.
                Code:
                private double LinRegDelta = 0;
                In the OnBarUpdate() method set the value you would like:
                Code:
                LinRegDelta = Math.Abs((LinReg(34)[0] - LinReg(34)[slopeLookBack]) * 10000);
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Compile Errors

                  I have just compiled my strategy. Here are three lines with line numbers and errors:

                  60 protected override void OnBarUpdate()
                  61
                  62 LinRegDelta = Math.Abs((LinReg(34)[0] - LinReg(34)[slopeLookBack]) * 10000

                  There are two errors for line 61:

                  Expected class, delegate, enum, interface, or struct
                  Identifier expected.

                  Would you please explain and tell me how to correct these errors?
                  The same two errors show up on many other lines.

                  Comment


                    #10
                    skat100,

                    Your line 61 should have a bracket. {

                    Make sure you have all opening and closing brackets intact.

                    Code:
                    protected override void OnBarUpdate()
                    {
                         //code
                    }
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Line 65 compile error:
                      A namespace does not directly contain members such as fields or methods

                      64//Condition set 0
                      65 if (Position.Unrealized >= TrailStopTrigger
                      66 {
                      67 SetTrailStop("TS.pp", CalculationMode.Ticks, 15 ) ;
                      68 }


                      Lines 51 60, 62, 72, 79, 86, 93, 124, 132, 140, 148 compile errors:
                      Expected class, delegate, enum, interface or struct

                      Lines 72, 79, 86, 91, 99, 107 compile errors:
                      Identifier expected

                      How do I correct these three errors?:
                      1-A namespace does not directly contain members such as fields or methods
                      2-Expected class, delegate, enum, interface or struct
                      3-Identifier expected

                      Thanks for all your help!

                      Comment


                        #12
                        Compile Errors

                        Line 65 compile error:
                        A namespace does not directly contain members such as fields or methods

                        64//Condition set 0
                        65 if (Position.Unrealized >= TrailStopTrigger
                        66 {
                        67 SetTrailStop("TS.pp", CalculationMode.Ticks, 15 ) ;
                        68 }


                        Lines 51 60, 62, 72, 79, 86, 93, 124, 132, 140, 148 compile errors:
                        Expected class, delegate, enum, interface or struct

                        Lines 72, 79, 86, 91, 99, 107 compile errors:
                        Identifier expected

                        How do I correct these three errors?:
                        1-A namespace does not directly contain members such as fields or methods
                        2-Expected class, delegate, enum, interface or struct
                        3-Identifier expected

                        Thanks for all your help!

                        Comment


                          #13
                          skat100,

                          It is likely that the structure of your code has been completely compromised. You will need to post complete code for us to help you. Please add your file as an attachment here. You can find your file in My Documents\NinjaTrader 6.5\bin\Custom\Strategy
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            I have scrapped the strategy which I was told was corrupted. I have a new strategy which I programmed in Easy Language (because I am familiar with it) and now am trying to create the code in the Ninja Wizard.

                            In the Condition Builder I am having difficulty in translating the following EL code:

                            If MarketPosition = 0 then begin
                            If LinReg crosses over (Close +bufferLong) then
                            Buy("B.LRC") 1 * ctr contracts next bar at market ;

                            The problem I have is that I can't figure out how to fill in the parameter sections. If you would do this one entry for me, I can go on with all the other conditions. Thanks for your help.

                            Stan Katz
                            [email protected]
                            860-434-9609

                            Comment


                              #15
                              Stan,

                              See this article for Market Position: http://www.ninjatrader-support.com/H...mparisons.html

                              See this one for offsetting your Close price: http://www.ninjatrader-support.com/H...ItemValue.html
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              595 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              554 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X