This strategy generates trading signals based on the MACD indicator. The MACD indicator consists of three lines: the MACD line, SIGNAL line and histogram (HISTO) line. When the MACD line crosses above the SIGNAL line and turns positive, it generates a buy signal. When the MACD line crosses below the SIGNAL line and turns negative, it generates a sell signal.
Specifically, when the close price crosses above the 34-period EMA and the MACD line crosses above the SIGNAL line into positive territory, it indicates strong upside momentum, so we buy. When the close price crosses below the 34-period EMA and the MACD line crosses below the SIGNAL line into negative territory, it indicates strong downside momentum, so we sell.
This strategy identifies trading opportunities using the MACD indicator and filters signals using a 34-period EMA. It allows timely entries when new price trends start while controlling risk via stop loss/take profit. The strategy can be further refined via parameter optimization, adding other indicators etc. to improve profitability.
/*backtest start: 2024-01-19 00:00:00 end: 2024-02-18 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © melihtuna //@version=2 strategy("Jim's MACD", overlay=true) Tendies = input(true, title="Check here for tendies") // === MACD Setup === [macdLine, signalLine, histLine] = macd(close, 12, 26, 9) //EMA ma = ema(close, 5) plot(ema(close,5)) //Entry if (close > ma and cross(macdLine,signalLine) and histLine> 0.4 and signalLine > 0 or histLine > 0 and signalLine > 0 ) strategy.entry("BUY", strategy.long) if(close < ma and cross(macdLine,signalLine) and histLine < -0.4 and signalLine < 0 or close < ma and histLine < 0 and signalLine < 0 ) strategy.entry("SELL", strategy.short) //Exit strategy.close("BUY", when = histLine < 0 ) strategy.close("SELL", when = histLine > 0 )