A simple Pine Script MACD 200 EMA pine script strategy. Copy and paste into TradingView. Pyramids orders.
How the strategy works
Strategy buys MACD crossovers and sells crossunders. 200 EMA helps to limit counter-trend signals.
MACD 200 EMA Pine Script Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © truemiller //@version=4 strategy("MACD 200 EMA Strategy") //inputs fast = 12 slow = 26 smooth = 9 // macd macd = ema(close, fast) - ema(close, slow) amacd = ema(macd, smooth) delta = macd - amacd // macd plot plot(series=macd) plot(series=amacd) plot(series=delta, style=plot.style_histogram) // ema ema = ema(close,200) // orders strategy.order("Long", strategy.long, when=crossover(delta,0) and close > ema) strategy.order("Short", strategy.short, when=crossunder(delta,0) and close < ema)
What is the MACD?
The Moving Average Convergence/Divergence Indicator, or MACD, is an invaluable tool for stock market traders. It was developed by Gerald Appel in the late 1960s, and it’s been in use ever since. On a basic level, the MACD is made up of two lines: the MACD line (the line you’ll see on most trading charts), and the Signal line. The MACD line is made up of two exponential moving averages: a fast-moving average (the “A” line) and a slow-moving average (the “D” line). The Signal line is simply a 9-period EMA of the difference between the two lines.
What is the 200 EMA?
The 200 EMA is a moving average that can be applied to any security. It is defined as the average price over the past 200 days’ trading. Like all moving averages, it is used to indicate a trend in the data. When a security’s closing price rises above the 200 EMA, it indicates that the current trend for that stock is bullish. When a security’s closing price falls below the 200 EMA, it indicates that the current trend for that stock is bearish. The 200 EMA is calculated by taking today’s closing price and finding the average of its previous 200 days’ prices. If there are fewer than 200 days worth of data available, then it replaces missing values with an average of itself and today’s value. The 200 EMA is also known as a “simple moving average” because there are no mathematical manipulations applied to it other than taking an average of prior observations.