How to adapt lowpass or moving averages periods to market conditions?

Discussion in 'Strategy Building' started by Mithrandir777, Sep 21, 2014.

  1. You are right, I expressed myself wrong there. Instead of 'parameterless' I should have said a parameter that can readapt to the market by retraining the strategy. By lowpass I meant lowpass filters http://en.wikipedia.org/wiki/Low-pass_filter which, applied to the price series supress high frequencies (ie cycles) and let short frequencies/long periods (ie trends) pass.
     
    #11     Sep 26, 2014
    kut2k2 likes this.
  2. kut2k2

    kut2k2

    The question you ask is an important one. The problem is that the trend you can measure is entirely dependent on two unspecified parameters: the sampling rate (e.g., 5-minute data; eod data) and the sample length. I don't think you can 'calculate' the sampling rate, you have to pick one as a starting point. Once you've decided on your sampling rate (aka your "bar interval"), then there may be a way to vary the sample length depending on market conditions but that's something I'm still working on. Good luck.
     
    Last edited: Sep 27, 2014
    #12     Sep 27, 2014
    Mithrandir777 likes this.
  3. Precisely so, given that you could trade a MA crossover in a 60 minute chart that is merely a pullback in a daily.

    I would suggest one could approach this either by testing the various bar intervals (on an ongoing basis?) and trading the one that best presents cyclical tendencies at the time, or testing only those intervals that one is psychologically suited to trade (if it will be a manual system).

    Edit: I think perhaps better described as 'best presents long wave cycles' rather than merely 'cyclical tendencies'?
     
    #13     Sep 27, 2014
    Mithrandir777 likes this.
  4. kut2k2

    kut2k2

    Assuming we've gotten past the sampling rate issue, it occurs to me that we may have an apples-and-oranges issue. Lowpass filters (of which MAs are a crude form) are concerned with separating cycles of different frequencies. But a trend is at best a half cycle, either from trough to peak (an uptrend) or from peak to trough (a downtrend). Unless I'm missing something, I'm not sure full cycle analysis is going to help pick the best half-cycle to trade off of.
     
    #14     Sep 27, 2014
    Mithrandir777 likes this.
  5. Not missing a thing actually. What I was visualising was half-wave symmetry, but even if asymmetric in clear cycles, something one could still trade.
     
    #15     Sep 27, 2014
    Mithrandir777 likes this.
  6. ronblack

    ronblack

    I see no possible market inefficiencies in forex other than those already exploited by Soros years ago. If you have any specific examples, let's discuss them. But arguing that there are unicorns does not mean there are actually.
     
    #16     Sep 28, 2014
    Mithrandir777 likes this.
  7. I have been busy with studies and work the last weeks. I have added to my script a filter that measures volatility. I could have used ATR but for some reason I found Alligator interesting so here it is the script and the results, the language used is lite-c from the Zorro platform:

    Code:
    function run()
    {
    //set(PARAMETERS);
    StartDate = 2002;
    EndDate = 2008;
    NumWFOCycles = 10;
    LookBack = 2000;
    vars Price = series(price());
    var period = 500;
    vars Trend = series(LowPass(Price,period));
    
    Stop = ATR(100)*4;//optimize(4, 2, 8);
    
    vars Meanness = series(MMI(Price,200));
    vars Filter = series(LowPass(Meanness,period));
    
    Alligator(series(MedPrice()));
    var diff = FisherN(series(abs(rBlue-rGreen) + abs(rGreen-rRed)),500);
    vars diffs = series(diff);
    var Threshold = 2.5;//0.1;//1.0;//1.5;//2.5
    
    static bool Filter2;
    if (crossOver(diffs,Threshold) or crossUnder(diffs,-Threshold))
    Filter2 = true;
    if (crossUnder(diffs,Threshold) or crossOver(diffs,-Threshold))
    Filter2 = false;
    
    if( valley(Trend) ){
    exitShort(); // close opposite position
    if(falling(Filter) and Filter2)
    enterLong();
    } else if( peak(Trend) ) {
    exitLong();
    if(falling(Filter) and Filter2)
    enterShort();
    }
    }
    The results and equity curve:

    Walk-Forward Test Workshop4_2Pc EUR/USD - performance report

    Simulation period 01.05.2002-31.12.2008
    Test period 30.11.2004-31.12.2008
    WFO test cycles 9 x 2742 bars (23 weeks)
    Training cycles 10 x 15538 bars (134 weeks)
    Monte Carlo cycles 200
    Lookback time 2000 bars (17 weeks)
    Assumed slippage 10.0 sec
    Spread 2.3 pips (roll -0.10/0.04)
    Contracts per lot 1000.0

    Gross win/loss 117$ / -44$ (+941p)
    Average profit 18$/year, 1.48$/month, 0.07$/day
    Max drawdown -34$ 47% (MAE -42$ 58%)
    Total down time 41% (TAE 9%)
    Max down time 68 weeks from Jul 2007
    Largest margin 5.00$
    Trade volume 17479$ (4278$/year)
    Transaction costs -3.02$ spr, 0.10$ slp, -0.88$ rol
    Capital required 34$

    Number of trades 17 (5/year, 1/week, 1/day)
    Percent winning 41%
    Max win/loss 42$ / -16$
    Avg trade profit 4.28$ 55.4p (+215.8p / -56.9p)
    Avg trade slippage 0.01$ 0.1p (+0.6p / -0.3p)
    Avg trade bars 151 (+346 / -14)
    Max trade bars 542 (4 weeks)
    Time in market 10%
    Max open trades 1
    Max loss streak 6 (uncorrelated 6)

    Annual return 52%
    Profit factor 2.65 (PRR 1.25)
    Sharpe ratio 0.75
    Kelly criterion 1.08
    R2 coefficient 0.385
    Ulcer index 6.0%
    Prediction error 125%

    Confidence level AR DDMax Capital

    10% 103% 14$ 17$
    20% 93% 17$ 19$
    30% 85% 18$ 21$
    40% 82% 20$ 22$
    50% 77% 21$ 23$
    60% 73% 22$ 24$
    70% 67% 25$ 27$
    80% 62% 28$ 29$
    90% 55% 32$ 33$
    95% 50% 36$ 36$
    100% 33% 58$ 54$

    Portfolio analysis OptF ProF Win/Loss Wgt% Cycles

    EUR/USD .166 2.65 7/10 100.0 ./XX//\\\
    EUR/USD:L .169 3.14 5/6 88.4 ..\///\\\
    EUR/USD:S .147 1.60 2/4 11.6 .//\...\.

    [​IMG]

    As you can see, I used Alligator lines closeness as a measure of volatility, I normalize their differences and when they go out of a threshold (which is higher the less volatile the market is, this threshold can be adapted to market conditions, maybe using equity curve trading for that) I consider it a signal to buy or sell.

    This has turned the loser system into a winning one with good Sharpe Ratio for a trend system and an ulcer of 6%. What do you think? Do you think It has any bias or curve fitting? I look forward to hearing your inputs. Thanks!
     
    #17     Oct 5, 2014
  8. You can compare the distribution of EUR/USD with flipping a coin and you can see that there are differences between them to be exploited, in the following chart in the x axis you can see the amount of hours the prices or the random values have been raising (or falling in the case of negative values) and in the y axis the amount of cases. This was done considering the last 6 years. It can be seen that for prices it is more often to have long hours of rising/falling prices than in a random process and also that there are more 1 hour rising/falling prices in the random process than in the EUR/USD prices.

    [​IMG]
     
    #18     Oct 5, 2014
  9. The symmetry is quite remarkable. It would be lovely to see a similar plot with duration in days. Also, is it at all possible to relate volatility to this?
     
    #19     Oct 5, 2014
  10. %%%%%%%%%%%%%%%%%%%%%%%%%
    '' a way to adapt the moving average?????''Yes something like that,trader 777.

    There are many different kinds of 200 day moving averages;
    explore,meditate, think again/think again[mind in gear, NOT mind out of gear].,explore them all; all data.


    50 day, 50/+ week moving averages....... worked well during 1901-2013+ ..... that includes2002 - 2008.You can probably improve on those,;
    people seldom share thier best on internet.Thank you IBD[Investors Business daily /William O Neil, for 50 days moving average+ price, 50 days[moving average ] volume, 200 dma.....................................................................................
    Moving averages do not fail, unless you get bad data-that seldom happens bad enough to cause a loss; but you should know SPY, or whatever you trade/invest in to work around it[occasional bad data].

    Wisdom is profitable to direct.
     
    #20     Oct 8, 2014