Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitShort

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

    ExitShort

    I am trying to set a calculated target. No matter what I have tried it just exits on the next bar.

    I went and put in a statice number to see if the calculation was causing the problem but I got the same results. I made sure the number was much higher than the low would ever be so there shouldn't be any exit in this case

    This is under the on bar update.

    I am entering a break of the first hour low. This is working fine. But it immediately exits the next bar.

    Any help would be appreciated.


    if (CrossBelow(Low, BzvOpeningRange4("0430", "0530", "1315").RangeLowSeries, 1)
    && ToTime(Time[
    0]) > ToTime(5, 30, 0)
    && ToTime(Time[
    0]) < ToTime(7, 0, 0))
    {
    EnterShort(DefaultQuantity,
    "BreakOutShort");
    }
    // Condition set 2
    if (Low[0] > 1500);
    {
    ExitShort(
    "Target 61", "");
    }

    #2
    delta20, I would suggest to include a condition as well to submit that Exit only if you're not flat or for example if a # of BarsSinceEntry was surpassed -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by delta20 View Post
      I am trying to set a calculated target. No matter what I have tried it just exits on the next bar.

      I went and put in a statice number to see if the calculation was causing the problem but I got the same results. I made sure the number was much higher than the low would ever be so there shouldn't be any exit in this case

      This is under the on bar update.

      I am entering a break of the first hour low. This is working fine. But it immediately exits the next bar.

      Any help would be appreciated.


      if (CrossBelow(Low, BzvOpeningRange4("0430", "0530", "1315").RangeLowSeries, 1)
      && ToTime(Time[
      0]) > ToTime(5, 30, 0)
      && ToTime(Time[
      0]) < ToTime(7, 0, 0))
      {
      EnterShort(DefaultQuantity,
      "BreakOutShort");
      }
      // Condition set 2
      if (Low[0] > 1500);
      {
      ExitShort(
      "Target 61", "");
      }
      That is because you have coded your exit condition as a null statement, so the ExitShort() will be triggered on every bar.

      Remove the semi-colon, that I have highlighted in red, so that the block following the if statement becomes the execution block for the statement, instead of the null statement that is currently coded.

      Do not feel bad. I still make that mistake even now, once in a while, and it is the devil to debug. The only reason that I saw it so quickly is because now, whenever I see a problem where a statement is ignoring an if condition, that is the first thing that I look for.

      It is so easy to overlook it, even when reading it back. One trick I use is to read from bottom to top, so that the code makes no sense in my mind. That way I can read what I wrote, instead of what I think I wrote, and keep missing the error. Just my $0.02.

      Comment


        #4
        Thanks alot for that I will give it a try.

        I am new to ninja with very limited progamming skills so I have been piecing code together. Fortunately there is alot of code available to learn from.

        Can you explain what a null statement is and or what it would be used for?

        Thanks again

        Stefan

        Comment


          #5
          Originally posted by delta20 View Post
          Thanks alot for that I will give it a try.

          I am new to ninja with very limited progamming skills so I have been piecing code together. Fortunately there is alot of code available to learn from.

          Can you explain what a null statement is and or what it would be used for?

          Thanks again

          Stefan
          A null statement is a statement that is null. i.e., it does nothing.

          The null statement is useless by itself, but it can have a syntactic use in a wider context.

          e.g., within the context of a loop:
          Code:
          while (ReadChar() != '\n')
           ;
          The above code continues calling the ReadChar() function until it returns a \n (newline) character.

          Comment


            #6
            Next 1st day non stop entries

            Your advice fixed my first problem!

            Now if I set the backtest to use regular trading hours (trading /es) the first day of the strategy backtest just has entry - exit on next candle etc.. until the end of my set time period for entry

            If I set it to instrument settings which has extended hours the returns are correct since I have the entry time only between 10.30am and Noon with exit on close of the session so I believe I am getting proper returns I just have have alot of extra data on the chart.

            I thought this might have to do with the look back period but haven't been able to figure it out.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            7 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            6 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X