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

Strategy compile error help.

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

    Strategy compile error help.

    Hi, I have had 2 attempts at producing 2 different strategies and have had trouble with the same compile errors in both.
    I see in example strategies what appears to me to be the same sort of coding but mine just gets errors. Please look at the attached screen shot to see what I mean.
    I mainly want to know what's wrong with the "if, else if" part.
    But also the supposed missing semi colons.
    Thanks.
    Let me know if you want the code.
    BTW, I have checked the NT help pages.
    Attached Files

    #2
    You have too many semicolons.

    You have:

    Code:
    if (xxxx);
      something1;
    else if (yyyy);
      something2;
    corrected:

    Code:
    if (xxxx)
      something1;
    else if (yyyy);
      something2;
    edit: umm apply that to all your IF's and ELSE's , etc.

    example here:

    The `if` and `switch` statements provide branching logic in C#. You use `if, `else` and `switch` to choose the path your program follows.

    Comment


      #3
      Tip - line up your if/else ifs/ elses so the indenting is right. It should look something like this:
      Code:
      protected override void OnBarUpdate()
      {
          if( this.IsFlat);  // this semi-colon is wrong right there
          {
              if( this.BPAboveEmaFast && EmaMediumAboveEmaSlow);  // don't put semi-colons after your if statements
              {
                  EnterLong();
              }
              else if( this.BPBelowEmaFast && EmaMediumBelowEmaSlow);  // <--- don't do dat
              {
                  EnterShort();
              }
              else
              {
                  if( this.IsLong();   // at least you're consistent!  :)
                      (EmaMediumAboveEmaSlow);  // I can't tell what you meant.  Is it pseudocode that you meant to implement later?
                  {
                      ExitLong();
                  }
                  else if( this.IsShort && EmaMediumBelowSlow)
                  {
                        ExitShort();
                  }
              }
          }
      }
      Try to write your code with the liberal use of braces and make sure the open braces are lined up with the closing braces.
      When you write everything nice and neatly, the errors will stand out and you'll recognize those kinds of errors instantly. I can clearly see there is nothing wrong with your if/else if statements when written this way. Take out those semi-colons on your if/else ifs and I bet those compile errors go away.

      Comment


        #4
        Partly fixed.

        Ok, thanks for your replies,I seem to have fixed the "if else" part, now if you can look at the new screen shot you will see the missing semi colon errors for the "bool" part. This has me stumped.
        How do I fix it?
        Do you need the code? Let me know if you do.
        Attached Files

        Comment


          #5
          Hello KennyK,

          Thanks for your post.

          Members sledge and traderpards have offered sound advice.

          In your latest screenshot, on lines 98 and 100, you are terminating an if statement with a ";" The semi-colon means that nothing else happens regardless of the evaluation of the conditions and that the action statements following the if statements will be executed on each OnBarUpdate regardless of the if statement condition. As member traderpards advised it is clearer and a cleaner read if you encompass the "action" part of the if/then statement with an open and close "{ }". For example:

          if (This is my condition to evaluate)
          {
          this is my action or actions to take if the conditions are true;
          You can have one or more actions here;
          }
          Note that the if() is not terminated by a ";" and note that each action is terminated by a ";" These are standard C# syntax and you may want to spend some time reviewing some on-line C# courses to aid in your understanding.

          The statements starting on line 104 and below are in the wrong area. They need to be outside of the OnBarUpdate(). The OnBarUpdate() begins with a "{" and you have to find the ending "}" and then move those statements outside of that area.

          There may well be other errors in your code/coding. In the support department at NinjaTrader we do not create, debug, or modify code for our clients. If you would like someone to create this for you, we can certainly provide a reference to 3rd party custom coders.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Barry Milan, Today, 10:35 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by WeyldFalcon, 12-10-2020, 06:48 PM
          14 responses
          1,428 views
          0 likes
          Last Post Handclap0241  
          Started by DJ888, Yesterday, 06:09 PM
          2 responses
          9 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          40 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Today, 08:51 AM
          2 responses
          16 views
          0 likes
          Last Post bill2023  
          Working...
          X