Free: indicator teardowns, a repaint checker and open-source scripts. No buy/sell signals, ever.

Taught to TradeSystems over signals.

Explainers / MACD + SMA 200 Strategy by ChartArt

MACD + SMA 200 Strategy by ChartArt, explained from the source

MACD + SMA 200 Strategy (by ChartArt) is an open-source TradingView strategy by ChartArt, dated November 2015 in its code, with about 32,300 boosts. Its notes say it goes long when the MACD histogram and "MACD momentum" are above zero, the fast MACD average is above the slow one, and recent price is above the 200-bar average, and short on the mirror. This page walks through the published code in order, says what each part really does, and ends with where it fails. It does not say whether the strategy makes money, and it gives no trades.

The surprise: this MACD is not the usual MACD

The standard MACD subtracts a 26-period exponential average from a 12-period exponential average, and its signal line is a 9-period exponential average. This script uses simple averages for all three. The names and the numbers 12, 26 and 9 are the same, so the lines look familiar, but they cross at different times. On one invented series of 5,000 bars, the simple-average histogram crossed above zero 176 times and the standard one 223 times; only 15 of the 176 crosses fell on the same bar, and 75 within two bars. If you compare this strategy with the MACD panel on your chart, they will not agree.

Step 1: the averages

Three simple moving averages of the close: 12 bars (the "fast" one), 26 bars (the "slow" one) and 200 bars. The MACD line is the 12 minus the 26. The signal line is a 9-bar simple average of the MACD line, and the histogram is the MACD line minus the signal.

Step 2: when it enters

A long order is sent on a bar where all of these hold:

The second and third lines are the same test written twice: the MACD line is the 12-bar average minus the 26-bar average, so it is above zero exactly when the 12 is above the 26. The "MACD momentum" in the notes is not a separate calculation in the code.

The fourth line compares an old close with a current average. The notes call it "the recent price". In our port it gave a different answer from today's close on only 9 of 1,359 long signals, so it rarely matters, but it is not what the notes say.

A short order is the mirror: the histogram crosses down through zero, the MACD line is below zero, and the close from 26 bars ago is below the 200-bar average.

Step 3: how the orders fill

Each order is a stop order. A long is a buy stop at the signal bar's low, and a short is a sell stop at the signal bar's high. A buy stop fills once price trades at or above its level, and price is already above the low it was placed at, so the order fills at the next bar's open, like a market order. In our port, on bars that open where the last one closed, every order filled at the next open. Only when the next bar opens beyond the signal bar's range (a gap) does the order wait. We read this from the code and TradingView's documented order handling; we did not watch it fill live.

Step 4: the "cancel" lines

The code cancels a waiting long order when the 26-bar average is below the 200-bar average, and a waiting short when it is above. Because almost every order has already filled at the next open, there is rarely anything to cancel. In our port it cancelled nothing on gapless bars, and 2 orders in 50 runs with small opening gaps.

Step 5: when it exits

It has no exit. There is no stop loss, no target and no time limit. A long is closed only when a short entry fills, and the other way round, so after the first trade the strategy is always long or short. The last line sets a maximum intraday loss of 50% of equity, which stops trading for the rest of a day if the day's loss reaches half the account. We read that from the code and did not test it; a 50% loss in one day is rare, so it seldom acts.

Step 6: the colours

The background turns green on the long signal when the 26-bar average is also above the 200-bar average, and red on the mirror, so it nearly matches the entries (12 of 1,359 long signals in our port came while the 26 was below the 200 and drew no colour). The bar colours and line colours follow other rules, built from where the close sits against the three averages and the slope of the 26 or 200 average. They describe trend, not trades.

What the settings change

The MACD fast, slow and signal lengths (12, 26, 9) and the very slow length (200) change the trades. The three switches only turn the colours and the average lines on and off. "Max Intraday Loss(%)" sets the 50% limit above. The order size and costs are the strategy tester's defaults unless you set them.

What we checked in Python

We ported the logic to Python and ran it on invented random-walk prices with a typical move of 1% a bar: 50 runs of 5,000 bars at the default settings, once with bars that open at the last close and once with small opening gaps of about 0.3%.

The filters thin the signals hard. On one series, 169 histogram crosses above zero became 48 once the MACD line had to be above zero, and 20 once the old close had to be above the 200-bar average.

Most signals do nothing. About three in four signals arrived while the strategy was already in a trade the same way, so they changed nothing.

Few trades. A median of 13 position changes per 5,000 bars (7 to 20 across runs), and the strategy was in the market about 95% of the time. A backtest built on a dozen trades says very little, whatever its profit figure.

Random prices, coin-flip results. 23 of the 50 gapless runs and 20 of the 50 gapped runs ended with a positive sum of trade returns. On prices with nothing to find, that is what chance looks like.

Tuning to the backtest. For each of 20 random series we picked the best of 36 settings (fast 5 to 16, slow 20 to 40, very slow 50 to 200). The chosen settings showed a profit on all 20 series they were picked on (median +64% summed). Run on 20 fresh random series, the same settings were positive on 7 of 20, median -18%. Choosing settings by the backtest makes the backtest look good and tells you nothing new.

These figures describe the code on invented data, not any market.

Where it fails

Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. MACD + SMA 200 Strategy (by ChartArt) is by ChartArt on TradingView; this page describes its published open-source code in our own words and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the script trades on any market.

Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue, Volume Flow Indicator by LazyBear, FVG Order Blocks by BigBeluga, CM_Williams_Vix_Fix by ChrisMoody, Bollinger + RSI Double Strategy by Chart, Ultimate Moving Average MTF by ChrisMood, Fibonacci Bollinger Bands by Rashad, Candlestick Patterns Identified by repo3, Pine Script v5 to v6, Moving Average Cross Alert, Multi-Timefr, WaveTrend Oscillator [WT] by LazyBear, WaveTrend with Crosses [LazyBear], CM_Price-Action-Bars by ChrisMoody, RSI Candles by glaz, CM RSI-2 Strategy Lower Indicator by Chr, CM Stochastic Multi-TimeFrame by ChrisMo, CM_Ultimate RSI Multi Time Frame by Chri, TonyUX EMA Scalper - Buy / Sell by tux, MACD 4C by vkno422, My Pine Script is valid. What did the va

Next steps

  • Get a script fixed. Compiles but behaves differently live, or changes after a reload? In a Pine Script Audit, an AI model reads every line and writes a report on what to fix for $49, or also fixes those problems for $149. It cannot prove a script is safe.
  • Check your own script. Paste its source into the free repaint checker. It runs in your browser and flags known patterns.
Before you trust its backtest: the Integrity Checklist, $19 one-offBack to Taught to Trade

No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.