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!

I was recently researching specific algo bots for crypto and came across an interesting setup on YouTube…  The setup seems pretty popular and does backtest out pretty well so I decided to develop a free crypto bot for NinjaTrader and offer it to the algo community! 

The video that I based the algo bot on is below (Note: we are not affiliated in any way with this organization or content, just providing some backstory as to what the setup is based on). https://youtu.be/xbAQR1e1XY8

The basics for the setup...

  1. Add the SSL Channel indicator to a one hour chart … Determine the direction from this (I have included a free NinjaTrader SSL Channel indicator in the download / install). The default settings of “10” are ok for the SSL Channel Period but you can change these in the bot if you desire. 
  2. Add an EMA indicator to a smaller timeframe chart (from his video, a 5 minute chart).  For the setup g from this video he is using a 50 EMA, however you can adjust this within the crypto bot strategy to be any EMA you want. 
  3. Wait for the price on the 5 minute chart to be below the EMA for long entries, or above for short entries (you can choose to have it crossing or below within crypto bot strategy setup). 
  4.  Choose from any bullish or bearish setups for your entry… Within the video he is going with a Engulfing pattern for entry however in the Crypto Bot Strategy you can choose from any of these setups for entry:

a.   Engulfing
b.   Harami
c.   Harami Cross
d.   Belthold
e.   Hammer
f.    Hanging Man
g.   Morning / Evening Star
h.   Rising / Falling Three
i.    Three Soldiers / Crows
j.    Piercing Line
k.   Upside Gap Two Crows
l.    Downside TasukiGap
m.  Dark Cloud Cover

Crypto Bot Strategy (Download Free Below!) 

 

I ended up adding several features to the strategy which can provide optional settings... 

  •  A minute interval for the higher timeframe (default is 60) 
  • Change several other inputs such as the SSL Channel period, EMA, and multiple entry inputs. 
  • Trailing stop loss 
  • Display the upper TF on the lower TF chart (with this you don't really need to ever pull up the upper TF SSL Channel). 
  • Highlight unusual volume (either very minimal or significant) on the chart. At the moment this is only part of the indicator and not the strategy... I am open to input on if anyone thinks these variables would be useful for integration within the strategy. 
  • Ability to enable the algo bot on startup, or based only after clicking a button after its enabled. Also individual buttons to manually go long, short. 

Order Entry Options

  • Optionally only enable long or short entries (or both!)
  • Profit target can be a recent high/low, or standard ticks/currency. 
  • Stop loss can be trailing or static number of ticks/currency.
  • Ability to set stop loss to break even after "X" number of bars.
  • Take profit / exit position after "X" number of bars in your direction.
  • Exit reverse candlestick pattern - Will exit on any reverse pattern! 

 

Backtesting - Below is some historical results with ETH... There are also some great results with BTC and others as well.  

The file is a free download however you do need to register with us to receive the file.

DOWNLOAD CRYPTO BOT STRATEGY FOR NINJATRADER (FREE BOT!)

Hope this is useful for anyone! Please post comments and any feedback!

-Chad

NashTech_Strategy_WaitXBarsBeforeReentry.jpeg

Feature: Wait X Bars from Last Exit

Benefits: Avoid continued entry and/or exit, possibly in market conditions that are not suitable for the trading strategy. 

We code a log of NinjaTrader strategies... and we like to provide tips for other developers or traders wanting to create custom strategies for NinjaTrader. 

Sometimes the market doesn't always respond well to your algo strategy... In that situation, you want to avoid entry, often for money management and controlling your trading strategy. We use a special feature within NinjaTrader for this.

We include this feature within all of the Epic NinjaTrader Indicators and strategies but you can reference the same code below:

Within OnStateChange()


BarsRequiredBeforeReEntry = 5;

 

Within Properties:


[NinjaScriptProperty]
[Display(Name = "Bars Required Before ReEntry", Order = 1, GroupName = "NashTech Order Entry")]
public int BarsRequiredBeforeReEntry
 { get; set; }

Within OnBarUpdate:


int BarsSinceExit;
BarsSinceExit = 0; 

 if (BarsSinceExitExecution() != -1)
                {

        BarsSinceExit = BarsSinceExitExecution();
           
                    if (BarsSinceExit < BarsRequiredBeforeReEntry)
                    {
                        if (EnableDebugMode == true)
                        {
                            Print("We should only be here if bars required before re-entry is less than bars since exit");
                            Print("Bars Since Exit Execution:" + BarsSinceExit);
                            Print("Required Before ReEntry:" + BarsRequiredBeforeReEntry);
                            Print("Time of Skipping order:" + Time[0]);
                        }
                    
                        BarBrushes[0] = PendingBrush;

                        return;
                    }

                }

 

 

Questions? Leave a comment! 

 

-Chad

All subscribers and lifetime license users get the latest templates to install based on our weekly optimization results. If there is an instrument you want the most recent template for, just ask! For trial users all templates are about 30 days old.

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 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

EpicSocial_AlgoTrade.png

Hi Algos!

Finished up with an algo related to social trending... There are multiple setups and it does require a little hand holding each morning (importing list of higher volume stocks that are trending).

General setup:

1. Setup is daily / not intraday.

2. Ignitor bar comes from stock that's already trending on twitter/reddit/stock twits and the first high volume day from 'x' days back... such as 200% (or any variable that is back testing well as I still optimize it).

3. Parameter for number of "Pause" bars, awaiting confirmation. Confirmation comes from when trending stock has spiked in activity or sentiment score (tracking 7, 14, 30 day moving average of activity for stocks etc...). If nothing happens with social sentiment within the pause bars, no trade.

4. If during pause bars social sentiment (positive or negative) or activity (number of posts) spikes, entry order is placed (as long as stock has not already went up too much in last 'x' bars.

5. Early exit option when sentiment has dropped while activity has spiked. I am actually not sure on the best exit yet... Could be after number of bars, or maybe after high volume and high wick?

Keeping this setup now only for long as all my backtesting basically represented "no such thing as bad press" and even poor social media sentiment would still lead to spikes... also who wants to be shorting any of these trending stocks, too risky!

Let me know if you have any ideas what have worked for you related to algos for social sentiment, especially best entry/exit setups.

-Chad

Lower studies:

1. Study below volume represents social sentiment (positive / negative discussions towards stocks).

2. Study at the very bottom below the social sentiment is activity (number of posts / mentions of a stock) for the day.

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