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

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 judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            53 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            33 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            5 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            19 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            6 views
            0 likes
            Last Post cre8able  
            Working...
            X