Moving Averages with Machine Learning Boosting

Discussion in 'Technical Analysis' started by tomascamara, May 8, 2018.

  1. If this is for your master's thesis, I recommend you to familiarize yourself with the field of optimization. Particularly, search based methods would be useful here.

    There are also plenty of existing published papers out there to research.
     
    #11     May 9, 2018
    tomascamara likes this.
  2. From what I have been taught, what I’ve read, what I’ve noticed in forums this is my thoughts concerning MAs.

    So typically when people use moving averages the ones that have rational thinking use 5(one week of data) 10(two weeks) 20(aprox a month) 50(2ish months) 100(Aprox 1/2 year) 200(aprox 1 year). Obviously they won’t be choosing all of them to chart but those seem to be the most popular they have most significance tied to rational thinking on daily charts. Since they’re more popular on the daily charts people have scaled those into multiple time frames. Thus a 20 MA will not always represent 20 days but, 20 bars/candles would be more accurate. Example someone trading hourly candles 20 MA will represent 20hrs.

    Often times MAs are used for trend identification, support/resistance and not necessarily for trading decisions itself. MA crossovers are probably the easiest and most basic form of using indicators. You’re somewhat right those that use MA crossovers for trading decisions will tend to choose numbers that seem random. This is most likely because those designing those systems are trying to optimize the results. Therfore they’re playing with all sorts of numbers and trying to identify numbers that would give the least false signals. Basically they’re looking for crossovers that are sensitive to prevent late signals, yet they’re trying to create cross overs that aren’t so sensitive they’re creating too many false signals.

    The problem with MA crossovers is they could possibly work if markets didn’t range, and went right into the opposite trend mode. If you study markets however you’ll notice that markets range and correct even within trends. They also range between trends. MA are notoriously bad in ranging markets giving false signal. Since a 2 MA crossover strategy tends to be an always in proposition, there is really no risk reward known before entering the opposite position. Of course you can always use a 3 MA system to eliminate an always in approach.

    I could also see trying to optimize the system further by training or inputting data to the computer that would wait for prices to correct after a cross over signal is given giving a better entry. One of the flaws of crossovers is they’re late and tend to signal at swing extremes giving bad fills.

    Personally if I were to explore MA crossover approach I’d probably design a 3 MA cross over system and do the opposite of what MA cross over traders do. For example I would most likely use a long term MA say 200 just for trend identification. Second I’d only take cross over signals in the direction of the greater MA. Three use two shorter term MAs say the 10 and 20 when 10 crosses the 20 downward(assuming price is above the 200MA an uptrend) signaling a correction, I’d be looking to buy the correction not sell. Of course exiting parameters would be a little hard to define as and upwards crossover for a sell signal in my system would be early since price action tends to run above moving MAs while in an uptrend. This is where you wonder if you could apply machine learning, where it could help you determine the optimal time to sell based on such factors: how long was the cycle of the last leg and at how many deviations above the MA would present the best time to sell based on statistical averages.

    I could also see a systematic investment approach where someone might try to juice returns by doubling the systematic invested amount. For example if someone wants to systematically invest $200 a week on average in an index, they could simply invest $150 a week when weekly price is above 200MA and up the the systematic contributions to $300 when it falls below.

    But as others have mentioned the market timing approach has been explored by many people and there’s nimbers of books on it. Basically it Comes down to this, the best 10-20 days in the market produces the annual return. If you’re out of the market or on the wrong side of the market on the markets best days, you’re screwed.

    Then again those who apply technical analysis successfully(not referring to MAs here). Aren’t doing it to time the markets and produce outsized index returns. They’re doing it because the found some kind of statistical strategy that makes money. Sometimes they outperform the index, other times they’re used for consistent returns and/or non correlated returns. Sometimes they need less capital tie up there many reasons. For example someone may be happy averaging 10-20% a year with minimal drawdowns. Sure years that the indexes average 40% this is underperforming but gaining
    That during years when markets are negative or flat is also very appealing.
     
    #12     May 9, 2018
  3. trader99

    trader99

    Have you considered exploring the use of deep learning models especially RNN, LSTM GRU to model prices and predictions?
     
    #13     May 11, 2018
  4. Had one course about vba, but i don't feel comfortable programing in vba. I'm currently doing in R. What do you think?
     
    #14     May 11, 2018
  5. userque

    userque

    I've experimented with creating models in Excel using MA crossovers (and other indicators/systems); and I've optimized it to find the 'best' parameter set. I'm sure it can be done in R (I did a quick google search), but I personally haven't used R.

    Using R, you can brute force the parameters to find the 'best' set since the search space is small and integers. Or you can use a solver/optimizer.
     
    #15     May 11, 2018
  6. To get a useful reply your first post should have included your objective.
    Otherwise, people replying are only shooting in the dark.

    is it to have a good thesis?
    Is it to have solid test of a trading system over random?
    What time frame and what instruments?
    What market period?

    IF you are trading stocks then certain MA crosses are for trend change (with the divergence for trend direction eg shorter above longer is up IF there is an appreciable slope to the MAs).
    Others -shorter time frame - for entry.
    Exit can be done with stops and profit targets.

    (Some people use MAs as support/resistance as mention in a prior post)

    Until you decide what you are trying to accomplish the selection of the periods is secondary.
     
    Last edited: May 12, 2018
    #16     May 12, 2018
    tomascamara likes this.
  7. Hi aquarian!

    You are right when you say that I should be more specific. So here it goes!

    I'm finishing a masters degree in Mathematical Finance. This is a new master in my university (my class will be the first one finishing it) so I'm still very suspicious wondering at what level are all teachers truly comfortable dealing with these kinds of models specific in this field ( but they are all excellent mathematicians :)...)

    Regarding my theses.... They gave me a lot of liberty to explore anything that a want. Since the beginning of this master that I'm very fascinate with algo trading. So I've told them that initially, I would like to study the basis of Technical Analysis. And this is what I thought of doing.

    1) Starting with Moving Averages(MA) (because this is one of the most obvious ones, I believe...). Creating in R a script with MA. Then I would create a dynamic portfolio with only one stock, and implement a trading idea around the MA. Then I would have to find the best (short,long) pair of MA in order to optimize my portfolio results ( I will compare it with the Buy and Hold Strategy and see which one is better). To find the best (short,long) pair of MA I'm thinking about applying three different methods.

    a) A simple grid. Just by choosing a grid and test all (short,long) in the grid and get the best one.
    b) With a larger grid, but instead of going one by one, testing only a few, inside the gird, chosen randomly.
    c) Trying to apply some learning methods.

    The idea is to compare this three methods taking in consideration the performance comparing with the Buy and Hold strategy and SPEED. For example, the method a) can probably give better results compared to b) since it will see all combinations of (short, long) but it can take a lot of time for a reasonable large grid. Since b) doesn't look to all dots in the grid, it will be faster but sometimes it can miss some good pairs of the grid.

    Then i would like to introduce some other technical indicator and see the impact ( hopefully positive) that it can have in my portfolio.

    I've already have the grid method, so a). I will start soon trying to do b) ( doesn´t seem rocket science). And then I'm trying to choose a learning method which i haven't been able to do it yet.

    Thks a lot to EVERYONENE for all your help.
    Tomás
     
    #17     May 14, 2018
  8. FxBeachbum!

    This was super useful. I will use a lot of your tips because I truly believe it can help me with the problems that I'm currently having.
    With this two MA, the way I've done it, it seems to have created a "conservative" portfolio. It seems to be good exiting from sudden drops in value but also it blocks me sometimes when the stock is rising in values, limiting my profits. So, I will look for more information about these 3 MA that you were talking ( So creating 1 of them to analyze the "long" trend and maybe minimizing my number os signals. For example, if the long term trend is rising for a long time now, a sudden drop in value shouldn't have to have the same reaction by the "trader" or "algoritm" as one that has a flat, or falling, long term trend, rigth?). The other thing that a have to look is how much to invest when given the signal, and how much to take out when the exits signal is given.
    I'm also thinking in switching to exponential moving average because, from the very little that i've read, i understood that it takes the "present" in more consideration. And that seems to be very reasonable to use.

    I would like implement, alongside the MA, other technical indicators to hopefully get better results. Do you recommend or have a preference for any other?

    Once again many thanks for your help.
    Tomás
     
    #18     May 14, 2018
  9. srinir

    srinir

  10. Ya overall you’re right about the longer term one being about the trend identifier and the shorter two be your entry/exit signal. Overall I’m not a fan of the Moving Average cross over system. Its why I would suggest maybe using it only to make one aware and not trade directly on the crossover, because they can lag. Also in a sideways or rangebound market what they’ll do is whipsaw around. Overall I’m also not a big fan of other indicators. Most people in this forum will probably be fans of price action. Pure raw price data since all indicators are really set number of price inputs into an equation they tend to lag. Then you have the issue of some indicators are for trending markets and others for range bound markets. It’s quite about of learning to understand Price action so idk if you could have time to incorporate that into a system. I know the ADX indicator measures the strength of trends and Bollinger bands measure standard deviation from a preset # which is actually a MA or EMA depending how you set it.

    So your two issues with a crossover system are how to get a better entry/exit and how to avoid whipsaws. When I was new to TA(technical analysis) I noticed studying MA crossovers they would get bad fills on entries, many times strong price movement up would create a cross and prices would correct shortly thereafter. Then same thing with an exit during an uptrend price action will run up above the MAs so by the time a cross is created price action actually creates a sell signal after giving up a lot of gains. All and all I don’t have a lot of faith in MA crossovers but what I recommended was what I’d try if I had to use them. So maybe trying to use candle counts and deviations of average price to time the exits better so you’re not giving back a lot of profit. Hopefully you could have the computer learn that stuff.

    But my thoughts are during an uptrend prices coming back to MAs or average prices would represent buy signals or times when an investor would be safer or have less short term risk if they were to buy there. it would take less time for their investments to be profitable and less likely smaller corrections, and short term down moves could create a loss of capital.

    I don’t know the exact details of your assignment but in the end I’d have to agree that trying MA crossovers alone won’t outperform Buy and hold. So if you can’t outperform with a crossover method without figuring out how to work around it’s flaws maybe it can be used to inform a B&H investor when to up their systematic investments.
     
    #20     May 15, 2018