Announcement

Collapse
No announcement yet.

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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          62 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X