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

Embedded Sample MA Strategy

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

    Embedded Sample MA Strategy

    Greetings

    I am playing with optimizing the Sample MA crossover that is loaded in NT. I set it to use Haiken Ashi candles on a 1M chart. Optimizing it I am using 1/13 crossover. I had 2 questions:

    1. What does the entries per direction mean?
    2. What is the exit strategy in this strategy and how do I adjust it?

    When running a backtest I got great results but I want to make sure I am set up to replicate those conditions in a live test. Here is a screen shot of my backtest.




    #2
    Hello RumHam,

    Thank you for your post.

    Entries per direction refers to how many times a strategy will enter in the same direction before it returns to a flat position. So, for example, if you are in a long position, and the conditions for a long entry become true again while you are in that position, but your Entries Per Direction is set to 1, that second entry order will be ignored by the strategy. If you had it set to 2, it would take the second entry as well.

    Entries per direction doesn't really impact the Sample MA Cross strategy, as that strategy switches from short to long and back again on each cross of the MAs.

    There are no exits in this strategy - it's a simple reversal strategy, so it just enters in the other direction. I would note that this strategy is provided as an example of a basic strategy and is not intended for live trading, simply as a jumping off point for you to create your own strategies.

    As far as backtesting goes, you should expect that a strategy running real-time (live brokerage account, live market simulation, Market Replay etc...) will produce different results than the performance results generated during a backtest. This difference may be more easily seen on certain Bars types (e.g. HeikenAshi, Renko, Point and Figure) than others due to their inherent nature in bar formation - anything that redraws the bar open will not perform the same in a backtest as on live data.

    During a backtest you can select conservative or liberal fill algorithms which will produce different results. Fills are determined based on 4 data points, OHLC of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

    Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

    Also, here is a link to the differences on real-time vs backtest (historical).


    Adding intra-bar granularity can help with this.

    Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades by supplying the correct price at the correct time for the order to fill with.

    In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add this secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (TickReplay).

    Here is a link to our forums that goes into depth on using Order Fill Resolution and Tick Replay to ensure your backtests are as close to real time results as possible:

    Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


    High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically.

    Please let us know if we may be of further assistance to you.

    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    9 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    20 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X