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

How can I place an order at bid when entering long, at ask when entering short?

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

    How can I place an order at bid when entering long, at ask when entering short?

    I searched various options of how I place orders on the Strategy, but I can't find how I can place an order at bid when entering long, and vice versa.

    EnterLong and EnterShort are market order so I'd like to place my order at where bid and ask prices are respectively.

    Thanks

    #2
    Hello rocketman7,

    You would need to use a Limit type order to do that however keep in mind that a limit does not guarantee that the order will be executed only that it has a fixed price. As long as that price is traded then it could be executed.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Are GetCurrentBid() and GetCurrentAsk() only working when State is realtime?

      Comment


        #4
        Hello rocketman7,

        That is correct, in historical data those return the close price.
        JesseNinjaTrader Customer Service

        Comment


          #5
          On the backtesting, shouldn't they have the same result as GetCurrentBid/Ask will bring the Close price we had used in EnterLong/EnterShort?
          I have quite different results when applying each line on the backtesting.

          Code:
          EnterLong(Convert.ToInt32(DefaultQuantity), "");
          EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid()  , "");
          Code:
          EnterShort(Convert.ToInt32(DefaultQuantity), "");
          EnterShortLimit(Convert.ToInt32(DefaultQuantity), GetCurrentAsk()  , "");

          Comment


            #6
            Hello rocketman7,

            When backtesting only the OHLCVT values are known for each bar so the ask and bid are unknown and the close is substituted with those methods. It is noted in the help guide that the close is substituted during historical tests. You can use TickReplay to get historical ask and bid prices at the time of the last or if you wanted the full granularity and are using a data provider that has historical ask and bid data you can add a secondary ask and bid series to reference which will give you ask and bid values in a backtest.

            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by elon888musk, Yesterday, 02:22 PM
            2 responses
            14 views
            0 likes
            Last Post elon888musk  
            Started by kiss987, 05-16-2018, 02:19 AM
            11 responses
            2,845 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by dinest93, Today, 03:01 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by kidpoker007, Today, 07:21 AM
            2 responses
            12 views
            0 likes
            Last Post kidpoker007  
            Started by Ludwik, Today, 06:04 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X