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

Setting Spread When Backtesting

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

    Setting Spread When Backtesting

    Is there a way to set the spread when backtesting through Market Replay? I have been searching for a while now, but I have not found any workable solutions.

    Just to illustrate with an example, I have been running my strategy repeatedly on EURUSD through the same period of time. The first position it enters has an Ask price of 1.06679 and a Bid price of 1.06678. This is a spread of 0.1

    I plan to use Forex.com as my broker. Their website states that the typical spread for EURUSD is 1.3 pips (https://www.forex.com/en-us/why-us/w...bility/pricing).

    This means that to accurately backtest EURUSD for my purposes, the example above would need an Ask price of 1.066855 and a Bid price of 1.066715 (roughly, since it wouldn't actually have that many decimal points).

    Is there any way for me to set that spread of 1.3 pips?

    In searching these forums, I did see it suggested that you can use slippage to simulate spread. However, I am not having any success with it. Perhaps I am doing something wrong. No matter what I enter for slippage, the Ask and Bid prices remain the same as when I had a slippage of 0. I even tried putting in ridiculously high slippage like 100 to no effect. I have also ensured that “enforce immediate fills” is not enabled.

    Any help would be appreciated, thanks!

    #2
    Hello geofftambler,

    Thank you for your note.

    Slippage is going to apply to market orders, and assuming your strategy gets in and out with market orders, adding a slippage value would be a way to discount returns. However, as of now, NinjaTrader restricts fills to within a current bar. For example if you had a stop which was triggered at 50:50, which was also the low of a 15 minute bar, NinjaTrader would not fill this order outside the bar, thus slippage would be ignored. No slippage would be applied if you were submitted a order to a secondary tick series, another limitation of the current backtesting logic.

    I will add your vote to SFT 1137 which would remove this restriction of fills to within the current bar.

    A solution for you might be to create your own performance metric, which you could have total net profit adjusted, for example creating MyTotalNetProfit =TotalNetProfit-1.3*Trades*2.

    I do not have a sample of how this could be done but you could open the NinjaScript Editor and see in the Performance Metric Folder>SampleCumProfit.

    You should also see the following two links,




    If you do not have programming experience I can follow up with a list of third parties that would be interested in programming this for you.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi AlanP,

      Please put me down for SFT 1137 as well.

      Thanks!

      Comment


        #4
        Hello wadams,

        Will do, thanks!

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        31 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Mindset, 05-06-2023, 09:03 PM
        10 responses
        265 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by michi08, 10-05-2018, 09:31 AM
        5 responses
        743 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X