Thursday, August 28, 2008

Tipster Trendlines

This page is out of date, click "Tipster Trendlines" at the top of the page.





The "free" version is no longer available. Go to the Tipster Trendlines 2.1 post for additional information.Trading from the chart - what a concept!


AFL code to trade from your Amibroker Chart


I've had many emails asking me for the code that I use to trade stocks from the Amibroker chart as seen in this chart trading example video post. I've decided to release the code since that is the spirit of the Internet I enjoy most. I was using separate files but to make this easier I've rolled them up, now there are only two files. Before you grab the files, please watch the quick video.



Make sure you test this yourself, all types of trades, Long, Short, at MKT, at LMT, at STP. And always make sure you double check the order entry in TWS before your transmit the order. I take NO responsibility if your a hammerhead and don't check your orders before you send transmit to the exchange.

  • MessagePanelInclude.afl - put this file in your default include directory. This is usually /Amibroker/Include/
  • TipsterTrendlines.afl - put this in your "custom" folder, or where ever you like, it will work from anywhere.
Click on the file names above, when the window open press "CNTL-A" to select all, then "CNTRL-C" to copy. Paste the code into a text editor like "Notepad" and save with an "afl" extension.
(BTW, donation button is on the right)
What it will do and won't do
  • Use this code to place bracket orders with trend lines drawn right on the Amibroker chart.
  • It does NOT allow you to use Amibroker to sell or cover, only place bracket orders.
  • Lines should be called BS - Buy or Short, TA - Target, ST - Stop (case insensitive)
  • Once you place the order and transmit, you need to manually adjust the target and stop inside TWS, the code does NOT do this for you once your order is placed.
  • You must have Amibroker 5.0 or above for the coloured bar to appear at the top of the chart.
Installation
  • Put the file "MessagePanelInclude.afl" in your include directory.
  • Put the file "TipsterTrendlines.afl" in your custom directory
  • Right click on the TipsterTrendlines" in the "Charts" sidebar and click "Insert" or "Insert Linked"
  • You can run "Debugview" to see what the program is transmitting to TWS. Debugview is in your windows directory.
  • You need to install IBController for Amibroker to communicate with TWS, it's available on the Amibroker website.
  • Make sure you set up TWS API interface under "global" config, and set trusted IP to 127.0.0.1
Potential Issues
  • This code uses GetChartID and therefore might give you odd results if you open another chart with the same code and place trend lines with the same labels (BS, ST, TA). It might place an order for the wrong symbol, I have not tested this. To get around this either consider using the actual chart ID (available in the parameters window)
  • There is no code to keep from placing multiple orders. If you hit "Buy" twice, you will place two orders, so be careful.
  • The code also does not check for waiting or pending orders.
  • This code works for stocks only, or other instruments with 2 decimal places. Forex uses 4 decimal places, so if you try Forex, you order is rounded, therefore do not use with Forex.
Improvements
  • In the future I may add additional functionality such as that listed above. If you have improvements on the code please let me know about the improvements.
  • Check for pending or waiting order to prevent multiple orders from being transmitted
  • Make display bar used as buttons (transmit, auto-trade on off, Long, Short, Close, Reverse, Cancel Order
  • Drop down menus can also be added And lastly, if you like the code, please post a comment to this post.

Monday, August 25, 2008

Stock data from Yahoo

Here is a sample of data that is retrieved from Yahoo! for MDCO, on the Nasdaq. This is the data source that I use for the short interest scan.

Trading from the chart with Amibroker

I've had a few inquiries about the code for chart trading with Amibroker. I will be posting the code soon. Should be up in the next week or so.

Sunday, August 24, 2008

Weekly Nasdaq Scan

Keep an eye on these stocks as the week progresses. This scan includes the short interest ratio and the increase in shorts from the last reporting period. Short positions are reported bi-monthly, see the link on the right for more information, it takes you to the NASDAQ Short Interest page. As a stock reaches new highs the shorts will start to feel the pain and some are forced to cover for a variety of reason, including margin calls. This gives the upward move more fuel, try to ride the tide. Here is the spreadsheet for the Nasdaq SI Scan Aug 24 2008.
Compared to last week, there are allot fewer shorts that show up on this list, and the number of stocks that have increased in shorts are far less. Does that signal a turn around?


Wednesday, August 20, 2008

SDS Update

Here is an update to the SDS trade posted yesterday.

Monday, August 18, 2008

Another example of trading with trendlines

I thought I would take the "potential" set-up Brian Shannon spoke of in his video today to show the "Trading with Trendlines" code I have written for Amibroker, interfaced with Interactive Brokers TWS platform. Both the set-up video by Alphatrends and my own video are below.

Alphatrends



Trading with Trendlines

Poll

I've added a new poll on the right side of the blog, "Do you trade from work?" This assumes you have a regular day job. Please take the poll, I'll be doing a short video soon on trading from work.

Do you have a questions that would be appropriate for a poll, that would give you a better sense of what other trader are doing? Perhaps "do you use a moving average crossover as part of your trading system?" If you have any suggestions, I'd like to hear them.

Saturday, August 16, 2008

NASDAQ scan for upcoming week

This scan includes short interest as well. Watch the video for details. All the stocks are longs and all are on NASDAQ. You can also get the excel file for the NASDAQ Scan Aug16 2008.





Monday, August 11, 2008

A nice toy, just say it!

If you use the command "Say" in AFL, or some other kind of audio alerts, check this site out;
http://www.research.att.com/~ttsweb/tts/demo.php
This site lets you type in the text, listen to it, and download it. Easy and painless. You can select different voices as well. It sounds tons better than other text to speech engines I've heard, and it sure beats the basic voice Microsoft gives you (Amibroker uses the Microsoft engine when you call the "say" function, look it up in AFL help)

I use the "Lauren" voice to tell me all about the orders I submit, or if there are data errors, etc. Why stop there? You can use these sounds as part of your windows sounds scheme too.

So when you boot up your computer after dinner to plan the day for tomorrow, this is what you could hear.

video

Sunday, August 10, 2008

Software Applications for Trading

Here's what you need to interface between Amibroker and TWS to trade with trend lines and auto trade. I also do a scan of the TSX and update an earlier trade.

Scan of NASDAQ and short interest

Tonight I ran a scan of the NASDAQ looking for stocks that are in one of two categories, the same criteria used in the last video I posted. There is one addition, I have added the short interest to the output (not used in the filter, just displayed on the output)

1. 10 day MA > 20 day MA > 50 day MA and 50 day MA rising
2. 10 day MA < 20 day MA < 50 day MA and 50 day MA falling

Other filters are in there as well, simple things like today cannot be the highest high in the past 5 days, the 20 day avg volume has to be more than 200K, today cannot be the lowest low over the past 5 days. This is trying to catch a basic pull back, or a stock correcting over time in a range. Here is the link to the spreadsheet with the scan. In the video I explain the san results.


Saturday, August 9, 2008

Indicators

DAX, QQQQ, SPY, IWM, TSX Stocks, Forex, whatever you trade, price patterns and understanding why price moves is probably better than memorizing patterns. Take a look at a MACD divergence and a price chart that uses the same MA's as the MACD. Find a divergence. Look at the patterns of higher highs and lowers lows. Notice that you can see these if you look. I find the most use for indicators is to filter my scan results.

Here is an interesting concept that I have looked at, it comes from some forum somewhere. I believe it has merit.

Crossover systems will generally do well when traded intraday, not so good when traded of daily prices. By substituting different filters based on the most recent action of the chosen market, you can use their basic rules (idea) forever. You can program this to be self adjusting (auto optimize).

As part of my exploration scan for trending stocks, I use the double stochastic, it filters out stocks that aren't pulling back quite to where I would like to see. This is a good use for an indicator, not as sole selection criteria. Support and resistance, and a dose of anticipation.

Friday, August 8, 2008

Using Multiple Trading Systems

Some info I found while surfing. I don't use neaural nets but I can relate to using multiple systems to increase trading frequency. The system should be non-correlated. It's a good read.

First find out what is going on in the market you want to trade in the timeframe you plan on holding a position. If you want to day trade with one trade per-day then find out all the different ways the day has played out in the past. Ex. trend day, two-way day, reversal day, etc.

Once you've done this you should have an idea of which type of day is most common and which is most profitable. Then define something which could be of value to trade one of the market types. An example might be in a reversal day to find out how often the market makes a low of the day in the first 15 min. of the session. If it happens often enough to be of interest then you go on to the next step.

Take every period for which the target is found and create a table of outputs with 1 for the target and 0 for non-targets. Then pre-process all the inputs into the target and convert them to binary inputs. (A common mistake is to take open, high, low, and close data -- analog and assume you can find relationships with the target). For ex. yesterday close > day before yesterday close. If found mark the input as a 1 if not present mark it as a 0. Do this for as many identifies as you can. This may present a hundred or more binary inputs leading to the target for each day of the data.

Then you'd pass the data into a backprop neural net and have it train on the data. (You’ll need to set aside some data for out of sample testing). Once it's trained to hit at least 90% correctly test the NN on the out-of-sample data. If you hit at least 85% correctly then you can do one of two things. If you're a discretionary trader, setup the NN and pre-process the inputs every day and use the net to predict whether tomorrow has the target (in this example the low of the day is within 15 min. of the start of the session). If so use it to trade to the upside as long the net remains 85% correct. If you're a systems trader then go back to the net and look at the weights of the net to see which of the binary inputs were most important in hitting the target. Use the inputs to create a back testable system based on the patterns. A system might be when xyz pattern exists then buy next bar above the lowest bar as long as the time is within the first 15 min. of the day. Set the stop to one tick below the low.
If the system tests profitable enough to be of interest then move on to the next step.

Next, take the trades and test them against random trades pulled from the same year (the edge test). Rank the trades versus random for each year of the back test. If the trades score consistently above the 70th percentile then you can guess you've found an edge-based system. If not, then you have to assume you've found a temporal characteristic in the data that can be exploited for some period of time.

If its edge based then all you need to do is adjust the trades for market volatility and apply a money management strategy. Check the trades on a periodic basis to ensure the edge continues and plan what to do with your next million. If it's not edge based you can still trade it but you need to setup an objective bailout method such as running a monte carlo sim and determining the bailout point to be say the 95% level of the predicted max drawdown point. Your trading would be more defensive using a non-edge based method as well. Maybe you'd split the trade size in half and have a 15 min. or 10% of daily range as a filter to adding the second position (letting the position prove itself) as long as the volatility was large enough to justify the scaled entry.

Every model I've worked on has gone through the same process. Look at the behaviour’s present in a market; characterize them by creating a rule and checking the fit until all behaviour’s are noted. Then start looking to see if there is a component to the behaviour that is non-random. If so, develop a system to mine it and create a way to monitor the behaviour to ensure it's persistent over time. For example, one of the behaviour’s widely known is the trend day in the SP market. It can be identified just by visually inspecting a chart. I characterized it as a low/high within 10% of the low/high of the day and the close within 20% of the high/low of the day. With the definition I can see how many of these days have persisted over the years (averages about 25 day’s per-year). Then I can see if there is a way to identify these days in advance (realizing I'm going to also be capturing some false days as well).

The algorithm used to adjust the number of contracts traded to volatility is calculated by the range (high - low), then average it for the past ten days. I use ten because I want my model to cut back on size pretty quickly if the volatility jumps. Then I divide the highest historical 10 day volatility (approx. 48 pts.) by the current volatility (ex. 8 pts) to come up with a multiplier (ex. 6). The model would then apply 6 contracts for the next trade. This is not the final size used to trade. It's just used to adjust the model for volatility levels so I measure one period against another without volatility being a consideration.
By doing so, I can see if the same level of opportunities persist from period to period. I can also use these normalized trades to feed into money management models as well as Monte Carlo tests to estimate future performance and drawdowns. If you were to use trades from say 2000 and 2004 for the SP market in a Monte Carlo test without normalizing volatility you'd get a much distorted estimate of future performance.



Comment from reader:
Just to make sure I understand the big picture, this is all being done to increase frequency in the desired profitable time period, correct? So if I understand, sub-par models tested individually with low frequency can be morphed into an above-par model when combined with other non-correlated sub-par models (assuming they're not too sub-par), thus increasing frequency, consistency, and lowering the need for a higher profit factor? Thank you for presenting the information the way you did, I would not have made that connection otherwise (assuming I’m on the right track). Fascinating.

Trading System Development

Trading system development – The DUM method

D - Define

All systems are based on finding and pulling a fundamental truth about the market. Define what fundamental truth you'll be going after. Eg. All markets have a tendency to trend beyond random. Now you've got the definition that most technical-based hedge funds are derived from.

U - Understand

Determine the conditions under which the defined truth tends to occur. In the case of a trend tendency it could be when does the trend tendency begin beyond random? This will lead you to how to measure a trend. Since trends can occur randomly, how do I determine if a trend is beyond a confidence level of randomness? Does the trending tendency beyond random exhibit the same degree of persistence beyond one year? two years? 5 years? If not, is there some point at which the persistence beyond random occurs every year? If so, does it also persist at the same frequency for 5, 10, 50 different markets? If so, you've discovered a fundamental truth and you now understand what you need to know about the behaviour.

M - Mine

Once you understand the conditions under which the behaviour occurs, you write the code necessary to map the understanding of the behaviour. Is the code going to be all inclusive of many markets? or try to just go after the best of the best? Once mapped it's a mechanical process to determine how well it maps against the behaviour. After you're satisfied you've developed a satisfactory method for mining the behaviour, you can do an edge test to see if it happens beyond random. If not, use Monte Carlo sims to determine confidence levels for trading the method. Determine at what confidence level you'll stop trading. Examine the drawdown versus the profit. Is it worth risking any money on this? If so, allocate money using a money management scheme.

After you're done with this, you'll have your first system. Next, develop a complimentary system (non-correlated). Go through the same process for (a different type) a range bound system. Once you've gone through the mining stage, use the correlation test to weight the two systems. Apply the weights to the money management scheme and move on to your third system.

Trading with Amibroker

In this video I'll show you how I enter trades using Amibroker and the interface to Interactive Brokers TWS platform. I also briefly discuss how I find the stocks that I trade, using an Amibroker exploration. I wrote the interface code for two main reasons, to eliminate input errors using a graphical interface, and to speed up my order entry. IB's chart trader has it's use, but its not suited for what I want to do, not to mention its clunky and not customizable to my liking. Enjoy the video!
Update can be found here:
http://blog.tipster.ca/p/tipster-trendlines-3.html

Wednesday, August 6, 2008

Short Interest and the Short Squeeze

The NASDAQ web site allows you to take a look at the short positions over the past year or so by semi monthly data. This data is posted twice a month and is also available on Yahoo. I download this into Amibroker, sort it, scan it, and out comes the short data. The filtering I do involves the positions of the moving averages. The 10 above the 20 above the 50. I'll look at each of these and buy on strength anticipating a break out with a tight stop in case the breakout fails.
Here is the data for the last part of July, the new number will be available in a few days. When the new numbers come out I'll post the scan again. I can also run the scan every weekend to see what stocks look like the might advance. If you don't know what a short squeeze is, Google it.

The thing to remember here is that the high short interest is not the only reason to get involved in the stock but it sure helps fuel it to new heights. This scan picks stocks that have momentum and are poised to advance. You can get the excel version by clicking the image.



Sunday, August 3, 2008

Scans

Check back frequently, I'll be posting scans for the TSX and the US markets. The TSX scans are based on momentum buys. The US market scans are for short interest. You can use the short interest scan to look at some charts and select those that look poised to move on a short squeeze.

Disclaimer

The information presented on this site is for educational and entertainment purposes only. This site contains no suggestions or instructions that you must follow, do your own research and due diligence before committing your cash to the markets. Your on your own.