RichGTastyTrader

[RichG] Easy MTF Strategy

As we all know, timeframe agreement is a powerful tool. This strategy uses 4 time frames and the Keltner ATR for entries and exits.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
strategy("[RichG] Easy MTF Strategy", overlay=false)

TF_1_time = input("D", "Timeframe 1")
TF_2_time = input("5D", "Timeframe 2")
TF_3_time = input("15D", "Timeframe 3")
TF_4_time = input("45D", "Timeframe 4")

transaction_size = input(1, "Contract/Share Amount")

src = close, len = 20
out = sma(src, len)
width = 5
upcolor = green
downcolor = red
neutralcolor = blue
linestyle = line

TF_1 = security(tickerid, TF_1_time, open) < security(tickerid, TF_1_time, close) ? true:false
TF_1_color = TF_1 ? upcolor:downcolor

TF_2 = security(tickerid, TF_2_time, open) < security(tickerid, TF_2_time, close) ? true:false
TF_2_color = TF_2 ? upcolor:downcolor

TF_3 = security(tickerid, TF_3_time, open) < security(tickerid, TF_3_time, close) ? true:false
TF_3_color = TF_3 ? upcolor:downcolor


TF_4 = security(tickerid, TF_4_time, open) < security(tickerid, TF_4_time, close) ? true:false
TF_4_color = TF_4 ? upcolor:downcolor

TF_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 == false
TF_global_color = TF_global ? green : TF_global_bear ? red : white
TF_trigger_width = TF_global ? 6 : width

plot(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_bear
exitCondition_Short = TF_global

longCondition = TF_global
if (longCondition)
    strategy.entry("MTF_Long", strategy.long, qty=transaction_size, when=strategy.position_size == 0)

shortCondition = TF_global_bear
if (shortCondition)
    strategy.entry("MTF_Short", strategy.short, qty=transaction_size, when=strategy.position_size == 0)
    
strategy.close("MTF_Long", when=exitCondition_Long)    
strategy.close("MTF_Short", when=exitCondition_Short)
This seems in history to do amazing, But I'm wondering if it repaints ie (Shows a buy signal one day then the next it turns red where it originally said buy) I'm very interested in this i'm giving it a chance in my next trade if it turns out successful send me your litecoin address if you have one i'll give a tip
Reply
miaomiao18 shanestaring
@shanestaring, yes it repaints
Reply
Out of the 4 time frames being checked, which one should be the trading/entry timeframe? The lowest?
Reply
Does it repaint ...i mean does the stratergy or readings depend upon current data
Reply
Is there a way to scan for these "MTF_Longs" ? I looked at the (pinescript PDF here: https://goo.gl/9Pn1st) way over my head. Any chance there is a comparable ToS or TC2000 scan? Thanks
Reply
sal brewhound
@brewhound, did you ever figure out if there is a way to scan ?
Reply
I just find your amazing strategy which have very high win loss ratio. When I test it, I find that it is not up to the current bar. I use daily time frame and your strategy bar only goes to last trading day, not upto the current bar. I try it with other time frame and the result is the same. Do you know why this happens?
Reply
Thanks; so is it a "buy" signal if the price closes higher than it opened on ALL the following time frames: daily, 5 day, 15 day & 45 day ? being a pine script newbie the "TF_#_time" definition mystifies me as I don't understand how the language knows to look at the daily , 5 day, 15 day & 45 day prices from "D","Timeframe #" ; "5D", "Timeframe #" ; "15D", "Timeframe #" ; "45D", "Timeframe #" ?
Reply
Thanks for the comment. You are correct -- all of the timeframes need to be in alignment for it to signal a "buy". The magic behind the timeframe variables is in the "security" function. The security function tells pinescript to get chart data for a different symbol/ time resolution. So you can ask it to retrieve info from any timeframe. I am passing the TF_#_time into the security function so it gives me back pricing info for that period. From the pinescript PDF:


"The function ‘security’ lets the user to request data from additional symbols and resolutions,
other than the ones to which the indicator is applied.....
<snip>

The lowest resolution is ‘minute’
which is set by the literal “1”. It’s possible to request any number of minutes: “5”, “10”, “21”, etc.
‘Hourly’ resolution is also set by minutes. For example, the following lines signify an hour, two
hours and four hours respectively: “60”, “120”, “240”. A resolution with a value of 1 day is set by
the symbols “D” or “1D”. It’s possible to request any number of days: “2D”, “3D”, etc. Weekly
and monthly resolutions are set in a similar way: “W”, “1W”, “2W”, …, “M”, “1M”, “2M”. “M” and
“1M” are sorts of one month resolution value. “W” and “1W” are the same weekly resolution
value"


There is a good pinescript PDF here: https://goo.gl/9Pn1st

Hope it helps.

-Rich
Reply
miaomiao18 RichGTastyTrader
@RichGTastyTrader, Hi Rich, thanks for the awesome script. it works ! I have one question about the result - it seem after the "MTF Long" is triggered and shown on the chart, it would later then disappear if the movement goes down?! anyway to fix it? to make it unable to retrace but make what triggered to be history?
Reply
EN English (UK)
EN English
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
SV Svenska
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
AR العربية
HE עברית
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Get Help Feature Request Blog & News FAQ Wiki Twitter
Profile Profile Settings Account and Billing Get Help Ideas Published Followers Following Private Messages Chat Sign Out