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

EnterLongLimit entering trade at end of bar even tho LimitPrice hasn't been reached

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

    EnterLongLimit entering trade at end of bar even tho LimitPrice hasn't been reached

    I created an Strategy that looks like this. Cross is the Entry Price. If within a given number of bars by user, Price crosses this Entry Price, it should enter a long. I used EnterLongLimit to do that. As you can see on the picture below, it works fine.
    Click image for larger version

Name:	NT1.PNG
Views:	172
Size:	9.1 KB
ID:	1133714

    The problem appears when the price on the next bar of the cross sign doesn't touch or go above the Entry Price. It enters the trade at the end of the bar even though LimitPrice hasn't been reached. See the picture below.
    Click image for larger version

Name:	NT2.PNG
Views:	146
Size:	9.6 KB
ID:	1133715

    Is there anyway I can avoid this problem? What I mean is, It should enter a trade only if the price equals to or goes above the Cross Sign (Entry Price).
    Attached Files

    #2
    Hello fawzanalim,

    Thanks for your post.

    A limit order will fill at the limit price or better. If you place a buy limit order above the market, the current market price will be the better price, and the order will fill.

    You could use logic that checks if the current market price equals your intended level, and then to submit a market order (EnterLong) when that price is breached.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks a lot for such a fast reply. <3

      I thought of adding Current Price. But couldn't figure out how to do that. How do I use current price in my logic?

      Comment


        #4
        Hello fawzanalim,

        The Close PriceSeries (Close[0]) will be the current market price if we are calculating OnPriceChange or OnEachTick.

        I.E.
        Code:
        if (Close[0] >= MyPrice)
            EnterLong();
        Please let me know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          I will use this for back testing and optimization. If I would use this for trading, I could've compared the Entry Price with High and set the strategy calculation mode to Price change or each tick. Since it is for back testing and optimization, I can's use these.

          Comment


            #6
            Is there any other solution to this?

            Comment


              #7
              Hello fawzanalim,

              You can use the Playback Connection to test strategies that use Calculate.OnPriceChange or Calculate.OnEachTick.

              Playback - https://ninjatrader.com/support/help...connection.htm

              If you would like to backtest a Calculate.OnPriceChange or Calculate.OnEachTick strategy with the Strategy Analyzer, you can:

              1. Enable Tick Replay
              2. Submit orders to a single tick data series.

              Tick Replay is required to have the logic processed OnEachTick or OnPriceChange, and submitting orders to a single tick data series would be required to have those orders filled with intrabar data. This is a bit more complex, so it may be easier to use Playback for testing.

              Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

              Backtesting with intrabar granularity (submitting orders to a single tick data series) - https://ninjatrader.com/support/help...ipt_strate.htm

              Please let us know if you have any questions.
              JimNinjaTrader Customer Service

              Comment


                #8
                I added the 1 Tick Data series.
                Click image for larger version  Name:	NT1.PNG Views:	0 Size:	5.3 KB ID:	1133816
                Checked "Show Tick Replay" in the Option and set the strategy to OnEachTick.

                Tried both EnterLong and EnterLongLimit.
                Click image for larger version  Name:	nt3.PNG Views:	0 Size:	2.5 KB ID:	1133818
                Click image for larger version  Name:	nt4.PNG Views:	0 Size:	13.7 KB ID:	1133819


                Click image for larger version  Name:	nt10.PNG Views:	0 Size:	2.4 KB ID:	1133820
                Click image for larger version  Name:	nt11.PNG Views:	0 Size:	12.1 KB ID:	1133822


                Sorry for the message being so big. I've come this far only for your help. This is the most crucial step for me. I've been stuck here for about a week. So, it would mean a lot if you could find me a solution. Also, please let me know if you want to have a look at the code.
                Attached Files
                Last edited by fawzanalim; 12-25-2020, 07:58 AM.

                Comment


                  #9
                  Hello fawzanalim,

                  You need to submit orders to the single tick data series. Please see lines 83 and 91 in the example given where different EnterLong/EnterShort overloads are used where a BarsInProgress index is specified. You may reference the Managed Approach documentation of the Help Guide to reference other overloads for different order types.

                  Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

                  Please also be sure to review the Multi Time Frame and Instruments documentation when working with a multi time frame strategy like this.

                  Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

                  Once Tick Replay is shown, Enable Tick Replay must be checked in the Strategy Analyzer or in the Data Series window for the chart you apply the strategy on.

                  We look forward to assisting.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot. It worked. You guys are the best.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by junkone, Today, 11:37 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post junkone
                    by junkone
                     
                    Started by quantismo, 04-17-2024, 05:13 PM
                    5 responses
                    35 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by proptrade13, Today, 11:06 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    34 views
                    0 likes
                    Last Post love2code2trade  
                    Started by cls71, Today, 04:45 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post eDanny
                    by eDanny
                     
                    Working...
                    X