Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Offset doesn't work

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

    Offset doesn't work

    I simply want to trigger a short when price moves X ticks on close past an EMA.

    It won't work...it just enters immediately when the bar closes. This is for USD/JPY on forex. I've been sitting here banging my head on the table for hours. I'm completely new to NinjaTrader so I'm sure it's something simple.

    // Condition set 1
    if (Open[0] + 8 * TickSize > EMA(23)[0])
    {
    EnterShort(Lots, "");
    }

    #2
    ... price moves X ticks on close past an EMA.
    Then you should be referring to Close[0], which is the close of the bar that just closed, not Open[0] which is the Open of the bar that just closed.

    That is, unless you are using CalculateOnBarClose = false; in your Initialize() method, in which case you can use either Open[0] or Close[1], which on most bar types are equivalent, most of the time.

    Comment


      #3
      trend747,

      Thank you for your post.

      koganam would be correct here. If you would like to enter after X ticks from the open of the current bar, please make sure your strategy is using CalculateOnBarClose = false;

      You can either set this property in the Initialize() method from your code, or when adding the strategy you will see an option to manually set the CalulateOnBarClose to false.

      Please review our Help Guide article on the COBC property for more information:



      I would also suggest taking a look at our strategy reference sample for 'Separating logic to either calculate once on bar close or on every tick':

      MatthewNinjaTrader Product Management

      Comment


        #4
        Originally posted by koganam View Post
        Then you should be referring to Close[0], which is the close of the bar that just closed, not Open[0] which is the Open of the bar that just closed.

        That is, unless you are using CalculateOnBarClose = false; in your Initialize() method, in which case you can use either Open[0] or Close[1], which on most bar types are equivalent, most of the time.
        I tried that as well. It still immediately opens a trade.

        Comment


          #5
          It also immediately tries to enter a trade as soon as I start the replay... so you then get an error, "There is no market data ..." So something is clearly wrong.

          Comment


            #6
            trend747,

            Can you clarify the calculate on bar close value you are using? What happens when you use COBC to true? Does the trade still execute when enabling? Or do you get the results you are looking for?
            MatthewNinjaTrader Product Management

            Comment


              #7
              Originally posted by NinjaTrader_Matthew View Post
              trend747,

              Can you clarify the calculate on bar close value you are using? What happens when you use COBC to true? Does the trade still execute when enabling? Or do you get the results you are looking for?
              COBC is true. Here's the code:

              // Condition set 1
              if (Close[0] + 0.1 > EMA(23)[0])
              {
              EnterShort(Lots, "");
              }

              To me, this says, "If the close of the bar is more than 10 pips greater than the EMA, then enter short"

              It doesn't do that...

              Comment


                #8
                Hello,

                I would suggest adding some Print() functions to help determine the value that logic is actually using vs the logic you intend to use.

                More information on debugging your NinjaScript code from the following link:

                MatthewNinjaTrader Product Management

                Comment


                  #9
                  I just tried:

                  // Condition set 1
                  if (Close[0] > EMA(23)[0]) + 0.8
                  {
                  EnterShort(Lots, "");
                  }

                  ...and it seems to be working correctly.

                  Comment


                    #10
                    Originally posted by trend747 View Post
                    COBC is true. Here's the code:

                    // Condition set 1
                    if (Close[0] + 0.1 > EMA(23)[0])
                    {
                    EnterShort(Lots, "");
                    }

                    To me, this says, "If the close of the bar is more than 10 pips greater than the EMA, then enter short"

                    It doesn't do that...
                    Actually that says: "If the close of the bar is smaller than the EMA by less than 10 pips, then enter short." Not quite the same thing.

                    Comment


                      #11
                      I think I got it figured out. Thanks everyone for the great support.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      670 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      379 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      111 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      575 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      582 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X