• 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

code help

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

    code help

    I have the following code within OnBarUpdate(). Even though the condition is true (I see "I'm here") and there is a "return" statement the code executes beyond this if statement. Why doesn't the "return" escape out of OnBarUpdate() or not go any further, why does the code execute further? Thanks.

    if ( (ToTime(Time[0]) >= ToTime(2, 30, 00)) || (ToTime(Time[0]) <= ToTime(8, 30, 00)))
    {
    Print("Im Here");

    if (Position.MarketPosition == MarketPosition.Long)
    ExitLong("", "");
    else if (Position.MarketPosition == MarketPosition.Short)
    ExitShort("", "");
    return;
    }

    #2
    Originally posted by EthanHunt View Post
    why does the code execute further?
    Short answer:
    No clue, you've given too little information.

    Long Answer:
    What is the code doing when it executes further?

    This is also a good question. You've not told us.

    Show us more (preferably, all) of the OnBarUpdate() code, that way we can see "what" it's doing, and perhaps then someone can tell you "why" it's doing it.

    Comment


      #3
      Originally posted by EthanHunt View Post

      if ( (ToTime(Time[0]) >= ToTime(2, 30, 00)) || (ToTime(Time[0]) <= ToTime(8, 30, 00)))
      This is always true.

      Nothing should be getting past your return;

      Comment


        #4
        Originally posted by EthanHunt View Post
        I have the following code within OnBarUpdate(). Even though the condition is true (I see "I'm here") and there is a "return" statement the code executes beyond this if statement. Why doesn't the "return" escape out of OnBarUpdate() or not go any further, why does the code execute further? Thanks.

        if ( (ToTime(Time[0]) >= ToTime(2, 30, 00)) || (ToTime(Time[0]) <= ToTime(8, 30, 00)))
        {
        Print("Im Here");

        if (Position.MarketPosition == MarketPosition.Long)
        ExitLong("", "");
        else if (Position.MarketPosition == MarketPosition.Short)
        ExitShort("", "");
        return;
        }
        What is the error in your log?

        Comment


          #5
          What does it matter what the code is when it executes further? The point is it does execute further. That is my question. Since there's a "return" in the condition when true the code should not execute any further. For your information the code that executes further down is just strategy buy/sells.


          Originally posted by bltdavid View Post
          Short answer:
          No clue, you've given too little information.

          Long Answer:
          What is the code doing when it executes further?

          This is also a good question. You've not told us.

          Show us more (preferably, all) of the OnBarUpdate() code, that way we can see "what" it's doing, and perhaps then someone can tell you "why" it's doing it.

          Comment


            #6
            There is no error in the log.


            Originally posted by koganam View Post
            What is the error in your log?

            Comment


              #7
              Originally posted by EthanHunt View Post
              The point is it does execute further.
              No, it doesn't.

              After the return is executed, absolutely nothing else in that function will execute.

              Sledge's post is absolutely correct.

              Originally posted by EthanHunt View Post
              That is my question. Since there's a "return" in the condition when true the code should not execute any further.
              There is no question posed that is worth answering beyond Sledge's reply.

              With what little code you're providing, I would have to say the problem is more the programmer's understanding of the code, and not the code itself.

              Provide more code and we'll help you better understand it.

              Originally posted by EthanHunt View Post
              For your information the code that executes further down is just strategy buy/sells.
              It seems like you're asking us to make blind guesses at some mistake you're making.

              Provide more code and you'd get better help. It's that simple.

              Otherwise, start using Print everywhere and figure it out.

              Good luck.

              Comment


                #8
                You misunderstand the original question (go back and look). Code is executing after the return statement. So your comment "After the return is executed, absolutely nothing else in that function will execute." is not true in this case. Reason for the whole post...



                Originally posted by bltdavid View Post
                No, it doesn't.

                After the return is executed, absolutely nothing else in that function will execute.

                Sledge's post is absolutely correct.



                There is no question posed that is worth answering beyond Sledge's reply.

                With what little code you're providing, I would have to say the problem is more the programmer's understanding of the code, and not the code itself.

                Provide more code and we'll help you better understand it.



                It seems like you're asking us to make blind guesses at some mistake you're making.

                Provide more code and you'd get better help. It's that simple.

                Otherwise, start using Print everywhere and figure it out.

                Good luck.

                Comment


                  #9
                  Originally posted by EthanHunt View Post
                  There is no error in the log.
                  In that case, given that your filter is always true, you should never be able to get past that block (which is what Sledge said).

                  That leaves only one possible conclusion so far. What you have posted is not what you actually have coded. I suspect that there is a stray semi-colon after your filter, turning it into a null expression.

                  Comment


                    #10
                    Originally posted by EthanHunt View Post
                    Code is executing after the return statement.
                    What code? You've not shown us any additional code.

                    If you're trying to say that something is broken with C# or NinjaTrader, you'll need to be a lot more specific.

                    Otherwise, I suggest you look at your question from our point of view:

                    You're claiming C# return statement is broken.
                    You're asking why code still executes after a return.
                    (This elicits a basic WTF are you talking about kind of response.)
                    We can't see your code.
                    We don't know your logic.
                    You're asking us to guess why something is broken that cannot be broken.

                    From what little you've provided, your claim is blatantly preposterous and shows a basic lack of understanding of programming principles.

                    Everyone knows that the code following a return is not executed. If you think it is, then more is happening in your code that you've failed to reveal.

                    Or, perhaps you have a fundamental lack of understanding about something else. Without more code, it is difficult to comment on the totality of your misunderstanding.

                    If you insist on debating the purpose of the return statement, then solving the root cause of your problem is probably hopeless.

                    First, calm down. You're asking for help, but we haven't a clue what you're really doing.

                    Let's assume the return is working. What else could it be?

                    I still recommend you use more Print statements to figure out what is happening.

                    Have you done that?
                    Last edited by bltdavid; 10-24-2016, 10:58 AM.

                    Comment


                      #11
                      Originally posted by bltdavid View Post
                      Let's assume the return is working. What else could it be?
                      Koganam's post is a great possibility.

                      Comment


                        #12
                        Hello EthanHunt, and thank you for your question.

                        So we can better understand what is happening with your code, can you add the emphasized line below? The other modifications are optional and are being provided for information so the differences between the test script on my end and your script are clear. The bolded line must however appear after your closing curly brace.

                        If you can add this line and send the resulting log file to platformsupport[at]ninjatrader[dot]com, referencing ninjatrader_jessicap and 1592190 in the subject line of your e-mail, we will be able to have a more clear idea why this is occurring.

                        Code:
                        // JDP Mon Oct 24 09:44:10 MDT 2016
                        // replacing this by equivalent code to minimize solution space
                        //if ( (ToTime(Time[0]) >= ToTime(2, 30, 00)) || (ToTime(Time[0]) <= ToTime(8, 30, 00)))
                        if (true)
                        {
                            Print("Im Here");
                            
                            /* JDP Mon Oct 24 09:49:40 MDT 2016
                            minimizing solution space by removing this code
                            if (Position.MarketPosition == MarketPosition.Long)
                                ExitLong();
                             else if (Position.MarketPosition == MarketPosition.Short)
                                 ExitShort();
                            */
                        
                            return;
                        }
                        Log("Reached unexecutable code at " + DateTime.Now.ToString("HH:mm:ss.ffff"), LogLevel.Information);
                        After compiling that line into your code and running your code, the appropriate log file will be in your (My) Documents\NinjaTrader 7\logs or (My) Documents\NinjaTrader 8\logs folder, depending on whether you are using NT7 or 8. It will contain today's date and will be the highest numbered one to do so.
                        Last edited by NinjaTrader_JessicaP; 10-24-2016, 09:55 AM.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello EthanHunt,

                          I would like to verify, were you able to resolve your query on your own? Did my code suggestion (the Log line) work as expected for you?

                          If we can help in any way please do not hesitate to reach out
                          Jessica P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by chrismcdermut, Today, 01:46 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post chrismcdermut  
                          Started by dpolyakov, Today, 01:13 PM
                          3 responses
                          14 views
                          0 likes
                          Last Post dpolyakov  
                          Started by tjendra, Today, 12:15 PM
                          3 responses
                          9 views
                          0 likes
                          Last Post tjendra
                          by tjendra
                           
                          Started by lunardiplomacy, Today, 11:46 AM
                          4 responses
                          16 views
                          0 likes
                          Last Post lunardiplomacy  
                          Started by trdninstyle, Today, 10:38 AM
                          2 responses
                          17 views
                          0 likes
                          Last Post trdninstyle  
                          Working...
                          X