ChartArt

Moving Average Cross Alert, Multi-Timeframe (MTF) (by ChartArt)

See when two moving averages cross. With the option to choose between four moving average calculations:


The moving averages can be plotted from different time-frames, like e.g. the weekly or 4 hour time-frame using HL2 , HLC3 or OHLC4 as price source for the calculation. In addition there is a background color alert and arrows when the moving averages cross each other when the price also rises or falls. And the moving averages are colored depending on their trend direction (if they are trending up or down).
즐겨찾기 스크립트에서 빼기 즐겨찾기 스크립트에 넣기
study("Moving Average Cross Alert, Multi-Timeframe Option (MTF) (by ChartArt)", shorttitle="CA_-_MA_cross", overlay=true)

// ChartArt's Moving Average Cross Indicator
//
// Version 1.0
// Idea by ChartArt on September 15, 2015.
//
// This indicator shows when two moving averages cross.
// With the option to choose between four moving
// average calculations:
// (SMA = simple moving average)
// (EMA = exponential moving average)
// (WMA = weighted moving average)
// (Linear = Linear regression)
//
// The moving averages can be plotted from different
// timeframes, like the weekly or 4 hour timeframe.
// With the possibility to use HL2, HLC3 or OHLC4 prices.
// 
// In addition there is a background color alert
// and arrows when the moving averages cross each other.
// And the moving averages are colored depending if
// they are trending up or down.
//
// List of my work: 
// https://www.tradingview.com/u/ChartArt/


// Multi-timeframe and price input
pricetype = input(close, title="Price Source For The Moving Averages")
useCurrentRes = input(true, title="Use Current Timeframe As Resolution?")
resCustom = input(title="Use Different Timeframe? Then Uncheck The Box Above", type=resolution, defval="W")
res = useCurrentRes ? period : resCustom
price = security(tickerid, res, pricetype)

// MA period input
shortperiod = input(50, title="Short Period Moving Average")
longperiod = input(100, title="Long Period Moving Average")

// MA calculation
smoothinput = input(2, minval=1, maxval=4, title='Moving Average Calculation: (1 = SMA), (2 = EMA), (3 = WMA), (4 = Linear)')
short = smoothinput == 1 ? sma(price, shortperiod) :
    smoothinput == 2 ? ema(price, shortperiod) :
    smoothinput == 3 ? wma(price, shortperiod) :
    smoothinput == 4 ? linreg(price, shortperiod,0) :
    na
long = smoothinput == 1 ? sma(price, longperiod) :
    smoothinput == 2 ? ema(price, longperiod) :
    smoothinput == 3 ? wma(price, longperiod) :
    smoothinput == 4 ? linreg(price, longperiod,0) :
    na

// MA trend direction color
shortcolor = short > short[1] ? lime : short < short[1] ? red : blue
longcolor = long > long[1] ? lime : long < long[1] ? red : blue

// MA output
MA1 = plot(short, title="Short Period Moving Average", style=linebr, linewidth=2, color=shortcolor)
MA2 = plot(long, title="Long Period Moving Average", style=linebr, linewidth=4, color=longcolor)
fill(MA1, MA2, color=silver, transp=50)

// MA trend bar color
TrendingUp() => short > long 
TrendingDown() => short < long 
barcolor(TrendingUp() ? green : TrendingDown() ? red : blue)

// MA cross alert
MAcrossing = cross(short, long) ? short : na
plot(MAcrossing, style = cross, linewidth = 4,color=black)

// MA cross background color alert
Uptrend() => TrendingUp() and TrendingDown()[1]
Downtrend() => TrendingDown() and TrendingUp()[1]
bgcolor(Uptrend() ? green : Downtrend() ? red : na,transp=50)

// Buy and sell alert
Buy = Uptrend() and close > close[1]
Sell = Downtrend() and close < close[1]
plotshape(Buy, color=black, style=shape.arrowup, text="Buy", location=location.bottom)
plotshape(Sell, color=black, style=shape.arrowdown, text="Sell", location=location.top)
hi, such a great idea and script :)

im trying to make it as a strategy for back testing


I wrote :
if (buy)
strategy.entry("buy", strategy.long)


if (sell)
strategy.entry("sell", strategy.short)

but im getting error as ( line 43: syntax error at input 'end of line without line continuation' ) with @version3 and ( line 43: no viable alternative at input 'end of line without line continuation' ) with @subversion23

any help please :(
응답
btcmstr888 btcmstr888
@btcmstr888, I mean line 43: no viable alternative at input 'end of line without line continuation' with @version2
+1 응답
Hi, does this script repaint? Thanks
응답
Pumpcat MDicko123
@MDicko123, Yes it does
응답
Any way of adding an alert to the script please?
+3 응답
MDicko123 MDicko123
@MDicko123, I figured it out. short trend line crossing down long trend line = SHORT/SELL. Short trend line crossing up long trend line = LONG/BUY.
응답
Does this repaint?
+9 응답
FYI - this NOT really a multiple time frame indicator is it?. It is a single time frame but user programmable.
AN MTF usually means it calculates and displays multiple timeframes SIMULTANEOUSLY - the idea being you can visually compare crossover readings AT THE SAME TIME. Just saying ...
+4 응답
Is it possible to have set this up as a 9 EMA and 20 SMA?
+10 응답
Nice.

One question - on my candle chart this turns some red candles orange, some green candles are changed too....?
응답
홈으로 스탁 스크리너 포렉스 스크리너 크립토 스크리너 이코노믹 캘린더 사용안내 차트 특징 프라이싱 하우스룰(내부규정) 모더레이터 웹사이트 & 브로커 솔루션 위젯 차팅 솔루션 도움 받기 기능 개발/개선 요청 블로그 & 뉴스 잦은물음 위키 트위터
프로화일 프로화일설정 계정 및 빌링 도움 받기 공개아이디어 팔로어 팔로잉 비밀메시지 채팅 로그아웃