Traders Guide To Ninja Trader Monte Carlo Analysis

Posted by TraderWerks | Free Indicators,Free Software,Indicators,Strategy | Monday 27 December 2010 6:24 am

Well since NinjaTrader 7 will probably be released in 2008 2009 2010 is released , I wanted to look one of the new features.

One of the most exciting is NinjaTrader 7 has a built in Monte Carlo analysis section. I should say cool and useful instead of exciting.

Before NinjaTrader 7 , if I wanted to run a Monte Carlo analysis , I would have to do it myself from a trade file. Pretty annoying and time consuming.

OK , WHAT IS MONTE CARLO ANALYSIS ?

There is no single Monte Carlo method; instead, the term describes a lot of approaches.

Monte Carlo simulation uses a random sampling of probability distribution as model inputs to produce hundreds or thousands of possible outcomes  providing probabilities of different outcomes occurring.

A Monte Carlo analysis looks at your trades, puts them in a random order over and over, to give you and idea of what your trading should look like over the long term. Note that I said ‘give you an idea‘. Not that anything is certain especially in trading.

OK SO WHAT DOES THAT MEAN FOR A TRADER

Using Monte Carlo analysis means given what we know about a trading systems results, we can try to get a best guess as to how a trading system would perform in the future.

Monte Carlo Simulation will randomize your trade results over and over again in multiple simulations to provide you with a normal distribution of simulation performance.

So say you have been trading for a while and you have 100 trades in NinjaTrader. What Monte Carlo will do , is randomize all your trades and give you a percentage of whatever you are measuring above or below a value.

It is a big ‘what if’ game. Looking back at the example, if we have a 100 trades and we do 100 trials , we will have information such as ’95% of the time, we made X dollars’ and things like that. Perhaps some examples would help.

EXAMPLES

Now all these examples I am talking in generalities. This is a random distribution which in itself is , well, random. Now to prevent me from having to write “the results are based on a random distribution of your result set and should only be viewed as educational in nature” everywhere , just add it to the end of every sentence. Thank you for your support.


    Cumulative Profit


Click For Larger Image

So for this particular system, we are looking at the amount profitable. The bottom is a percentage of the trades. If you click on the image, you will see a highlighted area at 5% / $35.3. What that means is that 5% of the time, the profit will be less than $35. Or 95% of the time the profit will probably be greater than $35.


Click For Larger Image

This chart is the maximum consecutive losses.  Here we can say that 70% of the time, we only have one loss in a row.


Click For Larger Image

Finally, Drawdown. Looking at this chart, well over 90% of the ‘tests’ would have less that a $200 drawdown. Now with that information, it is much easier to detect fraud.


PIMPING MY NEWSLETTER

I don’t post often, but I do have a mailing list you can subscribe to in the meantime. I usually write about Ninjatrader programming, but other trading topics as well. Subscribe to TraderWerks Blog by Email


Photo by of http://www.flickr.com/photos/kjunstorm/

Three Bar Reversal ( 3BR ) Strategy With Free Source

Posted by TraderWerks | Free Software,Indicators | Sunday 5 April 2009 12:04 pm

barrev

3 Bar Reversal Pattern ( Strategy Wizard )

        This strategy is from an article  by Thomas Bulkowski ”Are Three-Bar Patterns Reliable For Stocks?” . It was in the  January,2000 issue of Stocks&Commodities magazine. As an aside, I want to mention, that there are a lot of things called “Three Bar Reversals’, but I am just looking at this particular one.

        This strategy was done in strategy wizard using NinjaTrader so those who are not into C# programming, can fool around with it. You can import this strategy with File->Utilities->Import NinjaScript. Ninja expects a zip file when you import so don’t unzip the file after you download it, just import it as is.

THREE BAR REVERSAL

        I coded this up in NinjaTrader ( Sorry Tradestation people ) for use on daily charts and then I tested it on one stock. I chose AAPL for two reasons (1) I love Apple computers (2) It comes first alphabetically. I also like to trade AAPL stock, it is one of my favorites trading stocks.

        It is a stop and reverse system, which means it is always in the market. When it gets a buy signal, it goes long, when it gets a sell it closes the long position and goes short. Some people like this style of trading system, some people do not.

Rules :

- Day two of the three-day pattern has the lowest low / highest high of the three days.

- Day three  must have a close above the prior day’s high/low.

- No DoJi’s

If you want the full details , you can order a reprint from the net.


I discovered this gem of a pattern while prospecting for ideas in a recent issue of STOCKS & COMMODITIES.In the interview with Kevin Haggerty was the following pattern description: One example [to determine a change in direction ]is a three-bar pattern,which is the same one that futures traders use.The stock establishes a low price as a swing point.Once the stock closes above the high of the low day,to me,that is a change of direction for an undetermined period. Using this description as a guide,I decided to formalize the shape and behavior of the pattern.

-Thomas Bulkowski




SIXTEEN MONTH TEST ON AAPL (Apple Computer )

        So I tested this system from Jan 1, 2008 to today, April 4, 2009. No particular reason why I picked that date, I just wanted to start on a Jan 1. It ran for 16 months in backtesting, and the results are in the image about. You can click it for a larger image.

        Now admittedly, AAPL is a very volatile stock, that I do like to trade, so this probably does not represent your average stock. However, it has been a very volatile period and a lot of equities have been trading like AAPl stock.

        The strategy returned $84 a share over the 16 monhts, and had a win/loss ratio of 53%. Just a little better than flipping a coin but the profit came from the win /loss ratio. The wins were 50% greater than the losing trades. Average trade was over a week, which is a doable rate for the retail trader who cannot watch the market all day. The profit percentage was 4.41% percent a month.

aapl-11_12_2008-4_5_2009-daily

WHAT CAN BE DONE TO IMPROVE THIS STRATEGY

        I think there is a lot to be said for this strategy. However, it is an ‘always in the market’ kind of strategy that can get caught in a downdraft. So here are some suggestions ( If you try any of these, let me know and I will update this post )

  1. If used on a portfolio, use a portfolio normalization scheme for position sizes.
  2. Stop Loss at support and resistance levels.
  3. Profit Stop.
  4. Test performance on ETF’s

WHERE CAN I DOWNLOAD THIS

        You can download this here,3 Bar Reversal Strategy . Enjoy

None of this is investment advice. This is just a strategy I coded for entertainment purposes only. Nothing more. Whatever you do with this is up to you. There is no warranty expressed, adumbrated, implied, insinuated, inferred, implicated, aspersed, or otherwise in existence.

The ONE Free Thing You Must Do Every Week On Your Trading Computer

Posted by TraderWerks | Free Software | Wednesday 25 March 2009 8:30 pm

clamwin_logoVIRUSES SUCK

Damn computer viruses. You have to keep your trading system virus free, it is a matter of dollars and dollars.

A virus infected systems, quite frankly sucks. These viruses are written by kids /gangsters/spammers or other miscreants. They spend a lot of time to get your computer infected for a lot of reasons. Sometimes they infect your computer for fun, to spend spam, harass companies or any number of other reasons that are not very nice.

Think about this , do you want your trading account at the mercy of some 14 year old virus writer who wants to send spam on your computer ? I think not.

NEW THREAT USB DRIVES

I must admit, the computer that runs my NinjaTrader strategies was infected a couple of months ago. I was shocked because I only run NinjaTrader on that machine. It was a particularly nasty virus that was crashing my machine soon after startup.

A computer virus is a computer program that can copy itself and infect a computer without the permission or knowledge of the owner. A true virus can only spread from one computer to another for instance because a user sent it over a network or the Internet, or carried it on a removable medium such as a floppy disk, CD, DVD, or USB drive. Viruses can increase their chances of spreading to other computers by infecting files on a network file system or a file system that is accessed by another computer.
From Wikipedia

    So I cleaned the virus with the help of a Linux machine, and set out to  find the source of the infection. I scanned all my Windows machines. I have a mixed network so other operating systems might store a virus on a network drive while these computers would not be infected themselves. So I scanned my network drives and still nothing.

    Finally , I started scanning my USB drives I had laying around an there it was. The same virus that had infected my machine. I had let my 9 year old nephew copy some mp3 files with that USB flash drive. Great.

CLAMWIN

ClamWin is a free virus detection program. You should not have viruses to begin with, but that is beside the point I am trying to make here. Sometimes these things happen when you least expect it. At my former firm, we ran virus checks on our machines every weekend.  Every weekend, I run still run ClamWin on my trading and development computers to check for viruses.

Clamwin is based on the open source GPL program ClamAV, which can scan for viruses on Linux and Mac operation systems. The virus definition update files are also free. Open source guys rock.

VIRUSES CAN COST YOU MONEY

Some people complain about the performance of NinjaTrader. I wonder how many of those peple have infected computers, and blame the ‘slow’ computer.

NinjaTrader will use lots of memory, and viruses can cause a computer to run slowly or freeze during trading. Trust me on this one, you do not  want NinjaTrader to freeze while you’re in a trade.

Your trading computer should just be for the development and trading of systems. Do not let your 9 year old nephew download random software to your trading computer ( or copy mp3 files ).

So run ClamWin every week and keep your trading computer virus free.

FULL DISCLOSURE : (1) I have no connection with ClamWin except as a user (2) Open Source guy are great to have around (3) Did I mention it was free?