Combing in MACD and MTF — Strategy by marcoderoni

By version

Performance Metrics

Description

May 17, 2020Hi all, I'm trying to wedge in the MACD into a multiple timeframe. Scope is to create:1) an alert when the MACD across all timeframes is positive,2) an alert when the MACD across all timeframes is negative, and3) one when neither of them is applicable.Would anyone be so kind to give it some thoughts, please?//version=2strategy("[RichG] Easy MTF Strategy", overlay=false)TF_1_time = input("3", "Timeframe 1")TF_2_time = input("5", "Timeframe 2")TF_3_time = input("15", "Timeframe 3")TF_4_time = input("30", "Timeframe 4")fastLen = input(title="Fast Length", type=integer, defval=12)slowLen = input(title="Slow Length", type=integer, defval=26)sigLen = input(title="Signal Length", type=integer, defval=9)[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)width = 5upcolor = greendowncolor = redneutralcolor = bluelinestyle = lineTF_1 = security(tickerid, TF_1_time, open) < security(tickerid, TF_1_time, close) ? true:falseTF_1_color = TF_1 ? upcolor:downcolorTF_2 = security(tickerid, TF_2_time, open) < security(tickerid, TF_2_time, close) ? true:falseTF_2_color = TF_2 ? upcolor:downcolorTF_3 = security(tickerid, TF_3_time, open) < security(tickerid, TF_3_time, close) ? true:falseTF_3_color = TF_3 ? upcolor:downcolorTF_4 = security(tickerid, TF_4_time, open) < security(tickerid, TF_4_time, close) ? true:falseTF_4_color = TF_4 ? upcolor:downcolorTF_global = TF_1 and TF_2 and TF_3 and TF_4 TF_global_bear = TF_1 == false and TF_2 == false and TF_3 == false and TF_4 == falseTF_global_color = TF_global ? green : TF_global_bear ? red : whiteTF_trigger_width = TF_global ? 6 : widthplot(1, style=linestyle, linewidth=width, color=TF_1_color)plot(5, style=linestyle, linewidth=width, color=TF_2_color)plot(10, style=linestyle, linewidth=width, color=TF_3_color)plot(15, style=linestyle, linewidth=width, color=TF_4_color)plot(25, style=linestyle, linewidth=4, color=TF_global_color) exitCondition_Long = TF_global_bearexitCondition_Short = TF_globallongCondition = TF_globalif (longCondition) strategy.entry("MTF_Long", strategy.long)shortCondition = TF_global_bearif (shortCondition) strategy.entry("MTF_Short", strategy.short) strategy.close("MTF_Long", when=exitCondition_Long) strategy.close("MTF_Short", when=exitCondition_Short)May 17, 2020Release Notescleaned up the MACD references in the MTF snippetsMay 17, 2020Release Notesupdated the exit pointsMay 17, 2020Release Notespolished the exit pointsMay 18, 2020Release Notespolished the nameMay 18, 2020Release NotesGuys, I need some help, please.1) why doesn't my script close a position when TF_global_off kicks in? and2) why there is a gap of time between the fulfilment of a condition (all green or all red) and the actual opening?thanks in advanceMay 18, 2020Release Notesfurther polishingMay 18, 2020Release Notesthis should be the final version. Exit points correctly visualised and good results.only regret I have is that I would prefer to be able to count data from the open of the candle, instead of the close.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView