s
Contact Login Register
h M

NinjaTrader Algo Trading Strategies

rss

Best practices for NinjaTrader Algotrading with indicators and strategies.... Topics include algograding with Futures, Crypto, Forex, and equities/stocks. How do you backtest / optimize strategies with NinjaTrader? You have come to the right place!

Often we get requests to help with Ninjascript / NinjaTrader 8 indicators and strategies that do not always fit within our required work for engagement... This does not mean we don't want to be helpful! We always encourage algo trading and want to help novices and customers alike with best practices. We will continue to work on videos but are also planning weekly videos on best practices. 

Within each of our custom NinjaTrader straegies we often include some basic setup configurations... These include:

  • Wait X Bars from new trading day
  • Wait X Bars from last exit
  • Exit after X Bars 
  • Setup Stop Loss to Breakeven after X Bars
  • Exit after reverse tail (topping / bottoming wick/tail)
For the next few months we will continue to post a solution to each of these... for now here are some code examples for this.
 
Within OnStateChange:
   WaitXBarsFromNewTradingDay = 10;
 
WithinOnBarUpdate:
                if (Bars.BarsSinceNewTradingDay < WaitXBarsFromNewTradingDay && Position.MarketPosition == MarketPosition.Flat && EnableDebugMode == true)
                {
                    Print("RETURNING Bars Since new day has not fired... We will skip this order because we are currently flat in the market. ");
                    Print("Wait X Bars from new trading day: " + WaitXBarsFromNewTradingDay);
                    Print("Bars since new trading day: " + Bars.BarsSinceNewTradingDay);
                    BarBrushes[0] = DaysFromTradingDayBrush;
                    StrengthCandles1.BarBrushes[0] = DaysFromTradingDayBrush;
                    return;
                }
 
Within config properties:
 [NinjaScriptProperty]
        [Display(Name = "Wait X Bars From New Trading Day", Order = 16, GroupName = "Order Entry")]
        public int WaitXBarsFromNewTradingDay
        { get; set; }
 
Wanting a code example we are not including here? Let us know how we can help.
 
Chad
 

Epic+Bounce%2C+setup+for+large+wicks+near+high+lows.+Configured+entry+two+bars+after+signal+confirmation..jpeg

Trading crypto futures with NinjaTrader and Epic Bounce strategy. 

c398deea-4f71-4a93-a970-d8a5f9f80124.png

Several customers have been wanting to trade TD Ameritrade / thinkorswim with algo trading and after they initially research this idea... they usually end up in an endless loop trying to backtest using TDA OnDemand (extremely limited), and then they also find out that although Thinkscript is easy to learn and similar to C#, there is no real way to actually enable (at least at this time and likely a while given the Charles Swab merger).

So... For these clients some of the suggestions we have been utilizing several setups for Algo Trading with Epic Collection. I do want to point out several pros and cons when algo trading with TD Ameritrade and NinjaTrader:

Cons (as far as I know, most of these are all known issues when searching the NinjaTrader forums):

1. TD Ameritrade doesn't provide tick data and doesn't seem to work well with intrabar setups where the stop loss might change over time. 

2. Lots of errors pop up (which seems difficult or I can't find a way to disable) for things such as "no shares to short" messages. We ended up setting up only long setups. 

3. When an OCO orders is placed with a profit target and stop loss... that cannot be changed throughout the duration of the order. So basically for any setups where you would ever want to change the stop loss or profit target, this is a problem. 

4.  We initially had problems when we would have hundred plus positions open with the NinjaTrader feature "Close all positions" at a specific time. Basically this would work great with 15 instruments but with 100 it would end up timing out and leaving positions open overnight! 

We later added code into Epic Collection to set the trading session hours outside of the instrument trading hours. This is helpful for many reasons as there is also the option to flatten the strategy and end it if its running outside of that timeframe.

Pros:

1. No commissions! 

2. Sometimes the trades for Epic VWAP or Epic Bid would be in/out over 250+ times per day for over 100+ instruments! Seemed to trade well, especially for setups where the setting was "OnBarClose" and at least a 5 minute or more data series. 

3. Easily setup similar strategy that would run on percent basis with "Dynamic Quantity" enabled on the Epic Bid or Epic Follow strategy... With this we would run a daily import for specific stocks we wanted to target for the day, import this into a list within NinjaTrader, and then choosing the instrument for the strategy, choose "Select All" for the instrument list. This would end up creating 100+ strategies all with the similar parameters and all we have to do each morning is import the list, create the strategy one time and then right click on all of them and click "Enable".

PYPL trades well with Epic Follow... Epic Follow will look for correlation between index's or another instrument and if a major change in the index has occurred, and the same change has not occurred in the master instrument, it will enter in the appropriate direction to "follow" the index. 

 

Epic Bid, is a strategy which keeps an ongoing bid price for your instrument based on the lowest price of the last “x” bars. You can define optional settings such as price offset (above or below that price). 

 This first video covers only a brief summary of Epic Bid indicator and Epic Bid Strategy for NinjaTrader 8. Please check the blog and comments for upcoming videos on NinjaTrader 8 strategy optimzation and best practices with Epic Bid.

TradeCryptoFutures.png

When we first started backtesting Epic Follow I had high expectations between futures and stocks but I was extremly surprised to see the results that came from backtesting cyrpto against futures (and the other way around). Did a big move in NQ/ES affect Bitcoin? Did a significant move in bitcoin affect the Nasdaq? Surely not.... but wait, it looks like it does! 

Most of this strategy trades with tickers I am really not used too... Do you guys trade RTY? 6B? ZW? This was backtested from 01-01-21 to 03-10-21 against Epic Follow and literally all futures are coming up green, but I typically only trade micros and not sure I have the margin to keep these (although strategy is set to close EOD). It does test ok against MES and MNQ but nothing compared to the others I mentioned.

What crypto exchange do you prefer? As we continue to add crypto API's for trading with NinjaTrader, which ones would you prefer to see added?

-Chad

DISCLOSURE: Futures, stocks, and spot currency trading have large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures, stocks, commodities and forex markets. Don't trade with money you can't afford to lose.

Please remember that past performance may not be indicative of future results. Different types of investments involve varying degrees of risk, and there can be no assurance that the future performance of any specific investment, investment strategy, or product (including utilizing Nash Technologies indicators or back-testing strategies), or any non-investment related content, made reference to directly or indirectly in this commentary will be profitable, equal any corresponding indicated historical performance level(s), be suitable for your portfolio or individual situation, or prove successful. Due to many factors, including changing market conditions and/or applicable laws, the content and software may no longer be reflective of current opinions or positions.

Historical performance results for investment indices, benchmarks, and/or categories have been provided for general informational/comparison purposes only, and generally do not reflect the deduction of transaction charges, the deduction of an investment management fee, nor the impact of taxes, the incurrence of which would have the effect of decreasing historical performance results.  It should not be assumed that your Nash Technologies LLC product, consulting, or service correspond directly to any comparative indices or categories.

Known Limitations / Testimonials: Neither rankings and/or recognition by unaffiliated rating services, publications, media, or other organizations, nor the achievement of any designation or certification, should be construed by a client or prospective client as a guarantee that he/she will experience a certain level of results if Nash Technologies LLC engaged, or continues to be engaged, to provide financial indicators or consulting services. 


Site creation : Dune Interactive