Explainers / Moving Average Cross Alert, Multi-Timefr
Moving Average Cross Alert, Multi-Timeframe (MTF) by ChartArt, explained from the source
Moving Average Cross Alert, Multi-Timeframe (MTF) (by ChartArt) is an open-source TradingView indicator by ChartArt, published in September 2015, with about 21,000 boosts. It draws two moving averages, colours the bars and the background when they cross, and prints "Buy" and "Sell" arrows. Its notes say the averages can be plotted from another timeframe, such as the weekly. 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 indicator makes money, and it gives no trades.
The surprise: the weekly setting does not give a weekly moving average
Untick "Use Current Timeframe" and pick weekly, and you might expect a 50-week and a 100-week average. The code does something else. It asks the weekly timeframe for one thing only, the price, and then averages that price over the last 50 and 100 bars of the chart you are on. On a daily chart the weekly price is the same number five days in a row, so the "50" average covers about 10 weeks, not 50, and the "100" covers about 20.
In our Python port, with a higher timeframe of five chart bars, the script's lines crossed a median of 44 times per 5,000 bars. A real 50 and 100 average of the higher timeframe crossed a median of 10 times. Only 74 of 504 real higher-timeframe crosses had a script cross within five chart bars. The two are different indicators with the same label.
Step 1: the price
The script takes one price (the close unless you change it) from either the chart's timeframe or the one you pick. With the box ticked, which is the default, nothing special happens: it is the chart's own close.
Step 2: the two averages
A short average (50) and a long one (100) of that price. A setting from 1 to 4 picks the kind: simple, exponential (the default), weighted, or "Linear". The fourth is not an average. It is the end point of a straight line fitted through the last 50 or 100 prices, which moves faster than an average and can sit outside the range of the prices it was fitted to.
Step 3: the colours
Each line is lime when it is higher than one chart bar ago, red when lower. Bars are green while the short line is above the long one and red while it is below. The background flashes on the bar where the order flips, and a black cross is drawn at the crossing level.
Step 4: the Buy and Sell arrows
A "Buy" arrow needs two things: the short line moved above the long line on this bar, and this bar's close is above the last bar's close. "Sell" is the mirror. So a cross on a bar that closed the other way gets a background flash and no arrow. In our port, at the defaults, 1,593 of 2,333 crosses got an arrow (68%). About one cross in three has no arrow, and bar colours still flip on every one of them.
The close in that test is always the chart's close, even when the averages use another timeframe or another price source.
Step 5: there are no alerts in the code
The title says "Alert", but the code has no alert conditions. The alerts are the colours and arrows on the chart. To be notified you would have to add your own.
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, each bar built from 10 smaller steps: 50 runs of 5,000 bars.
Crosses on random prices. At the defaults the lines crossed a median of 46 times per 5,000 bars (33 to 66 across runs). These prices have nothing to find, so every one of those crosses is noise. A cross tells you the averages crossed and nothing more.
The live bar flickers. The averages use the current price until the bar closes. For every 10 crosses that held at the close, about 2 more showed inside a bar and were gone by its close (500 against 2,196). On a closed chart you only see the ones that held.
History with another timeframe. The code has no version line, which makes it the oldest kind of Pine. TradingView's documentation says scripts from before version 3 read another timeframe's value on past bars as it stood at the end of that bar, not as it was known at the time. If so, on past bars the script sees each week's final close from Monday. In our port that moved crosses a median of 5 chart bars earlier on history than they could have been seen live (2,272 matched crosses, 24 on the same bar). We read this from the documentation and the code; we did not watch it on a live chart.
These figures describe the code on invented data, not any market.
Where it fails
- The timeframe option is not a higher-timeframe average. It averages a stepped price over chart bars, so "50" on weekly from a daily chart is about 10 weeks.
- Past bars may look earlier than live. With another timeframe chosen, old Pine lets past bars see the higher bar's final price before it closed.
- Arrows skip crosses. About one cross in three in our port had no arrow, while the bar colour changed anyway.
- The close test ignores your settings. Arrows compare chart closes even when the averages use another timeframe or price.
- The live bar can show a cross that disappears. About 2 vanished for every 10 that held in our port.
- "Linear" is not a moving average. It is a fitted line's end point and behaves differently from the other three.
- No alert conditions. Despite the name, nothing in the code can raise a TradingView alert.
- Crosses happen on noise. Dozens per 5,000 bars on random prices, so a cross alone says nothing about what comes next.
- Old code. Written for the first version of Pine and not updated since 2015.
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Moving Average Cross Alert, Multi-Timeframe (MTF) (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 behaves 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, MACD + SMA 200 Strategy by ChartArt, Pine Script v5 to v6, 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
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
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.