Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

is it meaningful to include in a line of code If (BarsSinceEntry() == 0)

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

    is it meaningful to include in a line of code If (BarsSinceEntry() == 0)

    How does NT7 recognise the bar a new position was made?

    Alternatively, would this line of code be better:-

    if (Position.AvgPrice > 0)
    {

    }

    Regards

    Kay Wai

    #2
    Hello kaywai,

    Thank you for your post.

    BarsSinceEntry would indicate that a new bar has formed.

    Checking for the Avg Price change would not necessarily be helpful if the price has not changed since your entry, but a few bars have formed.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Cool Matthew. What would be the best way to put in a stop loss at the first instance if the stop loss is based on the entry price and we assume the entry price is filled at market.

      How should i code it?

      Kay Wai

      Comment


        #4
        KayWai,

        You would need to check with the entry is seen as filled by NinjaTrader. This is checked in OnExecution().

        You would need to check this method to check the the stop loss in the first possible instance:

        MatthewNinjaTrader Product Management

        Comment


          #5
          Hi Matthew,

          I've taken a look at the example in the manual and the example provided here.



          This would work fine if the position was flat. What would I do in circumstances where I go from long to short immediately as in, if I were in a long position and the trigger for a short position occurs, the code would be to EnterShort() to switch from a long to short position.

          I'm not trying to over-complicate things but these are issues which cropped up when I went over the backtesting results. If it is at all possible, I'm just looking for simple workarounds.

          Regards

          Kay Wai
          Last edited by kaywai; 09-07-2011, 08:49 PM. Reason: incomplete reply

          Comment


            #6
            Kay Wai,

            I'm sorry I'm not follow - why would this not work when you went from long to short? If your position is reversing, this is a new execution and you should be able to use the same methods you were using before.

            Can you detail what issue you ran into when using this in that scenario?
            MatthewNinjaTrader Product Management

            Comment


              #7
              Hi Matthew,

              In the onbarupdate section, the line of code writes.."if Entryorder == null.....entryorder == enter long();

              If I am already long, is entryorder null? Or should there be 1 entryorder for long and another for short?

              Kay Wai

              Comment


                #8
                Kay Wai,

                Best practice here is to reset order objects to a null state when they are filled or cancelled. So the entry object reference can be null even while you are still in a position.

                You should have a uniquely named object for each unique order statement. It is not a good idea to use the same named object for long and short enter methods.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Ryan,

                  1 issue come to mind.

                  if I were in a long position, and I reset the "long" order object to the null state, AND I get another signal to go long, I would have an extra position, no?

                  regards

                  Kay Wai

                  Comment


                    #10
                    Kay Wai,

                    In addition to your entry condition, you will want to check for current market position. Ensure you are currently in a flat position before entering another long.
                    MatthewNinjaTrader Product Management

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by futtrader, Today, 01:16 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post futtrader  
                    Started by Segwin, 05-07-2018, 02:15 PM
                    14 responses
                    1,789 views
                    0 likes
                    Last Post aligator  
                    Started by Jimmyk, 01-26-2018, 05:19 AM
                    6 responses
                    838 views
                    0 likes
                    Last Post emuns
                    by emuns
                     
                    Started by jxs_xrj, 01-12-2020, 09:49 AM
                    6 responses
                    3,294 views
                    1 like
                    Last Post jgualdronc  
                    Started by Touch-Ups, Today, 10:36 AM
                    0 responses
                    13 views
                    0 likes
                    Last Post Touch-Ups  
                    Working...
                    X