About programming and trading

Don’t get me wrong, I am not selling any trading system here. Before I go into the main point, I am thinking of sharing some of my new findings of Tradestation.

I spent most of the past weekend reading some books in my trading library and playing with EasyLanguage programing on Tradestation. I was preparing the program for backtesting, and to my surprise, I was in fact, automating my dummy trading system. With the help of some functions in Tradestation, I am able to fire basket orders for execution automatically. Well, good findings, but, now it is not the time for me to utilize it. Anyway, It is useful to Asian trader like me, who trades in the middle of the night. I can always replace the order function with Alert, just to wake me up when opportunity appears.

Some thoughts from programming. As you might know, to code a piece of software, you need to have a defined program flow , logic, specific declarations, input, and return values etc. (I know some readers like ZBS, Eyal, and Richard are far more better than me when it comes to these IT stuffs, so please correct me if I sound funny) You can’t have something which is ambiguous. You gotta tell the program what it should do. I have no problem with coding, but I was stopped couple of times when programming my trading system. I have realized that I have been making too much assumptions and judgments when I was making dummy trades.

For example, “we want the price pull back to the area near 20-EMA”. Fine. How “near” is considered near? 1 tick, 2 ticks or 5 ticks away from 20-EMA? Another example, “We want to enter the trade above a narrow range bar”. Excellent idea. But how “narrow” is considered as narrow? One more example, “When the price is trending up, I would go long” , Cool. Hey, What do you mean by trend up?
Dave commented on my system before as “I see there are a lot of “play” in the system, In other words,there are a lot of guidelines, there are very few real rules.” I fully understand his point when I started programming.

Here are some suggestion to evaluate if you really have a set of real trading rules for your system. You don’t have to do the boring coding. Instead, I would suggest trying to write out Pseudocode of your system. For example, a simple moving average crossover system should look like something like this

If 5-EMA crosses above 20-EMA then
if High-Low <=1.5 points and (low-20-EMA)<=2 ticks then Buy next at high +1 Tick. Stop loss at low - 1 Tick end end (The code above is for illustration purpose, you will go burst trading that) Nothing so technical, but it is one of the ways to think through and stop cheating yourself by thinking you do have rules. Guidelines are just not enough. I have found it to be inefficient when I need to make too much judgment and guessing during trading session. I am not suggesting to have any magic values for narrow range candle or distance from EMA, but you need to be specific in defining your system. Just a quick note to share something which I find it to be useful, nothing fancy. I am still working on backtesting.

About Gav

A Father, Husband, Trader, and Blogger. A serious coffee addict. Started trading since 2005, trades Futures and FX.

Follow me at Twitter and Google+

Comments

  1. I have been programming computers so long, I tend to define my guidelines in ways that could be programmed. 🙂

    There are methods to deal with fuzzy and inexact concepts and values (like “near” and “narrow”), but the underlying math does eventually turn the decision into a binary yes/no. Though, I should point out, the underlying mechanism in your brain turns the decision into a binary yes/no at some point as well–so the programming is really just a matter of reconstructing the rules that you internally use to define “narrow” in each context.

    Of course that’s a lot harder than it initially sounds to most people, until they sit down and try to program it themselves, of course! That’s why your pseudocode idea is good, as long as people have a good enough concept of what a machine can and can’t do when they try it.

  2. I have been programming computers so long, I tend to define my guidelines in ways that could be programmed. 🙂

    There are methods to deal with fuzzy and inexact concepts and values (like “near” and “narrow”), but the underlying math does eventually turn the decision into a binary yes/no. Though, I should point out, the underlying mechanism in your brain turns the decision into a binary yes/no at some point as well–so the programming is really just a matter of reconstructing the rules that you internally use to define “narrow” in each context.

    Of course that’s a lot harder than it initially sounds to most people, until they sit down and try to program it themselves, of course! That’s why your pseudocode idea is good, as long as people have a good enough concept of what a machine can and can’t do when they try it.

  3. Richard, thanks for your comment.
    I realized how weak is my “system” when I started writing codes. It is also a good way to organize trading ideas into a logical flow and it helps to make a better trading decision.

    Have a great week ahead!

    Gav

  4. Richard, thanks for your comment.
    I realized how weak is my “system” when I started writing codes. It is also a good way to organize trading ideas into a logical flow and it helps to make a better trading decision.

    Have a great week ahead!

    Gav

  5. I wish I knew something about programming 🙂 I went a similar route to yours some years back using both TradeStation and WealthLab. I gave up on trying to even backtest the dummy system not to metion automate future trades because of similar difficulties you mentioned. It probably can be done but the effort would be quite significant and the data available has to be to correct. For example measuring the pace a stock trades and not just volume.
    I think the benefit of what you are doing is in at least defining to yourself as much as possible what are your candidate selection/entry/exit criteria etc.

  6. great post…interesting idea

  7. great post…interesting idea

  8. I find it almost impossible to code Tradstation well enough to do all my “thinking”. As you say, it is hard to turn somethings into code. What I have done is write code for the radar screen that looks for those “fuzzy” rules I have. You can have the radar screener look for those instances that would include what you are looking for. Example: you can have the program look for stocks that are “near the 20 RMA” by saying 8 tics is near enough I want to take a look. This way the computer looks over 1,000 stocks every second and brings you the ones that Might meet your needs. So you get a short list of 10 stocks and out of that you find 3. Much better than pouring over 1,000 charts by hand. These searches can get pretty specific and look for a huge combination of “Fuzzy Little Things”. With a little work you can write one that will hand you a small list that will include those needles in the hay stack.

  9. John, thanks!

  10. John, thanks!

  11. i just spent the weekend doing the same with tradestation. i have the platform but my funds have not arrived yet from my old broker. Looking visually at the chart shows that i should be doing better than the backtesting results. I cannot yet figure out all the things to make it “think” like i do. Or maybe, my thinking needs to adjust.
    Either way, it is really interesting so far. Once i have more time and figure out more of this stuff i will put it into action with real money and see how it pans out.
    by the way, Teresa Lo has a black-box system on her website for sale. it works with tradestation among others.

  12. I find it almost impossible to code Tradstation well enough to do all my “thinking”. As you say, it is hard to turn somethings into code. What I have done is write code for the radar screen that looks for those “fuzzy” rules I have. You can have the radar screener look for those instances that would include what you are looking for. Example: you can have the program look for stocks that are “near the 20 RMA” by saying 8 tics is near enough I want to take a look. This way the computer looks over 1,000 stocks every second and brings you the ones that Might meet your needs. So you get a short list of 10 stocks and out of that you find 3. Much better than pouring over 1,000 charts by hand. These searches can get pretty specific and look for a huge combination of “Fuzzy Little Things”. With a little work you can write one that will hand you a small list that will include those needles in the hay stack.

  13. Good point, Gav. I forgot you’re doing it on futures. Good luck.

    Yes I want to visit Vivocity, looks quite impressive but I haven’t been there yet. I heard the cinema has premium seats, might be worth checking it out. Know any cute lady you can intro me? 😛

  14. I wish I knew something about programming 🙂 I went a similar route to yours some years back using both TradeStation and WealthLab. I gave up on trying to even backtest the dummy system not to metion automate future trades because of similar difficulties you mentioned. It probably can be done but the effort would be quite significant and the data available has to be to correct. For example measuring the pace a stock trades and not just volume.
    I think the benefit of what you are doing is in at least defining to yourself as much as possible what are your candidate selection/entry/exit criteria etc.

  15. Good point, Gav. I forgot you’re doing it on futures. Good luck.

    Yes I want to visit Vivocity, looks quite impressive but I haven’t been there yet. I heard the cinema has premium seats, might be worth checking it out. Know any cute lady you can intro me? 😛

  16. Hey Eyal,
    I am not trying to backtest Dummy. Instead, I am working on my own version of dummy system. As you know, dummy trading can be very different for every trader.
    I understand it takes a great effort to do that. Though I am not a big fan of backtesting , I decided to give it a try.
    I guess for stocks trader, it might be a little more complicated, at least , you need a bigger database for scanning. I am only focusing on few futures contracts, so hopefully, it is not as complicated.

    So far, I have gained positive results from the progress, like understanding deeper about my own system, rules and fine tune my risk management stuffs.

    Have a great December!

    Btw, maybe you can try out Movie theater at Vivo City, pretty cool 🙂

  17. Hey Eyal,
    I am not trying to backtest Dummy. Instead, I am working on my own version of dummy system. As you know, dummy trading can be very different for every trader.
    I understand it takes a great effort to do that. Though I am not a big fan of backtesting , I decided to give it a try.
    I guess for stocks trader, it might be a little more complicated, at least , you need a bigger database for scanning. I am only focusing on few futures contracts, so hopefully, it is not as complicated.

    So far, I have gained positive results from the progress, like understanding deeper about my own system, rules and fine tune my risk management stuffs.

    Have a great December!

    Btw, maybe you can try out Movie theater at Vivo City, pretty cool 🙂

  18. Boots,
    Absolutely. I agree it is impossible to code your thinking perfectly. As much as I can do, I will put it into code for all the rules I have. This is to eliminate as much guessing as possible during trading session. You know, It is a waste of time to guess something like “is the candle narrow enough”? or “is this considered near EMA”?
    That’s why, I do not go for automated trading system. Like what you’ve mentioned, I need a watchlist or alert. And, for trading, certain degree of human intervention is still needed, just my opinion. 🙂

  19. Boots,
    Absolutely. I agree it is impossible to code your thinking perfectly. As much as I can do, I will put it into code for all the rules I have. This is to eliminate as much guessing as possible during trading session. You know, It is a waste of time to guess something like “is the candle narrow enough”? or “is this considered near EMA”?
    That’s why, I do not go for automated trading system. Like what you’ve mentioned, I need a watchlist or alert. And, for trading, certain degree of human intervention is still needed, just my opinion. 🙂

  20. Sure Eyal,
    I will keep you “informed” if I meet some cute lady.
    😆

  21. Sure Eyal,
    I will keep you “informed” if I meet some cute lady.
    😆

  22. Hi,

    http://elitetrader.com/tr/

    Cheers / Ben

  23. Hi,

    http://elitetrader.com/tr/

    Cheers / Ben

  24. Hey Ben,
    Thanks for the link!

    Gav

  25. Hey Ben,
    Thanks for the link!

    Gav

  26. Gav,

    I also have an automated scanning tool I call MONEYMAKER. It is a crossover system of 3 moving averages.

    Trade Well.

  27. Gav,

    I also have an automated scanning tool I call MONEYMAKER. It is a crossover system of 3 moving averages.

    Trade Well.

  28. Born2Code says:

    i just spent the weekend doing the same with tradestation. i have the platform but my funds have not arrived yet from my old broker. Looking visually at the chart shows that i should be doing better than the backtesting results. I cannot yet figure out all the things to make it “think” like i do. Or maybe, my thinking needs to adjust.
    Either way, it is really interesting so far. Once i have more time and figure out more of this stuff i will put it into action with real money and see how it pans out.
    by the way, Teresa Lo has a black-box system on her website for sale. it works with tradestation among others.

Speak Your Mind

*