TraderR0BERT

MACD Multi-Timeframe- TraderR0BERT

MACD with ability to show multiple timeframes on the chart. Set the higher-timeframe MACD at a 5-multiple above the current timeframe that you're on.

NYSE:HES            
Remove from Favorite Scripts Add to Favorite Scripts
//Created by @TraderR0BERT, NETWORTHIE.COM, last updated 01/26/2016
//MACD Indicator with Histogram
//Resolution input option for higher/lower time frames

study(title="MACD Timeframe", shorttitle="MACD TF")
source = close

fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)
Timeframe = input(title="Timeframe", type=resolution, defval="W")

fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)

//Script for Indicator
macd = fastMA - slowMA
signal = sma(macd, signalLength)
hist = macd - signal
zeroline = 0

//Timeframe Optionality
MacdTF = security(tickerid, Timeframe, macd)
SignalTF = security(tickerid, Timeframe, signal)
HistTF = security(tickerid, Timeframe, hist)

//Histogram Color Definitions Current Timeframe
histA_IsUp = hist > hist[1] and hist > 0
histA_IsDown = hist < hist[1] and hist > 0
histB_IsDown = hist < hist[1] and hist <= 0
histB_IsUp = hist > hist[1] and hist <= 0

//Histogram Color Definitions Timeframe Optionality
histA_TF_IsUp = HistTF > HistTF[1] and HistTF > 0
histA_TF_IsDown = HistTF < HistTF[1] and HistTF > 0
histB_TF_IsDown = HistTF < HistTF[1] and HistTF <= 0
histB_TF_IsUp = HistTF > HistTF[1] and HistTF <= 0


plot_color = histA_IsUp ? lime : histA_IsDown ? green : histB_IsDown ? red : histB_IsUp ? maroon : white
Plot_color2 = histA_TF_IsUp ? lime : histA_TF_IsDown ? green : histB_TF_IsDown ? red : histB_TF_IsUp ? maroon : white

//Plot Current Timeframe
plot(hist, color=plot_color, style=columns, linewidth=3)
plot(macd, title="MACD", color=lime, linewidth=4)
plot(signal, title="Signal Line", color=blue, linewidth=3)
plot(zeroline, title="Zero Line", color=black, linewidth=3)

//Plot Timeframe Optionality
plot(HistTF, color=plot_color, style=columns, linewidth=3)
plot(MacdTF, title="MACD", color=lime, linewidth=4)
plot(SignalTF, title="Signal Line", color=blue, linewidth=3)

//Alert Function for MACD crossing Zero Line
Zero_Cross = cross(macd, zeroline)
Zero_Cross_TF = cross(MacdTF, zeroline)
alertcondition(Zero_Cross, title="Low TF MACD crossing Zero", message="Lower TF MACD crossing Zero")
alertcondition(Zero_Cross_TF, title="High TF MACD crossing Zero", message="Higher TF MACD crossing Zero")

//Alert Function for MACD crossing Signal Line
Signal_Cross = cross(macd, signal)
Signal_Cross_TF = cross(MacdTF, SignalTF)
alertcondition(Signal_Cross, title="Low TF MACD crossing Signal", message="Lower TF MACD crossing Signal")
alertcondition(Signal_Cross_TF, title="High TF MACD crossing Signal", message="Higher TF MACD crossing Signal")
nir90
2 months ago

Hi, with which trading platform can I use it? thanks
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out