Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting with entryOrder based on Bid/Ask

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

    Backtesting with entryOrder based on Bid/Ask

    Hi,

    After coding a fairly robust strategy I would like to take this to the next level and run the backtest based on bid/ask to replicate a real live trade scenario taking into account all the wild spikes in spread from my broker FXCM especially on news announcements etc...

    So how would I go about building the strategy code for backtesting based on bid/ask for all my entered orders (managed approach) do I need to go down the path of unmanaged approach?

    like for instance in the online guide I have the following order entry which uses the bid for the buy order.
    Code:
     [LEFT][COLOR=#808080][FONT=Consolas]entryOrder [/FONT][/COLOR][COLOR=#808080][FONT=Consolas]= [/FONT][/COLOR][COLOR=#808080][FONT=Consolas]SubmitOrderUnmanaged([/FONT][/COLOR][COLOR=#FF6600][FONT=Consolas]0[/FONT][/COLOR][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][COLOR=#808080][FONT=Consolas]OrderAction.Buy,[/FONT][/COLOR][COLOR=#808080][FONT=Consolas]OrderType.Limit,[/FONT][/COLOR][COLOR=#FF6600][FONT=Consolas]1[/FONT][/COLOR][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][COLOR=#808080][FONT=Consolas]GetCurrentBid(),[/FONT][/COLOR][COLOR=#FF6600][FONT=Consolas]0[/FONT][/COLOR][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][COLOR=#800000][FONT=Consolas]""[/FONT][/COLOR][COLOR=#808080][FONT=Consolas],[/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"Long Limit"[/FONT][/COLOR][COLOR=#808080][FONT=Consolas]);[/FONT][/COLOR][/LEFT]
    And the above would work under backtest and reference the historical bid/ask data i have downloaded? As when looking on the strategy analyser I only have the option of running last,bid or ask, I take it I would override this if manually pick the currentBid or currentAsk when submitting the order?

    Thanks for your help.


    #2
    Hello mr_trade,

    For backtesting on forex, you would want to add a 1 tick ask and 1 tick bid series to the script, and use the BarsInProgress index of the ask series for buy orders and BarsInProgress index of the bid series for sell orders.

    Below is a link to a reference sample that demonstrates adding series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thankyou Chelsea for the quick reply. My strategy was based on tick anyway so I have added the additional data series for both bid and ask, but do I need to reference the Instrument as specified in the documentation or is there a way I can just use the same primary instrument to keep things simple and dynamic when backtesting rather than hardcoding this into the strategy? Similar to the first one using "Data.BarsPeriodType"?

      Code:
      AddDataSeries(Data.BarsPeriodType.Tick, 1);
      AddDataSeries("@US30", Data.BarsPeriodType.Minute, 1, MarketDataType.Ask);
      AddDataSeries(Data.BarsPeriodType.Minute, 1, MarketDataType.Bid);
      Thanks again for help.

      Comment


        #4
        Hello mr_trade,

        From the help guide tips:

        "4. For the instrument name parameter null could be passed in, resulting in the primary data series instrument being used."


        AddDataSeries(null, BarsPeriodType.Tick, 1, MarketDataType.Ask);
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Perfect nice and easy thankyou. All looking so much better now using bid and ask makes more sense. However, just to make sure the tick Replay tickbox is now useless now i have coded this manually and no longer required right? So i can ignore tick replay option?

          Thanks

          Comment


            #6
            Hello mr_trade,

            That depends on what TickReplay was being used for.

            TickReplay doesn't help with fill accuracy.

            Instead it allows Calculate to run with OnPriceChange / OnEachTick historically to allow indicators to update real-time..

            If you have indicators you need updating in real-time, you would still need TickReplay.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X