Bar based Autotrading

Discussion in 'Automated Trading' started by walterjennings, Oct 14, 2010.

  1. Logic

    Logic

    From what I'm gathering, this is what you're hypothesizing:

    * A backtest using data that's 1 bar old outperforms a backtest using data that's 2 bars old

    * Therefore, if going live where we can react to the current bar, it should outperform the 1-bar-back backtest in the same way the 1-bar-back backtest outperforms the 2-bar-back backtest.

    Unfortunately, this isn't true. There is a step before going live, which is forward-testing - simulation in real-time. If you do that before going live, you'll be able to see the issues I'm going to present:

    [Using 1-minute bars] When a bar forms, you have all sorts of actors moving on it; a bar that eventually turns into a "buy" bar might not do so until second #53 (for instance). That's not a problem, except it's possible that there was a very short-term sell-off from seconds #1 through #40. Look for Doji candles on the chart - they're the type of bar that cause these events the most.

    If you were using a bar-based system to react against this real-time bar, your system would generate an erroneous sell signal for the first 40 seconds (depending on how sensitive your system is), and then nothing for the next 13 seconds, and then a buy signal for the last 7 seconds.

    Since a bar system is only designed to react once per bar, your realtime behavior here would be to generate the sell signal. This is "unexpected" behavior, since the true action your strategy is supposed to perform is a buy signal - since bar systems analyze once-per-bar-at-the-end-of-the-bar.

    Another scenario is that your bar system erroneously behaves like a tick system, generating a sell signal first, and then a buy signal later in the same bar, causing you to wash out of your entry for a loss.

    I hope I've interpreted your question properly.
     
    #11     Oct 15, 2010
  2. Yup. I agree there are situations where recalculating based on the newest bar may be bad. The question is, on average, will it have a positive effect or not, my price calculations are fairly slow and normally only shift around 1-2 cents per 1 min bar. a spike up in the bar may cause the price levels to shift up before the level is it, which would result in a more adventurous fill (or miss). I am unsure if the system 'dragging its feet' or being more reactive will get better performance, the only way for me to know for sure is to try trading them in separate accounts at the same time. Though I was hoping someone on here would have tested this theory live before.
     
    #12     Oct 15, 2010
  3. Logic is pretty correct here on the post before yours.

    I have tried what you are trying to do. I have always used something like this.


    Ex.

    = AND (Buy Limit @ Previous Bar Close - .5 && Limit > Previous Bar Low)

    The problem you will run into when forward testing live is another problem as well. You will never get the same fills on a live forward testing SIM as you will when you are actually running live with money on the line (Non-SIM forward testing).

    If you continue on this path of wanting to use these methods I seriously recommend using longer term bars for testing (15 min ++).

    Honestly, I kind of think you are wasting you time with anything less, but if nothing else at least you will learn from what you are doing. That is probably the most important part.

    Depending on the software provider you are using as well you could really have some messed up non-real world fills going on. That I found over the past few years is the most detrimental part of this whole process. It becomes quite depressing, trust me, I have gone through the emotional ringer so to speak with this entire process.

    GL
     
    #13     Oct 15, 2010
  4. borland

    borland

    With backtesting, what you want to see is results that are 'representive' of forward testing or actual trading.

    There are many factors that can change actual results. But a representative sample is all you need, as future results are never predictable. All you can hope for is trade expectancy.

    On my system using StrategyDesk, I have it set to 'buy the open' on the 5 minute bar. So my backtesting is done also on 'buy the open' by always looking back at the most recent closing bar before calculating various indicator values in the trade trigger logic.

    Since my system is multi-timeframe, the backtester must also be set to 'calculate intra-bar on 5 minute intervals' for longer time periods than my systems 5 minute primary bar. Otherwise, the backtester would be calculating indicator values by looking forward to the close of those longer interval indicator values, there by providing un-representive results.

    Hope your system's backtester has these same features.
     
    #14     Oct 16, 2010
  5. borland

    borland

    With backtesting, what you want to see is results that are 'representive' of forward testing or actual trading.

    There are many factors that can change actual results. But a representative sample is all you need, as future results are never predictable. All you can hope for is trade expectancy.

    On my system using StrategyDesk, I have live trading or forward testing set to 'buy the open' on the 5 minute bar. So my backtesting is done also on 'buy the open' by always looking back at the most recent closing bar before calculating various indicator values in the trade trigger logic.

    Since my system is multi-timeframe, the backtester must also be set to 'calculate intra-bar on 5 minute intervals' for longer time periods than my system's 5 minute primary bar. Otherwise, the backtester would be calculating indicator values by looking forward to the close of those longer interval indicator values, there by providing un-representive results.

    Hope your system's backtester has these same features.
     
    #15     Oct 16, 2010
  6. borland

    borland

    To clearify I actually meant to say "I have coded my trade logic to 'buy the open' by looking back at the prior bar". So, there are no trade alert settings for 'buy the open' in StrategyDesk. StrategyDesk only has this option in the backtester.
     
    #16     Oct 16, 2010
  7. Eight

    Eight

    Tradestation will treat the current bar the same as in realtime. It will calculate the indicators to the tick, every tick...
     
    #17     Oct 16, 2010
  8. As long as you make reference only to the O of a bar in your calculations and no reference is made to C, H or L, then you can use current bar.

    The following is forward-looking

    If current bar H > previous bar H

    because the value of current bar H may change after you get a signal and your position will be invalid.

    I hope this has relevance to your question.
     
    #18     Oct 17, 2010
  9. Yes, you CAN get marginally better results.

    Marginal improvement can also be significant.

    Please think harder about your opportunity.
     
    #19     Oct 18, 2010
  10. Actually, as soon as this condition becomes true in the current bar, it will remain true for the rest of the current bar, regardless of what else happens.

    No?
     
    #20     Oct 19, 2010