• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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:

    https://msdn.microsoft.com/en-us/library/5011f09h.aspx

    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 darkgreen, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post darkgreen  
          Started by GTBrooks, Today, 02:44 PM
          2 responses
          13 views
          0 likes
          Last Post GTBrooks  
          Started by GLFX005, Today, 12:22 PM
          4 responses
          41 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by AspenHiker, Today, 08:37 AM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by MartinT, Yesterday, 01:12 PM
          3 responses
          17 views
          0 likes
          Last Post MartinT
          by MartinT
           
          Working...
          X