8 Great Websites For Traders

The summer slowdown is almost upon us again and here is my list for websites you could read over the end of the summer.

Here is my list of sites I go to for trading information. I am a futures trader myself, so these sites will favor that type of trading. They are not in a particular order, so read the whole list.

If you have any websites that you think should be included in this list, place the link in the comments at the bottom of the page and I can include it.

EXCHANGES

I include the exchanges, because I am surprised at how many people DON’T go to the exchange websites, and instead will ask questions on message boards for things that would only take a few minutes to find on a the exchange website itself.

The CME Group www.cmegroup.com

You really need to check this site if you are trading CME contracts like the ES, 6E, CL, etc. What I am saying is that you should be familiar with the exchange for things you trade. This is the same for Eurex ( www.eurexchange.com ) and the ICE ( www.theice.com)

NEWS SITES

Barrons Econoday    Barrons Econoday

We may not trade the news, but we all should know when the news comes out. I like this calendar better than say the Forex Factory calendar. It seems more accurate, but is not really focused on the Forex market. If you are a forex trader, you probably want to try the Forex Factory calendar.

Bloomberg     www.bloomberg.com

I like Bloomberg, it has good reporting, and I fell i have a decent view of what HAS happened in the world. I don’t have a Bloomberg terminal right now, but I hope to grab one in the future.

The Big Picture www.ritholtz.com/blog

The Big Picture has been around for a long time. Barry Ritholtz is a perm-bear that posts some thoughtful posts.

FORUMS

I really do not like forums anymore. I go to the couple listed below and Wilmott.com ( which I did not list because it is too technical )

I recently went back to EliteTrader and could not take more that a few pages of rude posts. ( You will not see EliteTrader on this list. ) In the early 2000’s it was the place to go, and there are a lot of good threads if you can find some of the good threads. Today , it is mainly junk.

Big Mike Trading Forum    www.bigmiketrading.com

Big Mike’s is the only forum I really participate in or visit regularly. The site owner Big Mike is pretty good at keeping the rudeness level down and the trolls out.

I interviewed Big Mike a while ago, so take a look at the entire interview. A Talk with Big Mike from Big Mike’s Forum

The Long Room discussions.ft.com/longroom

This is a good read. I don’t know how to describe it, so go look for yourself. It is mainly professionals in the industry, so very few trolls or rude posts.

Nuclearphynance    www.nuclearphynance.com

A great site, however, I must warn you that is is low volume, geeky and newbie questions may get answered slowly. I don’t visit as often as I visit Big Mikes forum. Some really good guys hang out there.

OTHER

TED    www.ted.com

TED is a small nonprofit devoted to Ideas Worth Spreading. It started out (in 1984) as a conference bringing together people from three worlds: Technology, Entertainment, Design.

They have a lot of videos on some pretty interesting topics. Not directly related to trading, but something fun to watch in your down time.

 


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 curtesy of Andre Weason

Trading On A VPS : Interview with Speedy Trading Servers

SUMMER INTERVIEWS

I think I have gotten into the habit of doing a summer interview. I quite like doing them. This summer’s interview is with Sam of Speedingtradingservers. I have used one of his VPS’s for a while and I have been quite happy with running on his machine.

I have been running on different cloud servers and VPS’s for a while. The first VPS I used was with AWS ( Which was horrible by the way ) and then I ran my own VPS on a server on the east coast.

The reason I switched was there was a connectivity problem between the east coast and Chicago. On that day I could get to the VPS, but I could not get Ninja to connect to the broker’s system. I did not know my position or if I still had one. The brokers phone lines were busy because so many traders were calling in at the same time. I will leave it to your imagination as to how it all turned out.

It was one of those once every few year things, but a lot of people were affected, including me and a bond trade I was in at the time. So I got a VPS near Chicago which was Sam’s and it has been great so far.

INTERVIEW WITH SAM OF SPEEDING TRADING SERVERS

Question 1  Most trading software runs on Windows, NinjaTrader, TT, etc. I myself am a Mac person, but I use Windows to trade. So I connect my mac to the VPS. Since I am believe you have explained this a lot, can you explain how traders connect to a VPS servers?

 The first step is maybe to define what is a VPS, and also explain why VPS is maybe not the most appropriate word. VPS means Virtual Private Server, but in our case, the good definition should be VPTW like Virtual Private Trading Workstation.


Virtual: the machine you access to is a virtual machine, hosted on a physical server (in two words this helps to reduce costs, for similar performances).


Private: you are the administrator of your machine, you can install the programs you want, add some fixes yourself, reboot, … The owner of the physical server, where this machine is hosted, can’t see your files, or what you’re doing, it’s your private machine.


Server/Trading Workstation: “server” is commonly used for VPS because most of them are used as web or application servers, using Linux 99.9% of the time. In our case, it’s a server operating system (Windows 2008 R2), but the “server” functions are not used, and the VPS is acting as a remote workstation.


So, just to describe what is a VPS/VPTW, what I’m saying to non-technical guys, is to imagine this:

  •  you have a powerful PC, in a data center near the CME or the NYSE, with all your trading tools,
  •  your own PC (or Mac, iPad, tablet, …), in your own office (or in your car, boat, …), is connected to your remote PC (the VPS) with few hundreds/thousands miles keyboard/mouse/screen/printer/audio cables.

You move your mouse: the cursor on the VPS will move. You have an audio alert on your trading software, running on the VPS: you’ll hear the sound on your local PC.

Now, if the basic logic is simply getting “virtual cables”, we only need to get a software that will allow the creation of these cables.
The communication protocol used for this is named RDP (Remote Desktop Protocol): all the events (move the mouse, type on the keyboard, …) is sent/received using this network protocol.


The idea now is only to get a software able to do this, which is quite easy on Windows machines, as this program is already installed (usually in c:\Windows\System32). This is a standard program, created by Microsoft, the executable is mstsc.exe.

Now, the user execute this program, and have to enter few pieces of information:

  •  the name (or the IP address) of the remote machine, which is your VPS name
  •  a username and its password

This is not your PC username/password, their is no link between those two.
You can also change some options:

  •  display options: would you like to be on your VPS in full screen, do you want to use all your monitor, …
  •  will you allow copy/paste between your PC and the VPS ? It’s very useful, you can also transfer files from your PC to the VPS with a simple copy/paste
  •  will the VPS sound have to play your own PC ?

Once this is done, click on connect, and you will see your VPS screen(s), just like it was your own PC.

Question 2 What is your favorite RDP client ? Have you seen a major difference in speed or performance from different clients? How is using RDP over multiple screens ?

The question might be “favorite RDP client for each architecture”  .;).


For Windows based client, the official Microsoft client (mstsc) works fine, no need to look somewhere else.


For Mac, cord is pretty cool (http://cord.sourceforge.net/), so are 2X products (http://www.2x.com/rdp-client/windows-linux-mac/downloadlinks/). But for my own needs, I’m still using the official Microsoft client (http://www.microsoft.com/mac/remote-desktop-client).


For Android and iPad/iPhone devices, I’m now using the 2X client (http://www.2x.com/rdp-client/android/ and http://www.2x.com/rdp-client/ipad-iphone-ios/).  Some other Apple/Android clients are also good, but this one is the most stable.

On Linux, I use xfeerdp, but rdesktop is also a good choice.

The RDP protocol is already very optimized, I never found any performances differences between them, only more functions, or more stability.

For multiple screens, I only used it with from Windows or Linux, nothing special on this side, it works…


Question 3 Can you talk about WHERE you should have your VPS. For example, I trade on Eurex sometimes but my broker is in Chicago, so even if I have a VPS in Europe, my trades would still have to make the round trip to Chicago.

Good question!


The broker’s location is not the key point, it’s the location of its servers. Most brokers’s servers are located near the main exchanges, and your trading platform will be connected to the nearest servers. This is not true for Interactive Brokers, and maybe Tradestation (hard to get the truth here…), as IB is only in New-Jersey (and have dedicated servers in Europe/Asia).


Question 4  From what you have seen, what trading software uses the most RAM? NinjaTrader ? TWS ? CT4 ?

Whatever the software, this is not the key point. The key point is the number of charts open, how many bars are loaded, what kind of indicators are used, …
I didn’t find any big differences between each major trading software, MultiCharts seems to eat a bit more memory than NinjaTrader for examples. Same story for IB TWS, which can quickly eat a lot of memory when a lot of instruments are loaded.

Question 5   How can I tell if a VPS is ‘oversold’? I had tried a ‘Virtuozzo’ server and it was the slowest thing I had ever seen, the CPU was just slow.

That’s also a good question, you can’t know how oversold is your VPS, if it’s oversold. You’ll have a clue, if you have some erratic performances, or just bad performances… Another clue will be the price: if it’s too cheap, do not expect too much…

Question 6  What are some advantages for discretionary traders like me to run trade on a VPS ?

I see few things:

  •  security: your PC is “clean”, no extra or useless softwares, only trading related programs,
  •   reliability: the hardware used are enterprise grade servers, using Raid technologies, redundant power supply, ECC memory, Xeon processors, … All this makes these servers much more reliable than a standard PC.
  •   network: this is maybe the key point. The bandwidth is much higher than from any cable or DSL connection, as we have 1000 mb/s connection, which is 50 times faster than most good DSL connections. More important than the bandwidth itself, the latency is much lower than using a basic Internet connection, and is also much stable. I have few examples of round-turn in less than 16ms (which is the minimum which can be measured by a Windows machine). Most data feed gateway servers are 1ms from our VPS, vs 130ms for European users, 300ms for Asia, …, between their PC and the market gateways. Of course, these low latencies are helping to get better fills, when the entry/exit orders are managed on the VPS itself.

 

Question 7  Finally, what is the most common question you get about using a VPS for trading ?

The main question is “How do I change my Windows password on the VPS”. The information is easy to find in our FAQ, but it seems it’s not so popular ;).  The other question is “How can I transfer my files (indicators, strategies, templates, …) to the VPS”. It’s a simple copy/paste, between your own computer and the VPS.


QUESTIONS

If you have any questions or are interested in learning more, post them over at CandleWerks. This is a longer post and I did cut out a lot to get the size down. I try to keep my posts under a thousand words.


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

 


Realtime Logging of Trades in NinjaTrader using MongoDb

REALTIME LOGGING OF TRADES IN NINJATRADER & MONGODB

After last weeks Knight Capital’s blowup, I decided to take a look at logging trade data and getting real time updates about trades and positions. Something that could track the performance of a bunch of algos in as near as real time as possible.

I wanted to see if I could connect to a database  in a way that would not slow down Ninjatrader and could be used to collect data form multiple strategies that are running at the same time so you can get a ‘world’ view of what is going on.

 

KNIGHT CAPITAL, ALGO’s GONE WILD
Last week in the space of less than an hour, Knight Capital lost $440 million dollars. About $10 million a minute. They were trading using algos on 140 stocks on the NYSE exchange. These

I would think that Knight had such a logger to know their, but apparently not. No one knows what really happened right now, so we can only speculate what happened. I speculate that they just rushed their software out without fully testing it an came away with a very expensive bug in their software.

MONGODB

I decided to use MongoDb for a couple of reasons. The first is that I have been using MongoDb in production since 2011 ( Hey, that is a long time in internet years ) I was a big fan of MySQL until Sun bought them, and then I started using MariaDB. Both of MySQL and MariaDB are SQL databases but for high speed logging, MongoDB is better for trading applications. MongoDb is a NoSQL database. It is different in a regular SQL database in a few ways I won’t go into. You can read them here.

What MongoDb does do very well is logging. MongoDb is fast and light to start with in addition to some of the things it can do .

For logging financial data, the thing that is most useful in my opinion is that MongoDB inserts can be done asynchronously. Not slowing down a trading strategy to log data is very important. You send the data to MongoDB and forget about it. MongoDb is also very good at writing to a database as compared tom ost databases are very good at reading, and somewhat slower at reading.

ADDING MONGODB TO NINJATRADER

Algorithmic trading programs are called ‘Strategies’ in NinjaTrader and are written in C#.  MongoDb itself is written in C, but has a  C# driver we can use to interface to MongoDB. I am using MongoDb 2.2 which has some new aggregation features.

Added a call in OnExectuion to call a helper function I wrote in C#. It connects to MongoDb automatically. One thing about the drive to note is that you do not need to dis connect because it uses connection pooling to connect to the server.

 

protected override void OnExecution(IExecution execution)
{
    twlinkmongo.log_ececution(execution) ;
}

 

The function handles the connection to the server and creates a bson document and inserts it into the database. I insert the doc into three collections ( a permanent log, TTL collection, and a capped collection )

BsonDocument trade = new BsonDocument {
    { "instrument", execution.Instrument.FullName },
    { "quantity", execution.Quantity },
    { "delta", delta },
    { "time", execution.Time },
    { "execution_id", execution.ExecutionId }
};

 

GETTING REPORTS OUT OF MONGODB

Now that we have the data in Mongo, we need to get it out. MongoDb has a command line interface, and since I am a Linux command line kind of person, I am perfectly happy with that. MongoDB interactive shell is a JavaScript shell that allows you to issue commands to MongoDB from the command line.

To get the data out of MongoDb, I wrote small javascript apps to loop and display to the command line interface.

SHOWING PNL OF LAST 100 TRADES

This is using the capped collection I set up for trades. I capped the collection at 100 items and it acts like a ring buffer trowing away the oldest trade. In a capped collection of 100 trades, when a new trade is sent to the db to be logged, the oldest entry is thrown away to make room for the new entry.

 

db.createCollection("trades_100", {capped:true, size:100000, max:100});

 

SHOWING PNL OF AN ASSET AMONG DIFFERENT ALGOS RUNNING ON DIFFERENT SERVERS

This is where I think this approach shines. If you have several strategies that all trade the ES futures contract, but are running on different servers.thi can aggregate all the trade information in once place realtime. Using the group function from Mongo to pull out the trades you want.

db.trades.aggregate(
    { $group : {
        _id : "$instrument",
        current_pnl: { $sum : "$delta" }
    }}
);

This is using the new Aggregation framework in MongoDb 2.2.

SHOWING PNL OF THE MOST RECENT 30 MINUTES

This is another way of looking at the trades. By using a “time to live” collection, we can see how things are doing when the trades become slower, such as the middle of the day. Think of this as looking at your trades on a rolling 30 minute window.

The mechanics are the same, we just set the expiration time on the collection.

 

db.trades_30min.events.ensureIndex( { "time":1 },
    { expireAfterSeconds: 1800} )

 

The trades are expired after 30 minutes, but the expire process runs once a minute. It is not ‘exactly’ the most recent 30 minutes give or take 30 minutes.

QUESTIONS

If you have any questions or are interested in learning more, post them over at CandleWerks. This is a longer post and I did cut out a lot to get the size down. I try to keep my posts under a thousand words.


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

Making NinjaTrader Charts Look Like Bloomberg Charts

I LOVE BLOOMBERG CHARTS

I have always loved the Bloomberg chart style that looks like a shaded mountain. For longer term charts, like daily stocks or cash charting. For intraday, I am still a candlestick person.

I think you do lose some information by using a mountain style chart instead of a candlestick, but you also gain some clarity. You get an idea of where a stock is headed. When you are ready to trade, you probably want to take a look at the candlestick or OHLC chart.


 

NINJA MOUNTAIN CHART STYLE

This was written by Joydeep in Ninjatrader support ( or at least uploaded by him ) so I want to give credit. This was released a few months ago and I really don’t know why it hasn’t caught on.

I really hope they make this a chart style pre installed on Ninjatrader 8.

 

INSTALLING

So here is how to use and install the chartstyle in four easy steps. If you have any problems or questions you can ask over at CandleWerks.com my question and answer site.

STEP 1 First, download the zip file from here NinjaTrader Mountain Chart Style. ( This is also availiable on the Ninjatrader site )

STEP 2  Import into Injatrader. From  inside Ninjatrader import the file you just downloaded.

File -> Utilities -> Import NinjaScript

 

 

 

 

 

 

 

 

 

You will probably get a warning message which is normal, just click ‘OK’.

STEP 3 Restart Ninjatrader ( You have to restart for Ninjatrader to pick up the new chart style )

STEP 4 Apply to a chart

In an open chart select the Data Series and in the parameter box and Chart Style as Mountain

 

STEP 5 Enjoy !

 

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

 


Good to see you! If you are new here, you can subscribe to the RSS feed for updates


Sync your PC’s Clock with NinjaTrader for Better Charts

the_desert_clockWHY DO MY CHARTS LOOK DIFFERENT

I am sure you have noticed this, but when you reload a chart in NinjaTrader, the chart will look different than it did before you reloaded that chart.

The reason is that NinjaTrader timestamps for each bar work as END OF BAR timestamps. That is to say the timestamps used to make the bars are based on your PC’s LOCAL time  when drawing those bars.

So, say you have a 5 min bart chart and the first minute of the day is 9:30:00 to 9:34:59. That is where the first bar will be drawn and the size of the bar will be the prices that traded between  9:30:00 to 9:34:59.

You should sync your PC clock before you open NinjaTrader. It will help you keep your charts synced better, and it is better for your trading in general. Here is an example of what happens when you clock is slightly off.

Now, let’s say your local clock was fast by 10 seconds. When NinjaTrader thought it was 9:30:00, it was actually 9:29:50.When you reload your charts historical data, NinjaTrader will re-download that data with new timestamps. so instead of the first bar at 9:29:50 to 9:34:49, it will show the actual bar at 9:30:00 to 9:34:59.

This is in general because all data providers are not the same, as I will address in the next section.

NOT ALL DATA IS THE SAME

When using Interactive Brokers, you will have timestamps all done locally by your PC clock. Interactive Broker will send all its data without timestamps and then the  Interactive Brokers adapter inside NinjaTrader will time stamp the data set by your  local by your PC clock.

If you want data that is natively timestamped you can try eSignal, DTNIQ, BarChart. If you are doing any kind of scalping or higher frequency trading, I would recommend that you stay away from Interactive Brokers in the first place.

WHAT THE HECK IS NTP AND WHY DO I NEED IT ?

In use since before 1985, the Network Time Protocol (NTP) is one of the oldest Internet protocols in use and is a networking protocol for synchronizing the clocks of computers .First you might want to take a look at my post on on why you need to get your computers clock in sync. NTP can usually maintain time to within 10 milliseconds (1/100 of a second) with the time server which is usually synced to an atomic clock in some underground bunker I assume. The way NTP calculates the time is an algo written 20 years ago by Keith Marzullo . All of that is not important, just assume it happens auto magically.

AUTOMAGICALLY SYNCING

Windows has a built in NTP client. Microsoft does not call it that naturally, it is called Windows Time service (W32Time) which is a good thing because it is slightly brain dead. The problem is that the Windows client syncs your time once a week. Good enough for government work, but I would like to sync my time every time the machine starts. http://www.thinkman.com/dimension4/ 

UPDATE: To answer a readers question, this is not my software, it is free software from another site. I hove now connection with them.

WINDOWS SUCKS

Windows Time Service cannot sync the system time closer than about a 1-2 second range.

The W32Time service cannot reliably maintain sync time to the range of 1 to 2 seconds. Such tolerances are outside the design specification of the W32Time service.

From the Microsoft website : “We do not guarantee and we do not support the accuracy of the W32Time service between nodes on a network. The W32Time service is not a full-featured NTP solution that meets time-sensitive application needs.” You can have a read here Support boundary to configure the Windows Time service for high accuracy environments

HISTORICAL DATA

Everything is timestamped by YOUR PC clock and YOUR current timezone. You need to sync the PC clock to ensure the timestamping from your PC comes out the same as IBs. You then should reload historical data to fix any issues you have had with previous bars when you were not in sync.

You need to ensure your PC clock is synced and then you can also just right click on your chart and select “Reload Historical Data” which will repopulate your data with the historical set IB provides.

WINDOWS SUCKS

I just had to throw that last line in there.

Tip of the hat to ToniVC for the picture

NinjaTrader & Futures Contract Rollover. How Not to Lose Money Trading the Rollover

USF 1951 Dream Team

MARCH ROLLOVER HERE AGAIN

March is on us again and another quarterly rollover is here.

    This four time a year ritual happens when the trading switches from one contract to the next. The rollover date is different from the time when the contract expires. Think of it as the date when everybody changes contracts because everyone else changes contracts.

By not trading the correct contract, this can cost you money since you will be trading the wrong contract. We ( and by we, I mean the average trader ) need to trade the contract with the most volume, and that contract changes around rollover, but not the way it did when the pit ruled everything.

THE PIT IS DYING

The traditional rollover is when the contract traded on the top step of the trading pit at the Chicago Mercantile Exchange changes. The trading ‘pit’ is shaped like a , pit. It is an eight sided shape that is lower on the inside like a pit. The nearest contracts are traded on the ‘top step’ and all the other contracts are traded on the inside of the pit.

The old rollover rules occurred because that is when the volume in the open outcry pits rollover. I am sad to say the pit has been dying for some time thanks to Globex. Such is life. At one time, there were open outcry pits in London and Hong Kong that are long gone. We should look to when the volume REALLY changes from a contract to know which contract to trade.

    I have some  friends who are former pit traders and the pit dying is hard for them. It was a way of trading and a way of life that eventually gave us screen trading as we know it. If you want to know more about pit trading, take a look at the Trading Pit History website.

ROLLOVER HAS CHANGED

Futures contracts rollover is a concept harking back to pits.The old rules of rollover

  • Rollover is 8 days before expiration.
  • Expiration is the third Friday of each quarter month (March, June, September, December)
  • Volume shifts to the new contract at market open (09:30 EST) on Rollover day
  • Rollover is usually on the second Thursday of the month but will be on the first Thursday if the first day of the month falls on a Friday

These rules used to work well, but as more and more volume has gone to Globex , while less and less volume has gone to the pit, these rules don’t hold as much weight as they used to in the past. We need to trade the contract with the most volume.

NEW RULE FOR ROLLOVER

New rule of rollover

  • Trade the contract with the most volume.

 

Pretty simple. Most contracts have their own character and rollover now. You could take a look at each contract and see how things like first notice affects rollover and a myriad of things. But the best way it to look at the volume and trade the most popular contract.

There are a couple of ways to do this , but the easiest way it to bring up two Time & Sales windows and simply trade the contract with the most volume.

NINJATRADER & ROLLOVER

NinjaTrader will have a popup reminding you to rollover your contracts. For some contracts this may be a good idea, for others, it may not be and that could cost you money. It you follow the set rules, you may roll early and be trading a choppy contract.

According to Cameron over at NinjaTrader, their development team is aware of certain contracts holding more volume than the currently defined roll over dates, and are looking into a solution.

The one thing you can do is you can manually set the rollover date in the Instrument manager.

CHANGING ROLL OVER DATE IN NINJATRADER

 

From the Control Center -> Tools -> Instrument Manager

Search for the instrument

Select and press ‘Edit’

Press the ‘Misc’ tab

Scroll to the bottom and select ‘Contract months’ field

Press the ‘…’ button

 

Select the Month-Year combo to see the Rollover date and change if you wish.


Photo Courtesy San Francisco Foghorn

CC Licensed


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

 


Good to see you! If you are new here, you can subscribe to the RSS feed for updates


Finally… How to Get The Size Of Your Account Inside Of A NinjaTrader Strategy

FINALLY

I have been using this for a while, since the early NinjaTrader 7 betas, which seems like forever ago  and it has been very useful. Mainly used in risk management, which is usually overlooked by many.

Knowing the account size is very , very helpful for writing code for risk management. Risk management is so important in strategies that most of MY strategies have most of the code in risk management, not entries or exits. Developers really need to spend more time getting the risk management part of the code perfect.

THE OLD WAY

When I USED to do custom programming ( I have no time ) , what I would do would be to keep the starting value of the account and then use the running profit to calculate what the current value of the account was during the trading session.

Painful and convuluted, but it worked. It did have a couple of problems. Well, big problems. The first was that you have to input the starting account value at the start of the session. The second is when you are trading more than one automated system in your account. You are keeping the running total for THAT strategy only and you have no idea of what the other strategies are  doing.

FIXED FRACTIONAL PRICING EXAMPLE

As an example, say you only want to risk 2% of your trade on an a trade. That is fixed fractional risk management which is very popular. You have a $20,000 account,  are trading two strategies and you want to trade one contract per $5,000.

The old way, Say strategy #1 had lost $10,000. Strategy #1 will know about the loss and start trading 2 contracts instead of the previous 4 contracts. Strategy #2 should start to trade 2 contracts BUT it doesn’t know about the loss so it will continue to trade 4 contracts. This was typical using NinjaTrader 6.5, which frankly sucked.

TRADE SIZE

I think the biggest thing is that is helps position sizing and here are some code snippets to help get you started. Tons of people recommend you only risk a certain percentage of capital on each trade and the following code shows you how to do that.. You can use this to set trade size or the amount you risk by setting the stop loss.

Say you want to enter a trade one contract for every $5,000 in cash you have.

position_size = (int) GetAccountValue(AccountItem.CashValue)) / 5000 ;

Or you could calculate the max risk by calculating 2% of your cash.

max_risk = GetAccountValue(AccountItem.CashValue)) * 0.02 ;

Now, please note that futures and equities work differently in the amounts reported.
GET ACCOUNT VALUE

The function that does all the work is the GetAccountValue call. There are a couple of things to notice about this call. The first is that it will return 0 for historical data and that it returns the information on the account that the strategy is running on at the time. The other is that there are more items in Cbi.AccountItem then just the cash value, so you should explore those.

public double GetAccountValue(Cbi.AccountItem accountItem)

PUTTING IT ALL TOGETHER

So let us make a simple example. We will trade 10 contracts when backtesting, one contract per $5,000 running real time or replay.

protected override void OnBarUpdate()
{
    if (Historical)
    {
        contracts_to_trade = 10 ; // trade 10 historically
    }
    else
    {
        if (GetAccountValue(AccountItem.CashValue) > 5000)
        {
            contracts_to_trade = (int) GetAccountValue(AccountItem.CashValue)) / 5000 ;
        }
    }
}


GetAccountValue() doesn’t require very much computing power so you can call it fairly often.

NOTE

The ability  or inability for these functions to work depend on the information provided by the broker to NinjaTrader. So you should test using your brokers connection.

If you have any questions, just leave a comment.


Photo Courtesy John Althouse Cohen


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

 


Good to see you! If you are new here, you can subscribe to the RSS feed for updates


Writing Passive Relative Orders in NinjaTrader Strategies ( PASSV REL )

INTERACTIVE BROKERS PASS REL ORDERS

I was chatting with a friend that was trying to write passive relative orders in Ninja Trader that he had used in Interactive Brokers TWS.

Since you know I have no love for interactive brokers, I thought I would give him a hand.Besides, I have not written a coding post for the blog in a while.

 

If you want to find out how I feel about Interactive Brokers, just use the search bar over there.

Regardless, Interactive Brokers ( From now on, I will just type IB instead of Interactive Brokers because it is getting way to tiring to write the whole thing ) has a pretty good selection of orders, one of them being a Passive relative order (PASSV REL )

WHAT IS A PASSIVE RELATIVE ORDER ?

Lets start by looking at the IB website.

Passive Relative orders provide a means for traders to seek a less aggressive price than the National Best Bid and Offer (NBBO) while keeping the order pegged to the best bid (for a buy) or ask (for a sell). The  order price is automatically adjusted as the markets move to keep the order less aggressive

 

What is is in reality is an attempt to get a better price. Putting in an order away from the market hoping the market will come back and get you into the trade at a better price.

Stocks, futures and options ( and other things , but you get the idea) move up and down all the time. A passive relative order is an order that sits relative to the bid / ask and waits for the price to come back and get filled.

The difference between this and a limit order is that limit price will move relative to the bid/ask price. So here is an example of this type of order.

 

I won’t go into detail here, but there is a really good explanation on the IB website.

THE CODE

This PSEUDO code below is for Ninjatrader strategies. I think the closest you have in the ATM strategies is the ATM strategy. The code is a little advanced so you will have to bear with me on this one. If you are just a beginner at Ninja script, I would leave  this type of programming alone.

I went with PSEUDO code because if you are advanced enough write this, you probably would not have a problem writing the C# code yourself. I was going to release code, but I thought that would be to confusing. If there is enough interest, I will release it. So leave a comment and if enough people want it I will release the NinjaTrader code.

 

The first thing you will need is the order object and the bid / ask prices.

double offset_price ;
double max_price ;
bool entry_direction ;
double current_limit_price ;

...

We need to keep the entry direction since passive relative orders act with the direction.

The next part is in OnOrderUpdate(), remember to check for the IOrder.Token.

OnOrderUpdate()
{
  // wait until order comes back confirmed,and store the value.
if ( order completed ) current_limit_price = order price 

}
OnMarketData {

    ...
    double mid_point = ( GetCurrentBid() + GetCurrentAsk() ) / 2 ;
  // if the price is at max price do not move
  if ( current_limit_price gt max_price ) return
   // now if price is to far away, move the limit order
   if ( difference (mid_price , current_limit_price ) > offset_price )
      cancel order
     enter_new_order(mid_price , current_limit_price)
    ...
}

Most , well all , of the heavy lifting will be done in the OnMarketData and OnOrderUpdate. You cannot do this using on bar update.
 
I have just touched on the subject, if you would like me to write more , leave a comment so I know other people are interested.
 

A LITTLE WARNING


Programming this stuff is considered advanced programming and is for experienced programmers. Don’t blame me if something goes wrong.

Using this type of order can and will generate a lot of cancel order messages as the limit order is moved.

For futures there are message limits that can lead to a fine and in options there are usually cancel fees from the exchange. Of course your broker may add something on also, so you mileage will vary.

And finally, using a lot of cancel and replace orders , you may run into ‘in-flight’ order problems. Which are usually not nice.


Photo by szeke



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


Good to see you! If you are new here, you can subscribe to the RSS feed for updates

10 Websites For Traders

Here is my list of sites I go to for trading information. You won’t see any forums here except one. I have dropped out of forums for the most part. There are just too many trolls on boards.

I recently went back to EliteTrade and could not take more that a few pages of rude posts. ( You will not see EliteTrader on this list. ) In the early 2000’s  it was the place to go, and there are a lot of good threads if you can find some of the good threads. Today , it is mainly junk.

 

NEWS SITES

Barrons Econoday
http://online.barrons.com/public/page/barrons_econoday.html

Bloomberg – Business & Financial News, Breaking News Headlines
http://www.bloomberg.com/

 

INFORMATIONAL SITES

TradingNaked –
http://www.trading-naked.com/

This is a suprisingly good website with a supringsly bad design. There are a lot of good information and trade setups. It is a great site if you are starting out and a nice read if you are not. I do wish he would update his site.

The Long Room / FT Alphaville
http://discussions.ft.com/longroom

 

BLOGS

TradeWithTheFlow
http://www.tradewiththeflow.com/

This is one of the few blogs I read. Actually, it is the only trading blog I read. I have chatted a few times with the author of the site a few years back. I don’t trade the same way as he does, but I do like reading about his trading as he is one of the few places that posts trading results. ( That are selling some system )

 

FORUMS

Big Mike Trading Forum
http://www.bigmiketrading.com/

Big Mike’s is the only forum I really participate in or visit regularly. The site owner Big Mike is pretty good at keeping the rudeness level down and the trolls out.

Nuclearphynance

http://www.nuclearphynance.com/

A great site, however, I must warn you that is is low volume AND geeky. I don’t visit as ofter as I visit Big Mikes forum.

OTHER

TED

http://www.ted.com
TED is a small nonprofit devoted to Ideas Worth Spreading. It started out (in 1984) as a conference bringing together people from three worlds: Technology, Entertainment, Design.

 

The CME Group – The ‘Merc’
http://www.cmegroup.com/

 

Eurex

http://www.eurexchange.com/


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 curtesy of Andre Weason

A Talk with Big Mike from Big Mike’s Forum


BIG MIKE’S TRADING FORUM


Big Mike’s Trading Forum is a great place to hang out and discuss trading. I have been following Big Mike since he was on the Ninja forum as ctrlbrk. He has always been a very helpful guy. He was nice enough to answer a few of my questions as his forum is coming up on his second anniversary even with a broken hand.

This is a great interview and well worth a read. Interview posts are not very popular on my blog, but they are much more informative and useful if you want to make a living from trading , it would be good to listen to those who have been around for a while like Big Mike.

 

So after reading this post, head on over to Big Mike Trading, a great forum for traders and some of the things he has planned for the second anniversary.


  • Memorial Day charity drive: All Elite subscriptions get donated to charity
  • Battle of the Bots: June Winner gets Algo Trading book from Amazon
  • Teaching contest: Win an iPad 2 for the best thread teaching a methodology (follow-up to our iPad 2 journal contest)
  • Velocity Futures Webinar: Giving away two cent commissions for an entire month to two people
  • Suri Duddella Webinar: Chart pattern expert, giving away 10 autographed copies of his book
  • MultiCharts Webinar: Platform overview, new features, giving away two lifetime licenses and two sets of two hours each programming time for custom indicators or strategies
  • NinjaTrader Webinar: Platform overview, new features, giving away two round trip tickets from anywhere in the world to Las Vegas for November 2011 Trade Expo, plus one two year subscription to NT
  • Al Brooks Webinar: New price action books, price action trading: giving away 10 autographed copies of his book

AND NOW THE INTERVIEW

[1] One of my big things is journaling. I even print out my journals at the end of the month. When I go back over them months later I learn so much about my trading. I know you are a big fan of journals also. My question is, why do you think it is so hard from some people to do journals?

“Journals are probably the single best tool a trader can have.  Yet most traders throw it out the window and think they don’t need a journal.  Well, most traders fail.  So do the math…  I think people come up with a list of excuses that they don’t need to journal, but the single biggest one can probably be simplified into lack of determination to see it through.  Another common one is simply the “lack of time” excuse.  To me this says the trader is overtrading and it would take them hours to journal about all the trades.

Individual traders are not computers.  Let the computers do high frequency trading.  You should focus on just a small number of setups each day, maybe 3-5 trades at most.  Anyone should be able to write down why they entered and exited a trade three times a day, no excuses.”

[2] Somewhat related to the previous question, in that you have to be honest with yourself to improve. Why do you think people are not honest with them selves in their trading. Almost as if they see what they want to see.

“It’s not that people intentionally deceive themselves.  I don’t believe that.  What I’ve found through my own experiences and through the forum is that traders get caught up in something and can’t see the forest for the trees.  I refer to it as the black hole phenomenon, where the trader gets sucked into this vicious cycle of repeating the same mistakes over and over.  But the trader can’t escape.  In order to deal with this, the mind plays tricks and invents all sorts of reasons that a trade failed or that the trader lost money.

I’ve got news for you, if you don’t accept full and complete responsibility for every action, beginning to end, having to do with your trading – you will never succeed.  Don’t blame your computer if it is slow.  Don’t blame your internet connection for dropping out.  Don’t blame your platform for crashing.  Don’t blame Goldman Sachs for running your stop.  And worst of all, don’t play the “if only” game with your indicators.  If only you had… <insert 42 excuses here>.  It’s all you.  Own it.  Take responsibility.  If your computer sucks, your internet connection is flaky, and  your platform crashes routinely, then you shouldn’t be trading until you resolve all of those issues.

Once a trader finally comes to terms with the fact they are solely responsible for their own trading success or failure, it can be an eye-opening experience.  On the one hand, you can finally move past all the junk that gets in the way psychologically holding you back, and face it head on and deal with it.  But on the other hand, you finally realize you have only yourself to blame.  It’s crunch time.”

[3] We all start out somewhere trying to be full time traders. Do you have any advice for someone who is marginally profitable part time to make the jump to full time ?

“If you are marginally profitable, my first question is over what time period and how many trades?  I would be cautious if the term is less than 1 year and the frequency of trades is less than say 500.  Don’t get cocky and think because you had two good trades in a row that you’ve got this trading thing licked.  Trading success is incremental.  There are many things you must master, all individually, in order to finally put all the pieces together.  You can’t skip over the hard parts, there are no short cuts.  There is no indicator or trading system to download that will make you money.

My advice begins with “congratulations!”.  Even marginally profitable is considered a success in terms of the larger group of traders.  Build on it, slowly.  One of the most common mistakes traders make is allowing their ego of always wanting to be right to get in the way of a trade decision.  That often leads to giving back days, weeks, months or even years worth of profit in just a handful of terribly executed trades.  So go slow, don’t get cocky, and make sure you have some meaningful analytics in place to measure your success.”

[4] I have been trading the same basic system for the  last few years. It has evolved over time, but it is basically the same. I run into others who constantly want to radically change their system even when they have a perfectly workably system, one bad day of trading and they throw the system  out and start their search again? What are your thoughts?

“Congrats!  That’s awesome that you’ve been trading the same basic system for this length of time.  I constantly tell people to stop changing everything.  People rush to change indicators, tweak settings, or download the newest craze system in order to solve an underlying problem with their own trading psychology.  They want more filters, they want to stay out of chop.  Basically, they want the holy grail.

If you have been trading for 3 years but you’ve changed your method every few weeks, then you don’t have three years of experience but rather only a few weeks experience.  I strongly believe that success is determined by your ability to read the market, and not by your ability to follow a blue-to-red trading system or indicator.  You don’t stand a chance of properly reading the market if you are constantly changing your charts and indicators.”

[5] In trading, I have found that best advice I have ever received has been free or inexpensive. I usually steer people who ask me questions to Reminiscences of a Stock Operator ( can be found free ) , the CME website, and Al Brooks book ( Soon to be in English ). Besides Big Mike Trading, of course , where else would you direct others ?

“I prefer reading Trading Psychology books.  Brett Steenbarger has several absolutely excellent books, and a blog online that is filled to the brim of real-world advice.  I don’t read books that describe methodologies very often.  If the book has lots of pictures of charts, then it is really of no interest to me.  Sure, I’m always eager to learn new things, but I want to incorporate it into my existing trading system and am not eager to make any kind of departure from what is working for me.

As for online resources, of course I think BMT is the place to be.  I don’t frequent any other trading related websites anymore since BMT has taken off.”

[6] How do you deal with the boredom of trading? That is sitting on your hands and waiting for a great trade. Is it something that came with experience for you?

“If trading is exciting, your probably losing money.  I don’t treat trading like gambling.  I go to Vegas to gamble, which means to have fun.  I trade in order to make a living.  I usually trade for about 2-3 hours per day.  During this time, I turn off my phone, TV, and I don’t browse the web.  I am looking solely at charts on all of my monitors and I work to get in rhythm with the market.

With my particular methodology, I know where I want to enter and exit a trade ahead of time.  So I place limit orders and don’t have to watch the market tick by tick in order to press the button to get into a trade.  I would suggest a similar approach to others, as watching every tick will just lead to over trading and second guessing of your original analysis.

That said, a huge number of traders have a problem over trading.  My suggestion to them is to make a promise to yourself that you will take only 3 trades a day, period.  So help me, if you take 4 trades….  I find that knowing this number ahead of time really helps to focus traders.  Of course if you make this promise with yourself, your best bet is to post about it in your journal on BMT so you get the extra accountability you need.  The mind is a powerful tool, be sure you are using it to your advantage :)”

[7] Finishing up, if you could give one and only one piece of advice to a trader, what would it be ?

“Be realistic with your expectations.  Too often, traders come into this business and think they can turn their $500 forex account into $5,000, or they can turn their $20,000 futures account into a steady $75,000/yr income.  You cannot.  Those kinds of returns are outlandish.  Just because some guy on a website selling you his secret method says you can do it doesn’t mean you actually can.  Be realistic.  Realistically speaking, you will probably spend $20,000 to $50,000 the first two years you trade.  I say “spend”, not “lose”, because I look at this period as your tuition and its an educational expense.  Hopefully your third year you can earn a 10-20% return or so.  By your fifth year, maybe you can get to your $75,000/yr income figure with a modestly sized account.  A common number thrown around is 10,000 hours – you need 10,000 hours before you start to “get it”.

Expanding on the above – make sure you treat trading as a business.  If you are serious about being a full-time trader, then act like it.  This means no interruptions while you are working.  No wife and kids coming into your office every hour.  No surfing the web, watching TV, sleeping in, staying up late, etc.  If you don’t respect yourself enough to treat your trading business seriously, then you won’t succeed.  After you “make it” in trading, you’ll find your life will open up and you can do the things you’ve dreamed about without them interfering with your work, because you’ll likely only be working 2-3 hours a day.  But during your tuition period, you can expect to work 12 hour days routinely.

TW, it’s been a pleasure answering your questions today.  I look forward to seeing you, and your readers, on BMT!

Big Mike”

 

 

Good to see you! If you are new here, you can subscribe to the RSS feed for updates