can my strategy be automated?

Discussion in 'Automated Trading' started by brynno, Feb 3, 2013.

  1. brynno

    brynno

    what i would really like to know is firstly whether or not it is possible, in principle that a computer could trade my strategy for me.. and secondly, what my first step would be in finally getting this thing done after all these years. i have no friends in the "real world" who know anything about this either and i just do not know where to start - nor even whether it is potentially feasible in the first place.

    very briefly, this is a summary of the predicament in which i currently find myself. i believe that i have developed a profitable strategy which is 100% algorithmic involving no decision-making (discretion) on my part. i simply need to click "buy" and "sell" when all conditions are met according to my rules. this has, however, proven almost impossible to accurately execute in real time. typically i'll have a few dozen securities (i day trade US stocks) that need to be monitored throughout the day, from which at some point an entry might be triggered in maybe 4 or 5 of them in an average day. the problem is that, especially during "busy" periods when i get most of my trades, there just simply isn't time for me to process the data quickly enough to catch the entries as they are triggered. much of the time, i find myself not only missing valid entries but also accidentally getting into "illegal" ones where not all conditions have been met. sure enough, the illegal ones take out my emergency stop nearly every time!

    now whether or not my strategy actually is profitable on paper as i say it is, is not the point (i am convinced it indeed is). if i were able to automate it then at least i would find out either way. could anyone please advise me as to whether or not automation is even possible, bearing in mind we are not talking about something simple like "buy at new highs". dozens of stocks would need to be screened simultaneously and entries/exits would need to be made immediately as they are triggered. ultimately, the timing of my entries and exits depends solely on what the price charts are doing (price action). no indicators are involved, nor is any external fundamental information required. purely price action and nothing else. and once again, discretion does not enter into this anywhere at all. everything can be reduced to yes/no, on/off. a lot of calculations, yes; but no decision-making.

    my broker is "interactive brokers". (i trade straight off the "chart trader").
    please, if anyone thinks this can be done, i would be very grateful if you could advise me on how to proceed to at least get the ball rolling. presumably i need to choose a programming language of some sort? pay somebody to write the program for me?

    where do i start!

    thank you
     
  2. gmst

    gmst

    The way you have described it, yes it can be automated. Now, how do you go about automating it.

    Well, can you do any programming at all? If you have never ever done any programming before, then you have 2 choices: 1) Outsource your work to some programmer to code the thing for you or 2) learn how to program.

    Option 1) is something you can start immediately, it will just cost you money. However, option 2) will have a 2 months learning curve (say putting in 4hrs per day). Option 2) will allow you to retain all the IP whereas under option 1) it is obvious that the programmer will know your strategy.

    If you have never programmed before, I do not recommend Ninja Trader. It is based on C# which is a proper programming language. Rather you should go with something like Multicharts or Tradestation which has relatively simpler English like language called easylanguage.

    Finally, if you want to hire someone to program, you should always consider the possibility that that person in future might start trading your own strategy. So, theoretically it is possible that you might be able to hook up with someone to code your ideas for you without any fees - fees rather being that you give him the right to trade your ideas. So, if you are trading very liquid stuff, it should not matter. Just something to think about.

    Again, yes if you can write down all the rules, it is possible to automate. Currently I am in the process of automating my stuff on Multicharts. So, I am not an expert by any means but definitely looking at a strategy, I can tell how easy it will be to code the idea and how easy will be the automation. Feel free to PM me with more rules of your strategy if you want my 'limited' opinion.
     
  3. brynno

    brynno

    thank you for your replies, particularly to gmst. i will say a few more things about this then, if you have time. please reply in your own time (or not at all!); there is no rush.

    i know nothing about programming myself, and i do mean quite literally nothing, though my father happens to be an expert in the "CICS mainframe application system" (whatever that is!) and in a programming language called "IBM assembler". he assures me that what he knows about unfortunately has very little to do with what i would require to build an automated trading "machine" but we both agree that he might be in a good position to learn the necessary programming more quickly than most people. he is certainly more than willing to give it a shot but doesnt know which programming language to start learning... how to download the data.. how to set it up so that it is compatible with IB's tws trading platform ..... how to...
    ..sorry i know so little about this that i don't even know how to describe what we don't know! (my dad's away on holiday for the week so i don't want to bother him right now)

    you said that ninjatrader uses a "proper" programming language; well i suspect i might in fact need a "proper" one due to the complexity of my set of rules. i can't even imagine the amount of code that must be required. i can say something more about my strategy if it would be helpful.

    first of all, the complete set of rules that i am talking about here would be useless to anyone who does not have a fresh shortlist of potentially eligible stocks each morning, together with some very basic information such as the price range in which each is enterable. i arrive at this information based on my preparation done the night before. this is how i get my universe of stocks down to a few dozen tradable the following morning. i enter this into the "notes" column on the TWS and constantly refer to it when the markets are open. without it, my live trading rules are of no use whatsoever. presumably, i would need to input these values into my computer program each morning in advance before the market opens. this "preparation" part of my strategy does not need to be automated, as it is done in my own time, when the markets are closed, usually with no errors. that i would do this myself each day also neatly solves the issue of somebody being able to use my strategy themselves - they won't be able to!

    once the market opens in the morning, then, it is always a frantic rush to check each one of my shortlist of dozens of stocks to see whether any of them are setting up just nicely. after a few minutes, i might have temporarily ruled out all but a dozen or so, although those that have been temporarily ruled out might well be playable a little later on, so they will still have to be frequently monitored. so i might be left with say a dozen stocks by 9.45 in the morning that could trigger an entry at any time; i'll be frantically trying to toggle between each of the charts, not to mention various timeframes for each, as the action unfolds. each time i click on a different chart on the sidebar, i usually need to wait a few seconds for it to flash up, it's usually not instantaneous because i'm trying to access it more quickly than my computer/internet can handle, i suppose. (to this day i still dont know whether the delay is due to my computer or the internet speed or something else entirely! ??)

    at a certain point, i might be pretty sure that one of the stocks that ive been monitoring has fulfilled all the criteria for an entry. ideally i need to be absolutely 100% certain, but often i'll enter when i'm only 95%, since otherwise i'd barely trade at all, since there just isn't time to check and double check every single one of my rules for every single stock! so i enter... then trade it out according to my exit strategy.. and probably as much as 50% of the time i'll realise that i've made a mistake somewhere - by this i don't mean that it hasnt worked out so i "must" have made a mistake, but rather that i've accidentally broken one of my strict rules. of course, it can happen that i break a rule and the trade still works out (but it usually doesnt!). also note that i never deliberately bend the rules; my issue is not psychological but literally my inability to interpret the data and determine in real time whether there is or there isnt an entry. of course, while i'm dealing with an "illegal" entry, meanwhile i'll have likely missed one or two VALID entries, and there goes my profit for the day. time and time again this is how my day pans out. i believe it really is almost impossible for a human and so i'm not too far away from giving up after several years of effort, unless i can finally get it automated. the actual strategy itself, i am extremely confident in it, and very proud of it.

    right i'm going to stop there,
    i apologise for the length of my post.

    i don't necessarily expect any help from anyone; i don't know, somebody might find it interesting if they're bored! perhaps someone can relate to this experience? i highly doubt that i am the only one in this position.

    bryn
     
  4. gmst

    gmst

    Hello, You are in a great position actually with your father being an expert in IBM assembler. And as it seems, he is willing to help you get started. Great!

    He will learn multicharts software and easylanguage in 5 days flat. And will be learn how to set up data, prices etc. in multicharts from IB in few hours. Get a free trial of multicharts from this link.

    http://www.multicharts.com/free-trading-software/

    Valid for 1 month. Get the free trial next week when your father is back in town and after you have a chat with him. Multicharts also has a .NET version. Since your father is a pro programmer, he might prefer the .NET version.

    If your father decides to work few hours every day, chances are high that your automation would be complete by March end.
     
  5. jazeonli

    jazeonli

    You are lucky that you need to prepare a shortlist of potentially eligible stocks each morning for your strategy to work. This way even if you hire a programmer, you keep the important part of your strategy secrets.

    You are also lucky your father has a programming background and is willing to help you. He won't be able to use his CICS expertise directly however he will probably be able to read and interpret the strategy code and the rules you prepare.

    I am a programmer and have a few automated systems trading live 24/7 with InteractiveBrokers.

    I believe you should have full control over your automated trading platform. Since I don't know how the NinjaTrader/Multicharts/Tradestation is working internally I cannot use it. With Multicharts my control stops at the easy language code. I don't know how their backtesting code works. I also don't know how their order management works (this is important if you have an intraday system).

    Hint: backtest a strategy in NinjaTrader/Multicharts/Tradestation and some other platform. I bet the results will not be the same.

    In the past years I was able to build strategies and test them before going life. Many times strategies were giving me good results only to find an error in the way my application used data during backtesting. This saved me a lot of money.

    In the past I also used four other backtesting platforms. I can only say that all of them are giving better results than they should. Once I found out I cannot trust how a backtesting platform executes orders, I spent all my time looking for similar errors in my application. I "destroyed" many "good" strategies by testing them as close as possible to the realtime life trading.

    I suggest you pick one of the open source automated trading systems which trade with InteractiveBrokers API. I use JSystemTrader/JBookTrader (originaly I started with JSystemTrader and then merged it with JBookTrader).

    First strategy is usualy difficult to write since you need to get to know how the generic trading application works. This part of the application connects to the broker, subsribes to a data feed, calculates indicators,... This generic part of the application is similar to what Multicharts/Tradestation does except that you have the complete source code for it.

    The important thing is that you have the source code of your automated trading system. Through time you will learn how to modify your strategy and even how to write a new one.

    At some point every trading application calls a function where you put your strategy rules. I will include a sample code of such a function for one of my strategies at the end of this post. I'm sure your father will be able to understand what it does even if he doesn't know the programming language (Java in this case). I'm also sure he could modify this code or even write from scratch new rules.

    Most users would want to keep the rules in this function to themselves. In your case this is possible if a programmer writes one line of code for each rule and your father puts them together with IF statements the way you want them to work. This way you leave the hard stuff to the programmer and also keep your strategy logic to yourself.

    I'm willing to help you and your father to setup the generic trading application and program your basic rules for you.

    Here is a sample function with strategy rules (in your case 'directionPoints' could be % of the criteria for an entry fulfilled and 'directionPointsSignalConfirmed' would be a constant 100%):

    Code:
    private PriceSizeBar calculateSignal(PriceSizeBar priceSizeBar, boolean isCompletedPriceSizeBar) {
    	int direction = priceSizeBar.getDirection();
    	double lastPrice = priceSizeBar.getLastPrice();
    
    	// Profit/Loss for the position.
    	int lastSignalDirection = lastSignal.getDirection();
    	double buyProfitLoss = lastSignalDirection > 0 ? lastPrice - lastSignalPrice : 0;
    	double sellProfitLoss = lastSignalDirection < 0 ? lastSignalPrice - lastPrice : 0;
    	double profitLoss = (buyProfitLoss + sellProfitLoss) / getTickSize();
    	boolean isLoss = (profitLoss < 0);
    
    	Signal signal = priceSizeBar.getSignal();
    	if (signal == Signal.Undefined && isCompletedPriceSizeBar) {
    		double currentHistoricalDailyBasePrice = priceSizeBar.getDailyVWAP();
    		double currentHistoricalFixedVolumeBasePrice = priceSizeBar.getFixedVolumeVWAP();
    		boolean isFixedVolumeVWAPAboveDailyVWAP = (currentHistoricalFixedVolumeBasePrice > currentHistoricalDailyBasePrice);
    		boolean isFixedVolumeVWAPBelowDailyVWAP = (currentHistoricalFixedVolumeBasePrice < currentHistoricalDailyBasePrice);
    		if (currentHistoricalFixedVolumeBasePrice > 0) {
    			int directionPoints = priceSizeBar.getDirectionPoints();
    			int directionPointsAbs = Math.abs(directionPoints);
    			String directionPointsAsString = priceSizeBar.getDirectionPointsAsString();
    			String directionPointsRules = priceSizeBar.getDirectionPointsRules();
    
    			// Check for signal where price returned to the base price.
    			if (directionPointsAbs == directionPointsSignalConfirmed) {
    				// New signal.
    				signal = (direction > 0 ? Signal.Buy : (direction < 0 ? Signal.Sell : Signal.Undefined));
    				priceSizeBar.setSignal(signal);
    			}
    
    			// Check for signal where price didn't return to the base price.
    			if (directionPointsAbs >= directionPointsSignalRunaway) {
    				// New runaway signal.
    				signal = (direction > 0 ? Signal.Buy : (direction < 0 ? Signal.Sell : Signal.Undefined));
    				priceSizeBar.setSignal(signal);
    			}
    
    			// Check for profit target.
    			if (profitLoss > PROFIT_TARGET_PIPS) {
    				signal = (direction > 0 ? Signal.Buy : (direction < 0 ? Signal.Sell : Signal.Undefined));
    				priceSizeBar.setSignal(signal);
    			}
    		}
    	}
    	return priceSizeBar;
    }
    
     
  6. +1
     
  7. I asked the same question as things were getting more and more mecahanical. Best advice I got was from an experienced programmer who told me, "If you hire out, consider it to be a long term realtionship, because there will always be bugs to fix and modifications to make."

    since I'm not really into long term commitments, that kind of made my mind up

    I look at it as just a hobby, something to do on the weekends when the mkt is closed.
     
  8. brynno

    brynno

    ok thanks for the replies.
    we'll have a look at ninjatrader and multicharts for starters and i'll let you know if any progress is made!
     
  9. Check out bloodhound for ninjatrader...

    No,programming necessary.

    Should be able to do what you want.
     
    #10     Feb 4, 2013