Learn
Indicators
What is and how to use MACD in Tuned Script?
what is moving average convergence divergence (macd)? moving average convergence divergence (macd) is a trend following momentum indicator that shows the relationship between two moving averages https //tuned zendesk com/hc/en us/articles/360020723940 what is and how to use moving averages in tuned script of an asset's price the macd is calculated by subtracting the 26 period exponential moving average (ema) from the 12 period ema the outcome of that calculation is the macd line a 9 period ema of the macd called the "signal line", is then plotted on top of the macd line, which can function as a trigger for buy and sell signals key points about the macd macd triggers technical signals when it crosses above (to buy) or below (to sell) its signal line the speed of crossovers is also taken as a signal of whether a market is overbought or oversold macd also helps investors understand whether the bullish or bearish movement in the price is strong or weak how to add the macd to my script? below you will find a short example of using the macd in your script tunedscript // inputs // we will define 3 integer inputs, fast line (12), slow line (26) // and signal line (9) fastlen = intinput("fast length", 12) slowlen = intinput("slow length", 26) signallen = intinput("signal length", 9) src = close //indicator // define the macd conditions fast ma = ema(src, fastlen) slow ma = ema(src, slowlen) macd = fast ma slow ma signal = ema(macd, signallen) hist = macd signal // macd colors col grow above = seriesof("#26a69a") col grow below = seriesof("#ffcdd2") col fall above = seriesof("#b2dfdb") col fall below = seriesof("#ef5350") col macd = seriesof("#0094ff") col signal = seriesof("#ff6a00") // histogram colors histocolor = (iff(gte(hist, seriesof(0 0)), (iff(lt(hist\[1], hist), col grow above, col fall above)), (iff(lt(hist\[1], hist), col grow below, col fall below)))) // plot // plot the macd in 3 different lines plot(hist, "histogram", histocolor, 4, plotstyle histogram, 0, false) plot(macd, "macd line", col macd, 1, plotstyle line, 0, false) plot(signal, "signal line", col signal, 1, plotstyle line, 0, false) // signal push // never order means that no orders will be placed out(never order) the above image is how the plot should look on the chart how to use the macd to generate buy and sell signals? for the example, i will use the default settings, fast length = 12, slow length = 26, and signal length = 9 the most commonly used method for the macd is to buy when the macd line crosses up through the signal line and to sell when the macd line crosses down through the signal line this generally indicates a strong momentum change tunedscript //inputs // we will define 3 integer inputs, fast line (12), slow line (26), //and signal line (9) fastlen = intinput("fast length", 12) slowlen = intinput("slow length", 26) signallen = intinput("signal length", 9) src = close //indicator // define the macd conditions fast ma = ema(src, fastlen) slow ma = ema(src, slowlen) macd = fast ma slow ma signal = ema(macd, signallen) hist = macd signal // macd colors col grow above = seriesof("#26a69a") col grow below = seriesof("#ffcdd2") col fall above = seriesof("#b2dfdb") col fall below = seriesof("#ef5350") col macd = seriesof("#0094ff") col signal = seriesof("#ff6a00") // histogram colors histocolor = (iff(gte(hist, seriesof(0 0)), (iff(lt(hist\[1], hist), col grow above, col fall above)), (iff(lt(hist\[1], hist), col grow below, col fall below)))) //plot // plot the macd in 3 different lines plot(hist, "histogram", histocolor, 4, plotstyle histogram, 0, false) plot(macd, "macd line", col macd, 1, plotstyle line, 0, false) plot(signal, "signal line", col signal, 1, plotstyle line, 0, false) // entry and exit conditions // define the entry of the macd line crossing over the signal line buy = crossover(macd, signal) // define the entry of the macd line crossing under the signal line sell = crossunder(macd, signal) //signal push // here you will output your entry and exit signals out(signalif(buy, sell)) below is a screenshot of how your chart should look so now you have learned what macd is, how to use it and how to put it in a script and generate signals from it have fun scripting!