All SMA/EMA trade entry situations

Hello, I am trying to program a brute force backtesting program, where trade entry conditions are based on SMA/EMA combinations.
For example favourite use is if short sma crosses long sma from the bottom, it might suggest an uptrend. In this case my program will backtest several different sma’s, for example every combinations of sma10-50, crossing sma60-100.

I am looking for other entry signals based on sma/ema, which I can test in simmilar fashion and there can be more conditions, like short sma crosses long sma and 3rd sma is (10-50)ticks above price, which could indicate a different market situation, etc.

I am trying to flip through milions of sma patterns, which should include different market situations and count how successfull they are.
Any more widely used sma aplications, that can be tested in similar manner?

Sounds like curve-fitting algorithm. Some are pro some against.
What do you use for this MT4/5 or custom written software ?
Ah, and also what kind of data do you feed into ? bars or real quotes ?

If you backtest enough variations of this, methodically and accurately enough, over large enough samples, two things are certain:-

  1. You’ll come up with one which is “the most profitable of the lot” (and it will show a net profit over the sample of data tested).

  2. It will be no more or less likely than any other specific SMA-combination to remain profitable moving forward, because it will be totally curve-fitted

In the long run, although moving averages have some useful aspects and valid uses, using them as a trade-entry method in themselves isn’t one of them, and this reality is among the several reasons why what you’re proposing to do (to put it very politely) isn’t a good use of your time and effort.

2 Likes

Thanks for reply, I will have other mechanisms to reduce curve fitting, we will see how that goes, but for now, I am looking for the methodology itself, how to define range of sma combinations, that would theoreticaly include as many as possible market situations. Any suggestions what to pair SMA with, in my use? - Yes it is basically a curve fitting, but I will try some other stuff on top of that to reduce it.

I am using my own software, and I am fitting 1 minute ohlc bars.

Far from reducing it, that will increase it.

No disrespect, but you seem either not to be listening to what people are telling you, or you don’t quite understand it.

I advise you not to fall into the well-known trap of imagining that compounding a moving average crossover with another indicator as well is going to make the outcome any less curve-fitted.

Moving averages can certainly be helpful for defining “trend” within a specified time-frame and therefore for determining overall directional bias, but to imagine that a backtested MA crossover used as a trade entry method will have predictive value for future trading is based only on a fundamental misunderstanding.

1 Like

Well, you got to start somewhere. Some say, SMA crossover is more for exit then entry.
I would throw in some EMA, some BB channel, paint candles with shades of red for high volume.
Do you have your own custom charting too ? (C++, Java, what do you got) ? just curious :slight_smile:
Also, the position size can bend the curve. If you play small, no harm in there.

Hi stanoo - Instead of focusing on the trade entry conditions, give more consideration to what the ideal position should look like AFTER you’ve entered. Say 10 bars after you’ve entered. This will then indicate to you the right sort of entry signal to look for and how it should perform. It will also indicate opportunities to add to or pyramid your position.

Using this approach from back to front as it were, your focus should switch from signals to trends, and that’s were the money is.

I do use MA’s for judging trend strengths - both when comparing existing trends on different markets and also for judging that an existing trend is strong enough to justify entry. The actual entry pattern isn’t that important - certainly not important enough to make your strategy rely on a particular pattern or patterns.

2 Likes

Absolutely.

But it’s kind of questionable whether someone intent on backtesting a huge variety of MA crossovers used as trade entries is really going to hear that.

2 Likes

To better explain my reasoning(im a begginer so pls correct me at any point): There are bilion different systems, traders, aproaches indicators etc. and every one of them can more or less be easily defined as enter position IF(some condition, which descibes some situation market is in), exit position IF(some condition) - even if the trader thinks about his trading as some sort of art, he must have this atleast unconsciously defined (if not, he is not very consistent with his trading). I find the aproach of picking one spend 1000hrs trying it, maybe slightly modifiing it based on gut feeling statistics and then maybe switching to different one not very reasonable.

So I want to go through milions of these, and let the program tell me which one does the best. I’ve started with sma, (one of the reason is simplicity for programing) the other is that if I look at any indicator or any trading aproach, it somehow look at the previous trend/market state, which I think could be descibed with some state of MAs, price(which is basically MA 1 period), or some combination of that (not necessary a crosover, was just an example).

If I define the different possible market situations (I was thinking I can do it with MAs somehow, like descibed above, like in example MA crossover descibes certain situation ), I can try entering market on those states, same for exits.

For now I’ve started with SMAs combinations for entry and simple stoploss /profit target for exit, around 120 mil combinations of entries/exits. To reduce curve fitting, I do backtest on some time period, pick the best and try walk forwarding it to some forward period (Here I also try different combinations). I don’t pick the one with best result - the most curve fitted one, but I check also surrounding “systems”. For example to pick system with exit PT of 100, I am doing average of results from PT 90 100 110, so I won’t get the most curve fitted. Same for SLs and entries, so currently it does average of 243 “surrounding systems” when choosing “the best”.

So I want to do backtest of a lot of systems - market situations where to enter/exit position (this is my main question, how to define the range of those systems, my first thought was I can do it by some sort of MA states and combinations), pick “the best” (this is also a question how to pick the best, currently I am doing that average of 243 surrounding systems), then trade it for some time (I am simulating this with walk forward), hoping that if it (and surrounding 243 systems), did good in a X backtest period, It will do half as good in Y forward period/live trading.

If the MAs are not enought to define an entry pattern, I am open to suggestions.

"give more consideration to what the ideal position should look like AFTER you’ve entered. Say 10 bars after you’ve entered…This will then indicate to you the right sort of entry signal to look for " - Isn’t it basically the same? I defined that ideal position after I entered should be profit of some sorts:P, and I am looking which sort of entry signal will provide that.

I know exits are as important as entries, for now it’s sl/pt but open here as well, but must be defined same way as entries, some range of conditions where I can test which produces best result.

“Do you have your own custom charting too ? (C++, Java, what do you got) ? just curious” - I have no cahrting, it’s just my home freetime project to learn to code with a hope I can do some real stuff with it afterwards. I use c++ and CUDA (nvidia programing language for GPUs - small massivelly parallel supercomputers:P)

“No disrespect, but you seem either not to be listening to what people are telling you, or you don’t quite understand it.” - What I ment on top was that walk forward and picking surrounding systems as well, not necessary adding another indicator to curvefit it more.

Please take all my thoughts just as a current thoughts of a begginer and I’ll gladly listen to any suggestions.

Positions are not the same as entries. They are far more important.

Exits are not as important as entries.They are far more important.

Profit targets (as exit signals) are a great way to keep your profits small.

That said, I do believe all new traders should start with MA’s as their only indicators and work from there.

Those aren’t “trading systems” at all. Those are the output of people who don’t understand what trading systems are, and wrongly imagine that “when you enter” is the most important thing. As long as one subscribes to that frankly deluded perspective, it’s pretty hard to make any real “progress” at all.

What’s far more helpful is to learn about the things that are actually important.

It’s an easy trap to fall into. Intuition tells some/many people that “if they enter at the ‘wrong’ times, they can’t possibly profit”, and because that’s technically true, it makes it easy for them to imagine - totally wrongly - that if they make good entries at good times and in the right direction, the odds will be in their favour, and everything else will work out ok. This is, of course, completely untrue. And a terrible, time-wasting, deluding, inappropriate approach to learning how to trade.

It isn’t really possible to help you much, until you change your mind about that.

I can recommend books which explain why it isn’t really possible to help you until you change your mind about that, but that isn’t something that anyone can realistically do in a forum post.

Your entire perception of what a “system” is, at the moment, is too misguided to make it possible for people to help you, really. No criticism implied at all, even if it sounds that way! It’s where many of us started off.

Suggestion: read “Profitability and Systematic Trading” by Michael Harris, and “Beyond Technical Analysis” by Tushar Chande, before trying to DO anything.

2 Likes

Thank you for your replies and for your patience, I will deffinitelly have a look at those books. I know that I haven’t read the books yet, so I still don’t understand it and if you have patience to correct me again, please do. If I look at trading, isn’t it in the end mostly about looking at the market situation/state (which might be to some degree described by indicators) and decide whether click buy/sell button? Once for entry (I know it might be negligable compared to exit, but probably not many traders trade by the flip of a coin, so let’s not dismiss it) and then you are looking for a market situation when to exit. ( growing or lowering position in mid of trade, or moving SL is basically the same as introducing second entry-exit pattern to the mix, as you are again looking for certain situation ).

Why is it that ill minded (if it’s in the end about when to click buy/sell) to try backtest loop through different entry-exit conditions, pick the best (not necessary simply the one with highest profit on the curve), try it on forward period, which is not backtested, thus the chosen one was not curve fitted to that data, repeat. If I do for example (numbers not important here) 6months backtest, pick “the best”, forward it 1 month (backtest the chosen one on next 1 month where is is not curve fitted at all), repeat. On 3y data I would get 28x result of a situation that would tell me what would have happened If I would do 6months backtest and live trade the chosen one for a month, every month. If I get 28 times average (hopefully with not extreme variance between them) result of “my chosen enter-exit combination had on average 1000 profit a month during backtest and just 300 during forward/live trade”, I find that statisticaly pretty significant.

Theoretically if I would loop through all possible (that would be around infinity:P) entry-exit conditions, I would have trading aproaches of all the most successfull traders included, even better one (just from statistical perspective, that noone found the best from infinity:P) and do the above.

Is this totally ill minded and I simply need to read the books? (I will do that either way) Why?(If someone has the patience to explain).

If it’s not totally ill minded, I am mainly looking for a suggestion how to define the range of entry-exit conditions to loop through in this manner. (my initial thought was that I can catch enough valid ones with MA combinations/crossovers/whatever as entry and simple SL-PTs as exit). Even if it is simply totally wrong aproach, don’t mean to be stubborn, but I would still be gratefull for some suggestions here, as this is also a programming excercise for me, so I can code something until I’ll read some more about this.

Start with a slow and a fast SMA, and increase/decrease the period towards each other until they become equal, where you stop. When the 2 SMA are close one to the other they will cross very frequently, especially on 1m bar or when using real quotes. If that’s the case then one idea is to use a -30 pips SL and trail it at 15 pips until when positive it will become your TP.

About CUDA, I don’t know. For me, it will mess my code. I don’t like to separate my strategy into .cu/.cuh non c++ calling convention. All pointer allocations are slow, but obviously not enough to beat the parallelism speedup. From the small tutorial I read on CUDA, I didn’t get too much, like the stack per thread on the device, what you can and cannot do with the memory there, etc.

OpenMP would be much cleaner and does not need a separate compiler. It’s does run in parallel but on CPU. For me that would be CPU=8 cores, CUDA=196 cores, so a clear disadvantage for omp.

Maybe you can post here your findings. I would be interested of course to hear more.

TradingResult.txt (93.0 KB)

Here is a backtesting result for 2017 with live quotes, 2145 different SMA crossover versions, from SMA(2, 1H) up to SMA(48, 1H) and SMA(2, 1D) up to SMA(20, 1D). The results are sorted by PL, from the best to the worst. :slight_smile:
Took about 1.5 hour to finish.