Showing posts with label Amibroker Code. Show all posts
Showing posts with label Amibroker Code. Show all posts

Thursday, August 30, 2012

How to program AFL in Amibroker and MQL for MT4

I’m a self taught programmer, the only classes I ever took part in were in high school.  Back in the day of the cards – you had to use a pencil on some cards then feed them into a machine and it ran your program.  I learned Fortran first.  Then a tried basic language on a Commodore 64 or something, long time ago, can’t remember the details.

If you want to learn Amibrokers AFL or MT4 here are a few suggestions:

Take a night course in programming, not sure which language is close to either of these but if you ask in some forums or Google for similarities you’ll find answer.  If you already know a language, don’t bother with school, jump to step 2.  

You first need to learn logic flow and what functions are and what object programming means, your looking learn to the concept of programming and how you write a program, run it, and debug it.  Then you can cross utilise this skill with any other language.  It takes some self learning. 

The next step, load up a small program and try to understand it. If you put your cursor on a function (which usually highlighted in blue) and press F1 help opens up and you can read about the function.  Then read the help docs on program flow to understand how the program executes. 

Next – load up a bigger program and understand the flow.  Make some small changes, maybe try to print stuff to the screen or alerts menu, or send en email. 

Next – read a tutorial, free one are always offered on line.  You can start with this as step one as well but after you play with code you should go back to a tutorial and read it again.  Read the tutorial once a week for 3 weeks, read it to understand it.  Read it when the kids are in bed, you need to focus un-interrupted.

Next – have an idea of what you want to do, then steel some code as a starting point and modify it to suit your coding goal.  here’s an example.  Load up the stochastic indi.  Make an indicator in one single window with 3 stochastic, with either K or D.  Set them to 8, 21, and 55 periods.  Run it on a 15 minute timeframe.  Now add another that is set to a forced time frame of 4 hours and is an average of the 8, 21, and 55 periods.  Plot the four lines.  Use the same colour for the 15 minute and a thicker and different color for the 4 hour.

Then, ask yourself this – am I coding because I like it and trading is secondary, or am I coding for a purpose? I got into the rut of coding because it was a challenge. I wasn’t learning to trade.  Then I decided to just watch the screen and price action and learn to trade. Then code for what I wanted to do.

And the best for last – I don’t think I have ever written a program from scratch – I always start with something that has been done already, then change it, add to it, delete stuff, and make adjustments.  After a while there might not be anything left of the original, but it sure make it easier to start.

Friday, April 13, 2012

Tipster Trendlines 3.2a - Visually Trade from the Chart

A video on the new version


Tuesday, July 12, 2011

Video on Tipster Trendlines for Amibroker

I thought I would offer an update on this code.  The code might be "old" but it sstill works and I still use it.

This code allows you to place trades and modify trades right from the Amibroker chart.  It has much more functionality than the current version of Amibrokers trading off the chart feature.  Watch the video and see for yourself.

Here is the link to read more about this and get the code.  Tipster Trendlines 3

Tipster Trendlines 3 from Another Brian on Vimeo.

This AFL code for Amibroker allows you to place trades right from the Amibroker chart. Once the order is place (transmitted) you can change it just by moving the 3 lines on the chart and pressing the button on the chart window. Once the order is filled, you can move the target and stop lines and press a button the change them too! All you have to do is draw 3 horizontal lines on your chart and you're ready to trade. Watch the video to see how it works.

http://blog.tipster.ca/p/tipster-trendlines-3.html

Saturday, November 6, 2010

Developing an Auto Trading System

UPDATE - this is the link to the article

http://www.adaptrade.com/BreakoutFutures/Newsletters/Newsletter0305.htm


If you've embarked on developing a trading system with auto execution, you have no doubt discovered that it's not that easy to find something that offers consistent profits.  You have all kinds of idea but not sure how to test them all, thinking it could take forever plus a day to find the right one.  Well there is something called Rapid Prototyping that can help you out.  There's a great article written about this and some AFL to go along with it.  Here's the info and links to get you started.

Article with a great explanation

Original AFL - You may have to fix line breaks to make this code work

// Rapid Prototyping Method for Trading System Development

// Idea from "The Breakout Bulletin March 2005" by Mike Bryant
// AFL coding by mmike

SetTradeDelays(1,1,1,1);
Cond1 = C-Ref(C,-1);
Cond2 = C-Ref(C,-2);
Cond3 = C-Ref(C,-5);
Cond4 = C-Ref(C,-10);
Cond5 = C-MA(C,5);
Cond6 = C-MA(C,25);
Cond7 = C-MA(C,45);

w1 = Optimize("w1",1,-1,1,1);
w2 = Optimize("w2",-1,-1,1,1);
w3 = Optimize("w3",-1,-1,1,1);
w4 = Optimize("w4",1,-1,1,1);
w5 = Optimize("w5",0,-1,1,1);
w6 = Optimize("w6",0,-1,1,1);
w7 = Optimize("w7",0,-1,1,1);

Buy = w1*Cond1>=0 AND w2*Cond2>=0 AND w3*Cond3>=0 AND w4*Cond4>=0 AND
w5*Cond5>=0 AND w6*Cond6>=0 AND w7*Cond7>=0;
Sell = w1*Cond1<=0 AND w2*Cond2<=0 AND w3*Cond3<=0 AND w4*Cond4<=0 AND
w5*Cond5<=0 AND w6*Cond6<=0 AND w7*Cond7<=0;
Short = Sell;
Cover = Buy;


AFL Code modified by me trying out a TTM system

// Rapid Prototyping Method for Trading System Development

// Idea from "The Breakout Bulletin March 2005" by Mike Bryant
// AFL coding by mmike

SetTradeDelays(1,1,1,1);
Plot( C, "Close", colorBlue, styleNoTitle
styleBar
styleThick );


/* Original test system
Cond1 = C-Ref(C,-1);
Cond2 = C-Ref(C,-2);
Cond3 = C-Ref(C,-5);
Cond4 = C-Ref(C,-10);
Cond5 = C-MA(C,5);
Cond6 = C-MA(C,25);
Cond7 = C-MA(C,45);
*/

// TTM and MA

HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
barcolor = IIf(HaClose >= HaOpen, colorBlue, colorRed);

//Plot( C, "Close", BarColor , styleNoTitle
styleBar
styleThick);

TTM = IIf(HaClose >= HaOpen, 1, 0);

Cond1 = TTM;
Cond2 = Ref(TTM,-2);
Cond3 = Ref(TTM,-3);
Cond4 = Ref(TTM,-4);
Cond5 = C>MA(C,5);
Cond6 = C>MA(C,50);
Cond7 = C>MA(C,200);


w1 = Optimize("w1",1,-1,1,1);
w2 = Optimize("w2",-1,-1,1,1);
w3 = Optimize("w3",-1,-1,1,1);
w4 = Optimize("w4",1,-1,1,1);
w5 = Optimize("w5",0,-1,1,1);
w6 = Optimize("w6",0,-1,1,1);
w7 = Optimize("w7",0,-1,1,1);

w1 = -1;
w2 = -1;
w3 = 0;
w4 = -1;
w5 = 1;
w6 = -1;
w7 = -1;

Buy = w1*Cond1>=0 AND w2*Cond2>=0 AND w3*Cond3>=0 AND w4*Cond4>=0 AND
w5*Cond5>=0 AND w6*Cond6>=0 AND w7*Cond7>=0;
Sell = w1*Cond1<=0 AND w2*Cond2<=0 AND w3*Cond3<=0 AND w4*Cond4<=0 AND
w5*Cond5<=0 AND w6*Cond6<=0 AND w7*Cond7<=0;
Short = Sell;
Cover = Buy;

Wednesday, January 13, 2010

Playback to Bracket Trader

There are two ways to backtest that I know of using Amibroker;
Use the backtester
use the playback feature

Backtester - This requires some coding, coding that isn't required when trading live with Amibroker, Bracket Trader, and TWS. You have to watch out for a whole basket of different issues that can creep into the test. It remains a valuable tool.

Playback simulation - This is a great tool for practicing discretionary trading. It's also a great tool for testing your Bracket trader (BT) interface / system. If it would just work! I searched high and low and the net for some information on how to do this, or code that I could simply drop into Ami that would "make it happen". The good news is that I've finally got it to work, and surprisingly it wasn't to difficult to code, but getting the bug out was an issue.

Ive used it to test several days of 1 minute HSI system with BT to get the stats from it. The last thing I just completed tonight was exiting positions near the close. Still a few issues to work out with that. Still, the most difficult part is finding a system that generates a profit, I'm looking for a winning ratio of 40% or better.

Is anyone else using Amibroker playback in this fashion?

I was contemplating doing a video on this and posting the code. Not sure I want to spend the time to do it though.

Tuesday, October 27, 2009

VWAP

Definition


"Volume Weighted Average Price. A measure of the price at which the majority of a given day's trading in a given security took place. Calculated by taking the weighted average of the prices of each trade. The method is used by institutional traders, who often break a given trade into multiple transactions."

Another definition

The VWAP for a stock is calculated by adding the dollars traded for every transaction in that stock ("price" x "number of shares traded") and dividing the total shares traded. A VWAP is computed from the Open of the market to the market Close, AND is calculated by Volume weighting all transactions during this time period.

VWAP, or Volume Weighted Average Price is a tool used by some traders, I first learned of it from Brian Shannon who trades stocks. This won't work for forex since there is no volume.

There are a few different ways of displaying this in Amibroker. It can be a simple line like a moving average, this is the most common way pro's use it. Amibroker has a function to display it behind price, look in the help for these two functions with examples;

  • PlotVAPOverlayA
  • PlotVAPOverlay
Here are a few ways tp lot it and some code to try out.

eTokes Blog post on VWAP
I suggest reading his post, as well as Brian's post on VWAP, links below. eToke used a vertical "study" line drawn on the chart. This might give you an error on your chart if there is no line drawn. Here is his code with a little fix for this problem (adding "Nz");


Plot VWAP starting at a horizontal study line (Study ID set to ST)

//VWAP since last change in sentiment
TurningPoint = IIf(Nz(Study(“ST”,GetChartID())==0,1,0));
BarsSinceLastTurn = 1 + BarsSince(TurningPoint==1);
StartBar = ValueWhen(TurningPoint==1, BarIndex());
RunVolume = Sum(V,BarsSinceLastTurn);
IIf (BarIndex() >= StartBar, MTVWAP = Sum (C * V, BarsSinceLastTurn ) / RunVolume,0);
Plot (MTVWAP,”MTVWAP”,colorPink, styleLine);

Other ways to plot VWAP

Plot VWAP starting at selector line

This is another way, it will display the VWAP starting from where your selector line is placed. I use it for short term trading to see where all the volume is, makes finding support / resistance a bit easier when working with breakout.

_SECTION_BEGIN("Selector Line VAP");
segments = IIf(SelectedValue(BarIndex()) == BarIndex(), 1, 0);
PlotVAPOverlayA( segments , 300, 50, ParamColor("Color", colorDarkGrey ), 6 );
_SECTION_END();

Plotted like a moving average

_SECTION_BEGIN("VWAP");
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 093000, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * V, Bars_so_far_today ) / TodayVolume,0);
Plot (VWAP,"VWAP",colorOrange, styleThick);
_SECTION_END();


Other links on VWAP
VWAP link 1
VWAP link 2

Saturday, September 5, 2009

Code Snippet - EOD Data

On the weekends many traders are looking over charts, some only do it on the weekends. They might place orders based on the charts they view. No matter what type of order you use, if you are using daily data, you may have noticed that sometimes you don't get all the current data for every symbol. Murphy's law says that the stock you interested in will be the one that is missing one days worth of quotes. A couple of times I have almost placed an order based on old data, but noticed something wasn't right when I logged into the trading software and noticed the last price was different. I wrote this piece of code to show up in the title when the last daily bar isn't the same as today's day. The code also considers Saturday and Sunday.


DownloadDate = LastValue(DateNum());
TodayDate = Now(3);
if(Now(9)== 7) DownloadDate = DownloadDate + 1;
if(Now(9)== 0) DownloadDate = DownloadDate + 2;
if(LastValue(DownloadDate) != TodayDate)
BarDateError = " *WARNING: Data NOT Current*";
else
BarDateError ="";


My title bar uses this code, which is where the value BarDateError is displayed.


Title = EncodeColor(colorLightBlue) + Name() + " " + FullName() +
EncodeColor(colorLightBlue) + " - " + Date() +
EncodeColor(colorBlue) + " O=" + O +
EncodeColor(colorLime) + " H=" + H +
EncodeColor(colorRed) +" L=" + L +
EncodeColor(colorBlue) + " C=" + C +
EncodeColor(colorYellow) + " ATR: " + Prec(ATR(6),4) + EncodeColor(colorWhite) +
" " + BarDateError;



Hope this helps you reduce errors, trading is hard enough without having to deal with oversights.

Sunday, August 2, 2009

Tipster Trendlines 2.11



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


Go to the Tipster Trendlines 2.1 post for additional information on how to obtain this AFL code. Don't make any more manual entry mistakes!

Several readers have donated and received the Tipster Trendlines 2.1 (TT) AFL. A few things have come up, and I want to share the questions and code fixes.

CODE FIX
This fixes an issue where TWS rejects the submitted prices when TT is set for "Futures" trading.
Search for the red text below using the find box and replace with the code below. The NEW code is in blue. If you can't figure this out, let me know by comment or email.

if(Length == "0")
{
BS = int( BS ); // this truncates whatever is after the decimal
TA = int( TA );
ST = int( ST );
IBTarget = NumToStr( TA, 1.0, 0);
IBOrder = NumToStr( BS, 1.0, 0);
IBStop = NumToStr( ST, 1.0, 0);

}

VISTA

Microsoft VISTA continues to be a problem for Amibroker. The Interpretation window should be closed according to Ami support. The issue has not been resolved at this time, stay tuned in the Yahoo Amibroker groups. The reports I am receiving indicate the the TT screen "flashes" when Auto Trading is turned on.

Here is some code added by Rick. This code flashes the screen at the start and end of the trading day. Adjust the time as required:


Plot(TimeNum() == 092959, "",colorPaleGreen,styleHistogramstyleDashedstyleOwnScalestyleNoLabel);
Plot(TimeNum() == 155959, "",colorRed,styleHistogramstyleDashedstyleOwnScalestyleNoLabel);

(In Preferences - Intraday, "Time stamp of compressed intraday bars shows - "END time of interval")

Questions and answers

Q1. can make change to stop loss and target profit or not so that I can move my stop loss/target after the trade is entered.

A1. No. Once the order is placed and not filled, cancel and re-do in Amibroker. Once the order is placed and filled, move stops and targets in TWS.

Q2. Also if I used stop + limited price to enter trade, the trade may or may not be able to be filled. Can we see the trade has been filled in the status of Amibroker panel or not without going to IB pages?

A2. No. This is possible but I have not coded it. I had that feature in an earlier version.

Other Issues
Lastly, I would appreciate any feedback on this code posted as comments so other potential users can see the value. If current users have any suggestions, of issues with the AFL please let me know and we will remedy.

Wednesday, June 17, 2009

Bracket Trader

Bracket Trader (BT) communicate directly with TWS. You can trade right from BT, or have an external app send signals to BT.

I've installed Bracket Trader and tried it with my IB simulated account. So far, so good. I like this set-up because I only have to generate signals and sent them to a text file. BT looks at the text file for orders and executes. BT has some nice features, trailing stops, multiple targets, etc. It's worth looking at. The main reason I like it is I don't have to code the scale out or order management part of the trade.

I'm setting Amibroker up to send LMT orders. If they don't trigger within a few bars then I cancel the order.

Has anyone else played with this application? I would like to hear about your experience. Once I get this working I'll post some AFL code to interface to BT, and I hope you will participate.

Wednesday, December 10, 2008

Tipster Trendlines - v2.1 being finalized

I've just sent the latest code (v2.1) to three others who offered to help get it all working. For the most part it works fine, just needs some calculations for the risk panel. I've tried to make it determine risk based on user selection of stocks, futures, or forex.

There are a few other brand new features too.

With the extra help, this shouldn't take to long.

Wednesday, November 26, 2008

Tipster Trendlines - Update

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





A quick update on the code; I haven't had much time to work on the code, not to motivated with the market jumping all over the place. I'm spending most of my "market" time evaluating my RRSP holdings. I'm also testing a strategy on the simulated account for longer term forex trades, s swing trade time frame from a day to a few weeks.


I hope to have the code ready in a week or two. Is anyone willing to test and give me feedback?

To qualify you need to know how to program in Amibroker, I'm looking for some help to test and tweak the code. Any takers? Drop me a line at my email, in the top right under "What this Blog is all about"

Saturday, October 4, 2008

Chart Trading Question

A reader emailed a question about the tipster trendline chart trading code that I thought would be beneficial to others if I posted it. I'm not offering any advice or opinion on the set-ups profit potential, only how the code works and IB's order triggers.

"I attached a graphic, in which you can see, on 1st of Oct. I wanted to short IMS, on breakout of the bottom of the previous candle, but as you can see the candle of 1st of Oct, is a strong up candle. My stop order of sell should not trigger, and my buy stop (which is my stop loss) is set to 12.39$, so what happen in IB."

Line BS is the buy stop order. The price must go below this level for the order to trigger. This is the "Parent" order.

Line ST is the stop loss order. This is a child order, child of Parent order "BS". This order is will not trigger until the Parent order triggers (BS).

Line TA is the target order. This is a child order, child of Parent order "BS". This order will not trigger until the Parent order triggers (BS).

So in this example, if the BS order was a "DAY" order and not a "GTC" (Good 'Till Cancelled) order, at the close of Oct 2 the order BS has not triggered, therefore ST and TA will not trigger. At the close of the day the orders will automatically disappear from TWS and you would not have a position.

How does this work in TWS? To see how this works, left click on the coloumn titles of your order page inside TWS. You need to add a field called "OCA" (One Cancels All). The Parent order (BS) will be blank. The two child orders (TA and ST) will have the same numbers in the field.

When you set up a bracket order manually within TWS, this is basically what TWS is doing for you. You can also do it manually. Try it manually to learn something. You can also use this technique to capture a breakout of a range, such as a squeeze in price, if you want to catch a move to the upside or downside. I haven't played with this type of order very much but I'm sure it can be done so that when you get a break in one direction, the orders for the other direction are cancelled.

Wednesday, September 24, 2008

Michael'sScreen Shot

Here is a screen shot from Michael. His version of "nothing special" is a simple screen.

I have heard that the two most valuable assets for a trader is screen time and discipline. Screen time is your ability to see price action without indicators. Over time I have noticed that you get a better feel for charts and price action by simply watching it live. Try this to see what I mean; look at a chart of the S&P or QQQQ every half hour throughout the day, keep notes every half hour on what you see and where price might go next. Note support and resistance lines. What you get from this is a timeline. You understand how long it takes for things to happen. If you can't do this at work, than watch a different market such as Australia stocks, Forex, or Gold.

Michael writes:
This is my screen shot, as you can see it is nothing special, I use at most two indicator like PPO and ADX for detect HDIV and DIV and pattern like Wolfe Waves.


Michael is also preparing a guest post on Wolf Waves, we look forward to that post.

Tipster Trendlines

Thanks to Murthy for additional code for the Tipster Trendlines, trading from the chart.
He has added functionality that tells you if your lines are off the viewable chart area along with some other functionality.

A new version of Tipster Trendlines is available.

The "free" version is no longer available. Go to the Tipster Trendlines 2.1 post for additional information.

Pete's Screenshot

Pete sent me his screen shots. He shows us one EOD and one Intraday screen. He's trading index fuures on these charts. From his description, it looks like he's visited DayTraderRockStar. Pete, great set up, good job. This is an example of simple uncluttered screen. This is very close to a template I'm working on at the moment for futures. I'm currently working on my "Radar Screen" that has overall market Ticks, Puts/Call ratio, and Trin as well as some of the majors.

Instead of me re-writing what he has sent me here it is;

I would also recommend www.powercharting.com for some really great information on trade setups for trading futures intraday. The two charts I'm sharing are rather new for me. I just configured them a couple weeks ago when I started doing a little intraday trading.

The intraday setup chart is pretty simple. I use the real-time quote window on the bottom to select the security I want to view. The 15 and 5 min charts are linked so they show the same ticker. I use a 20 period EMA along with a 200 period MA. Those horizontal lines you see are pivot levels. I have since refined the code to calculate weekly and daily pivots on an intraday chart automatically. I just love the flexibility Amibroker offers.

The EOD setup is an example of my pivot point calculations (shorter lines at far right), and I have a few longer trend lines which are there to remind me of weekly and monthly support/resistance levels.
I have been working all summer long on developing a trading system. For now I don't have anything to show in that area as it is still a work in progress.


Thanks again for sharing and also for providing an environment for others to share.


Monday, September 15, 2008

Screen Shots

A call to all users of charting software!


Often we read about trading systems and methods, risk management, triggers, market indicators, and the list goes on. As I read through blogs and trading books that talk about set-ups, triggers, stops I often ask myself "everything is being presented except the final piece of the puzzle", usually this is the entry and initial stop placement. Sure, once the trade gets going there is an entire different approach; when to take profits and how soon to move the stop. I wonder what the screen looks like that these guys are trading from? How do they arrange the windows to make it easy to monitor the things they need to monitor. I've seen pictures of huge desk's with multiple monitors. What's on these screens? Have you ever watched videos on Youtube by the "Suck My NASDAQ" guy? He's a day trader that makes pretty good calls but he never gives you details and never shows you his screen. Until we see what he is looking at, we cannot tell his source of info, or what he's using to form his "opinion". Not that we need too.

I thought I would use this blog to post some screen shots of various users. I don't know what exactly it will generate in terms of ideas or education, but it will be interesting. My screen has developed over the years moving averages and a bunch of indicators to only a few screens. I only use indicators I understand. My current screen for day trading has a 5 minute, 1 minute, risk screen, and pivot points. For end of day trading I use two screens which I have shown on previous videos, one that has moving averages and order entry (where I draw horizontal lines for entry, stop, and targets), and the other is the risk screen.

How to do a screen shot (screen capture)


Method 1: This is the method I use. Maximize your application that you want to capture. Press the "Prt Scr" key (above the "Home" key). Open up your email application and "paste" the image. If you want to trim it first, open up your Microsoft Paint or something similar (I use a really old version of Paint Shop Pro) and edit the image.


Method 2: Use other software the capture, Paint Shop Pro also does this (I use a really old version, simple but effective). You could also use something like screen Hunter 4.0 (Freeware).


Danger:
The problem with looking at other peoples code and screen captures is that you tend to want to try it all to find the silver bullet. I've tried so many formulas and set-ups that I eventually figures out what I wanted. You don't know what you want or can have until you know the boundary's of what is available, then you find yourself satisfied. I'm down to using different types of moving averages, stochastics, ATR, and TTM on bar charts (I found that I don't like candlestick charts). I also found I prefer blue and red bars. This took hours of looking at charts to find my ultimate preference. So a word of caution when you look at screen shots, before you ask "how did you do that, can you share the code?", consider if it would really be useful to your trading game. On the other hand, perhaps you need to immerse yourself in all that's available in order to find what works for "you".
I would like to post screen shots of other users, doesn't matter what software you use. Please email me your screen shots to tsxtrends @ gmail dot com (fix the email address, it is modified to prevent spam engines). It would also be helpful to have a small description to help people understand “why” and "what" they are looking at.
Here is a screen shot of my EOD screens (using my IB simulated account). I'll post my other screens later next week.

Above: Main screen with MA's. Watch the videos for additional info on this screen.



Screen Shots by David W
He writes:
"I have lots of screens and indicators that I have tested and tried over the last few years – and now tend to use 2-5 indicators, CCI, and a price chart. In other words I have my favorites. This is a great idea because I got to this point looking at other peoples screens and setups. Would only take a few minutes for the screen shot. Also this is exactly how I am documenting my system – screen shots and descriptions in Word. Further, If I like someone’s idea – I add it to my future plan section in my Trading Plan. "








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

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.

Saturday, November 10, 2007

Amibroker Code - Zero Lag

I'm working on a bit of code that will plot a small line at recent high and lows in an attempt to highlight the "highest highs" and "lowest lows". I find that my eye doesn't catch that too quick, and that I have to stare at a chart for a while to determine what the trend is. I also know why I haven't learned to pick it up as quick as others, I don't "practice" enough. This is the main reason I'm trying to build a system, so I don't have to watch for trades all day long.... I can't anyways, I have a day job.

Here is some code I use called the "Zero Lag". I discovered this at amibrokerfan.com and modified it a bit. Enjoy.

When I post the code directly to the blog, the HTML screws up some of the text. Rather than figure out what the HTML switch is to post just text, I have posted the code to google docs.

Zero Lag Code

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.