MACD Crossover trend strategy, Long and Short

conflixx95493 Updated   
Hey everybody,

This is my first strategy and script I wrote mostly myself. There's tons of content out there to learn how to code in Pinescript and it's exactly what I wanted and needed in this time of my life.

In any case, I made a rather simple MACD crossover strategy that only takes trades in the direction of both EMA and SMA (there are inputs to change the length of the moving averages and lots of other stuff too).
If the MACD line crosses upwards on the signal line, while above the zero point of the histogram and the price is above EMA + SMA , it's a long signal.
If the MACD line cosses downards on the signal line, while below zero on the histogram and the price is below EMA + SMA , it's a short signal.

There are a lot of default variables that make no sense, for basically any symbol you're going to be looking at. You're going to have to adjust the EMA , SMA , backtest date, take profit, stop loss and all that good stuff yourself to find decently profitable parameters.

I made this myself because I couldn't really find a strategy out there that allowed for so much customizing and it's an easy way to get started in Pinescript.

If you have any suggestions, tips or you see a flatout mistake in my code, please let me know. I'm still learning, everyday and I'm enjoying every second of it.
Release Notes:
Initially I wanted to rewrite my MACD script and release a new one. Eventually it ended up looking too much alike and I've decided to just overwrite my previous MACD strategy.
My previous MACD script only had one option, it had a static stop loss and take profit. This is bad, I knew this from the beginning but I had to start somewhere. Now that I know how I can go around fixing that, I've decided to just overwrite my previous MACD script.

This script gives you two options, the entry signal is always the same, it's been the same in my previous script and it's the same now. The exit signals are vastly different though. Previously it was a static stop loss and take profit, now I changed it to either pullback decided by the 20 period high or low(basically Donchian Channels, which is why I say they're mixed). The other option is where we let the MACD indicator do all the work, if we're in a position(either long or short) when the MACD inversely corsses the signal line that means we exit our position.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?