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

Unmanaged Bid/Ask Limit order placement

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

    Unmanaged Bid/Ask Limit order placement

    Hello,

    When backtesting in strategy analyzer, I want to make sure that both - limit and market buy orders are filled at Ask prices, while limit Sell and Market Sell orders are filled only at Bid prices.

    Can you please confirm if it is possible?

    Considering only Long entries:

    The way I am trying to approach it is to:

    1 - In addition to primary series, to add 1 tick bid, 1 tick ask and 1 tick last series for the same instrument as primary instrument.
    2 - Once a primary series shows long signal - then to submit limit order against index of "Ask" series (with some offset). Will that guarantee in historical backtest, that order will be filled only when "Ask" price reaches given price?
    3. Submit Target limit order against "Bid" series, submit stop order also against "Bid" series. Same question - will that guarantee that order will be filled only when "Bid" series reaches that price, and will be filled at that price (I prefer exact bid/ask instead of last series)?

    I don't like "Slippage" concept because it seems that it basically randomly does the slippage (does approximation).

    Thanks!

    #2
    Hello music_p13,

    You can find a details and a walk through of the historical backfill logic in the following page: https://ninjatrader.com/support/help...ill+processing

    The fill will be controlled using the fill algorithm in contrast to the data available in historical data. The order submitted would be filled in conjunction with the rules laid out in the help guide using the supplied series. If you are adding secondary series for ask and bid, that data would be used if you are specifying the BarsInProgress for the order to be submitted to.

    This question would be something that you can directly test by creating two versions of the script to test with. In one test using Last data and in the other test using the Ask and Bid data. If the ask/bid data is being used you should see the fill prices/locations deviate between tests.




    Please let me know if I may be of further assistance.



    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      I have tried creating a strategy with multi-series. I tried managed approach. If I use "Managed" approach, and if I submit order against the bid or ask series - trade doesn't get displayed in Strategy Analyzer. Also, trades themselves in "Trade" tab display totally incorrect PNL (in cents very low) when trading against CL ##-##, and incorrect ticks...

      So I wonder if I have to use Unmanaged appoach when trying to backtest against historical bid/ask prices, and whether executions in Unmanaged will display in Strategy Analyzer chart...

      I am using latest NT8 version 21.1.

      Configure:
      else if (State == State.Configure)
      {
      _entryIndex = 0;
      _bidIndex = 1;
      _askIndex = 2;

      if (IsBackTest)
      {
      AddDataSeries(Instrument.MasterInstrument.Name, Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);
      AddDataSeries(Instrument.MasterInstrument.Name, Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);
      }
      }
      OnBarUpdate:
      protected override void OnBarUpdate()
      {

      if (CurrentBars[_entryIndex] < BarsRequiredToTrade)
      return;
      //Add your custom strategy logic here.
      if (IsBackTest)
      {
      if (CurrentBars[_bidIndex] < BarsRequiredToTrade || CurrentBars[_askIndex] < BarsRequiredToTrade)
      return;
      //Look for Signals
      if (BarsInProgress == _entryIndex)
      {

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      //double curAsk = Bars.GetAsk(0);
      //double curBid = Bars.GetBid(0);
      if (CrossAbove(_fastEma, _slowEma, 2))
      {
      if (IsLimit1)
      {
      _firstEntryOrder = EnterLongLimit(_bidIndex, true, Qty1, Instrument.MasterInstrument.RoundToTickSize(Bars.G etBid(0) - Offset1 * TickSize), "FirstLongLimit");
      }
      else
      {
      SetProfitTarget("FirstLongMarket", CalculationMode.Ticks, Target1);
      SetStopLoss("FirstLongMarket", CalculationMode.Ticks, Stop1, false);
      //EnterLong(Qty1, "FirstLongMarket");
      EnterLong(_askIndex, Qty1, "FirstLongMarket");
      }
      }
      else if (CrossBelow(_fastEma, _slowEma, 2)) //(_bioSsVolumetricMaster.Sell1Plot[0] > 0)
      {
      if (IsLimit1)
      {
      _firstEntryOrder = EnterShortLimit(_askIndex, true, Qty1, Instrument.MasterInstrument.RoundToTickSize(Bars.G etAsk(0) + Offset1 * TickSize), "FirstShortLimit");
      }
      else
      {
      SetProfitTarget("FirstShortMarket", CalculationMode.Ticks, Target1);
      SetStopLoss("FirstShortMarket", CalculationMode.Ticks, Stop1, false);
      EnterShort(_bidIndex, Qty1, "FirstShortMarket");
      //EnterShort( Qty1, "FirstShortMarket");
      }
      }
      }
      }
      }
      else
      {

      }

      }

      Thanks

      Comment


        #4
        Hello music_p13,

        It is unlikely that unmanaged would help here, you would have to recreate your strategy to support that and redesign your logic for that use case. If you are not seeing trades placed that is a case where you need to debug your script to see why.

        You can use Trace orders to see if you are hitting any expected cases where orders are ignored or expired, you can also use Prints to better understand how your logic is executing. As for the PnL, that is something I would need a specific example of to be able to understand why that may be happening. I would suggest to first try to diagnose why the orders are not appearing as you expect as that may relate to the other items you mentioned if the strategy is not working as you expected in general.

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks, as a follow up regarding PNL - I want to use multi-timeframe strategy. I would like to enter on a higher timeframe (maybe minutes / Renkos, etc..), but in parallel to perform account PNL sampling every second (will add a secondary series as 1 second). At some point - when my Realized and Unrealized PNL reach certain goal, I would like to exit position same second. Can I use Managed approach, enter position on one series, but then exit it on another timeframe series? Any suggestions on Managed vs Unmanaged to accomplish this goal? If I enter on one timeframe but exit on another - will it get diplayed in real time and also in historical on Strategy Analyzer chart?

          Comment


            #6
            Hello music_p13,

            Yes the managed can do mostly the exact same thing as unmanaged, the only item that unmanaged offers is to remove the managed order handling rules which lets you submit questionable orders without them being ignored or blocked.

            For multi timeframe scripts you can do what you are asking, you could enter on one timeframe and then exit on another. You can also separate logic between your timeframes. The strategy analyzer will still use historical data so you will still see differences from realtime however that will allow for a more granular exits. You can see this being shown in the following sample: https://ninjatrader.com/support/help...ipt_strate.htm In realtime the secondary series could be used to submit intrabar orders or exits.



            I look forward to being of further assistance.



            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by WHICKED, Today, 02:02 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by selu72, Today, 02:01 PM
            0 responses
            3 views
            0 likes
            Last Post selu72
            by selu72
             
            Started by f.saeidi, Today, 12:14 PM
            8 responses
            21 views
            0 likes
            Last Post f.saeidi  
            Started by Mikey_, 03-23-2024, 05:59 PM
            3 responses
            49 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by Russ Moreland, Today, 12:54 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X