MTF indicator from tradingview


Category:
0
0

Hey Pete,

Someone on tradingview made a cool MTF script and the code is available to see. However, I\’m not sure how to convert from pine (tradingview) to thinkscript. Would you be able to help?

 

Thanks

Marked as spam
Posted by (Questions: 4, Answers: 9)
Asked on April 22, 2018 7:05 am
350 views
0

I can, and I have. In fact we have at least one post in the Q&A forum on this topic. However MTF studies can get a bit complicated. Which means I may not do this for free in the Q&A forum. It may end up being a paid custom project. But I need to see it first. You didn’t provide a link? Or source code?

( at April 22, 2018 8:29 am)
0

Hello? Anyone out there?

( at April 25, 2018 12:55 pm)
0
Private answer

Hey Pete, sorry for the late reply just saw this now. Here is the code:

 

tf1=input(‘5’, title=”Short TF 1″)

tf2=input(’10’, title=”Short TF 2″)

tf3=input(’15’, title=”Short TF 3″)

tf4=input(’30’, title=”Short TF 4″)

tf5=input(’60’, title=”Medium TF 1″)

tf6=input(‘120’, title=”Medium TF 2″)

tf7=input(‘240’, title=”Medium TF 3″)

tf8=input(‘D’, title=”Long TF 1″)

tf9=input(‘W’, title=”Long TF 2″)

tf10=input(‘M’, title=”Long TF 3″)

high1=security(tickerid, tf1, high)

high11=security(tickerid, tf1, high[1])

high2=security(tickerid, tf2, high)

high22=security(tickerid, tf2, high[1])

high3=security(tickerid, tf3, high)

high33=security(tickerid, tf3, high[1])

high4=security(tickerid, tf4, high)

high44=security(tickerid, tf4, high[1])

high5=security(tickerid, tf5, high)

high55=security(tickerid, tf5, high[1])

high6=security(tickerid, tf6, high)

high66=security(tickerid, tf6, high[1])

high7=security(tickerid, tf7, high)

high77=security(tickerid, tf7, high[1])

high8=security(tickerid, tf8, high)

high88=security(tickerid, tf8, high[1])

high9=security(tickerid, tf9, high)

high99=security(tickerid, tf9, high[1])

high10=security(tickerid, tf10, high)

high101=security(tickerid, tf10, high[1])

low1=security(tickerid, tf1, low)

low11=security(tickerid, tf1, low[1])

low2=security(tickerid, tf2, low)

low22=security(tickerid, tf2, low[1])

low3=security(tickerid, tf3, low)

low33=security(tickerid, tf3, low[1])

low4=security(tickerid, tf4, low)

low44=security(tickerid, tf4, low[1])

low5=security(tickerid, tf5, low)

low55=security(tickerid, tf5, low[1])

low6=security(tickerid, tf6, low)

low66=security(tickerid, tf6, low[1])

low7=security(tickerid, tf7, low)

low77=security(tickerid, tf7, low[1])

low8=security(tickerid, tf8, low)

low88=security(tickerid, tf8, low[1])

low9=security(tickerid, tf9, low)

low99=security(tickerid, tf9, low[1])

low10=security(tickerid, tf10, low)

low101=security(tickerid, tf10, low[1])

c=iff(high>high[1] and low>low[1], 1, iff(high<high[1] and low<low[1], 2, 3))

c1=iff(high1>high11 and low1>low11, 1, iff(high1<high11 and low1<low11, 2, 3))

c2=iff(high2>high22 and low2>low22, 1, iff(high2<high22 and low2<low22, 2, 3))

c3=iff(high3>high33 and low3>low33, 1, iff(high3<high33 and low3<low33, 2, 3))

c4=iff(high4>high44 and low4>low44, 1, iff(high4<high44 and low4<low44, 2, 3))

c5=iff(high5>high55 and low5>low55, 1, iff(high5<high55 and low5<low55, 2, 3))

c6=iff(high6>high66 and low6>low66, 1, iff(high6<high66 and low6<low66, 2, 3))

c7=iff(high7>high77 and low7>low77, 1, iff(high7<high77 and low7<low77, 2, 3))

c8=iff(high8>high88 and low8>low88, 1, iff(high8<high88 and low8<low88, 2, 3))

c9=iff(high9>high99 and low9>low99, 1, iff(high9<high99 and low9<low99, 2, 3))

c10=iff(high10>high101 and low10>low101, 1, iff(high10<high101 and low10<low101, 2, 3))

sig1=iff(c==1 and c1==1 and c2==1 and c3==1 and c4==1, 1, iff(c==2 and c1==2 and c2==2 and c3==2 and c4==2, 2, 3))

sig2=iff(c==1 and c5==1 and c6==1 and c7==1, 1, iff(c==2 and c5==2 and c6==2 and c7==2, 2, 3))

sig3=iff(c==1 and c8==1 and c9==1 and c10==1, 1, iff(c==2 and c8==2 and c9==2 and c10==2, 2, 3))

signal=iff(sig1==1 and sig2==1 and sig3==1, 1, iff(sig1==2 and sig2==2 and sig3==2, 2, 3))

plot(15, title=”Current TF”, color=iff(c==1, blue, iff(c==2, black, white)), style=circles, linewidth=5, join=true)

plot(12, title=”TF 1″, color=iff(c1==1, blue, iff(c1==2, black, white)), style=circles, linewidth=3, join=true)

plot(11, title=”TF 2″, color=iff(c2==1, blue, iff(c2==2, black, white)), style=circles, linewidth=3, join=true)

plot(10, title=”TF 3″, color=iff(c3==1, blue, iff(c3==2, black, white)), style=circles, linewidth=3, join=true)

plot(9, title=”TF 4″, color=iff(c4==1, blue, iff(c4==2, black, white)), style=circles, linewidth=3, join=true)

plot(7, title=”TF 5″, color=iff(c5==1, blue, iff(c5==2, black, white)), style=circles, linewidth=3, join=true)

plot(6, title=”TF 6″, color=iff(c6==1, blue, iff(c6==2, black, white)), style=circles, linewidth=3, join=true)

plot(5, title=”TF 7″, color=iff(c7==1, blue, iff(c7==2, black, white)), style=circles, linewidth=3, join=true)

plot(3, title=”TF 8″, color=iff(c8==1, blue, iff(c8==2, black, white)), style=circles, linewidth=3, join=true)

plot(2, title=”TF 9″, color=iff(c9==1, blue, iff(c9==2, black, white)), style=circles, linewidth=3, join=true)

plot(1, title=”TF 10″, color=iff(c10==1, blue, iff(c10==2, black, white)), style=circles, linewidth=3, join=true)

plot(8, title=”Short TF Signal”, color=iff(sig1==1, green, iff(sig1==2, red, white)), style=cross, linewidth=4)

plot(4, title=”Medium TF Signal”, color=iff(sig2==1, green, iff(sig2==2, red, white)), style=cross, linewidth=4)

plot(0, title=”Long TF Signal”, color=iff(sig3==1, green, iff(sig3==2, red, white)), style=cross, linewidth=4)

plot(-1, title=”Signal”, color=iff(signal==1, green, iff(signal==2, red, white)), style=circles, linewidth=5)

Marked as spam
Posted by (Questions: 4, Answers: 9)
Answered on April 26, 2018 12:09 pm
0

Ordinarily I would require that you post your response as a comment instead of using the “Post your Answer” box at the bottom of the thread. But code pasted into a comment box does not format well so I’ll let this pass.

I can tell you that this code is a monstrosity. I count 10 higher time frames total. That is madness, in my opinion. I’ve never seen a professional trader regularly use more than 5 time frames to trade. Most use 2-3. I would file this under: “Just because you can, doesn’t mean you should”.

Aside from that, I would never translate something of this size for no charge. So I will not be providing a solution to this request here in the Q&A forum. You are welcome to submit this as a custom project request. You can read about our rates and other details here: https://www.hahn-tech.com/about/

I will tell you up front that translating this code will take several hours. And given the scope, we may find that certain aspects are not possible to implement in Thinkorswim. This will be quite an expensive project. So make sure this is something that makes you lots of money.

( at April 26, 2018 12:21 pm)
0

Thanks Pete, I will think about it. Take care

( at April 26, 2018 12:34 pm)
0

Hey Pete just something I was curious about. I know that the code is very long however the only part of the code that I’m really interested in is the “Long TF Signal” (second last line). It only includes the daily (tf8), weekly (tf9), and monthly (tf10) inputs.

( at May 18, 2018 7:45 am)
0
Private answer

Since Giuseppe has clarified the request to include a small subsection of the entire indicator I have the following solution. Giuseppe has requested just the section of code that plots the “Long TF Signal”, which consists of Daily, Weekly and Monthly time frames. The time frames are inputs which can be adjusted as needed.

First, I will provide that portion of TradingView code I used for the conversion:

tf8=input(‘D’, title=”Long TF 1″)
tf9=input(‘W’, title=”Long TF 2″)
tf10=input(‘M’, title=”Long TF 3″)
high8=security(tickerid, tf8, high)
high88=security(tickerid, tf8, high[1])
high9=security(tickerid, tf9, high)
high99=security(tickerid, tf9, high[1])
high10=security(tickerid, tf10, high)
high101=security(tickerid, tf10, high[1])
low8=security(tickerid, tf8, low)
low88=security(tickerid, tf8, low[1])
low9=security(tickerid, tf9, low)
low99=security(tickerid, tf9, low[1])
low10=security(tickerid, tf10, low)
low101=security(tickerid, tf10, low[1])
c=iff(high>high[1] and low>low[1], 1, iff(high<high[1] and low<low[1], 2, 3)) c8=iff(high8>high88 and low8>low88, 1, iff(high8high99 and low9>low99, 1, iff(high9high101 and low10>low101, 1, iff(high10
sig3=iff(c==1 and c8==1 and c9==1 and c10==1, 1, iff(c==2 and c8==2 and c9==2 and c10==2, 2, 3))
plot(0, title=”Long TF Signal”, color=iff(sig3==1, green, iff(sig3==2, red, white)), style=cross, linewidth=4)

And here is the translation of that code into Thinkorswim:

declare lower;
input timeFrameOne = AggregationPeriod.DAY;
input timeFrameTwo = AggregationPeriod.WEEK;
input timeFrameThree = AggregationPeriod.MONTH;
def highTF1 = high(period = timeFrameOne);
def highTF2 = high(period = timeFrameTwo);
def highTF3 = high(period = timeFrameThree);
def lowTF1 = low(period = timeFrameOne);
def lowTF2 = low(period = timeFrameTwo);
def lowTF3 = low(period = timeFrameThree);
def directionBase = if high > high[1] and low > low[1] then 1 else if high < high[1] and low < low[1] then 2 else 3; def directionOne = if highTF1 > highTF1[1] and lowTF1 > lowTF1[1] then 1 else if highTF1 < highTF1[1] and lowTF1 < lowTF1[1] then 2 else 3; def directionTwo = if highTF2 > highTF2[1] and lowTF2 > lowTF2[1] then 1 else if highTF2 < highTF2[1] and lowTF2 < lowTF2[1] then 2 else 3; def directionThree = if highTF3 > highTF3[1] and lowTF3 > lowTF3[1] then 1 else if highTF3 < highTF3[1] and lowTF3 < lowTF3[1] then 2 else 3;
def uptrend = directionBase == 1 and directionOne == 1 and directionTwo == 1 and directionThree == 1;
def downtrend = directionBase == 2 and directionOne == 2 and directionTwo == 2 and directionThree == 2;
plot upper = 1;
plot lower = -1;
plot signal = 0;
signal.AssignValueColor(if uptrend then Color.GREEN else if downtrend then Color.RED else Color.WHITE);
signal.SetPaintingStrategy(PaintingStrategy.POINTS);

Screenshot below shows the final result.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on May 18, 2018 1:48 pm
0

Thank you Pete, is there any way to use this in the scanner? To see when the white dot turns to green?

( at May 20, 2018 7:00 am)
0

No, you cannot apply a MTF study to a scan. To build a scan that mimics this you will need to add a study filter for each of the three time frames.

( at May 20, 2018 7:40 am)
0

Would you be able to show the study filter for one of the time frames?

( at May 20, 2018 8:43 am)
0

This is the base time frame that can be used in a scan:

def directionBase = if high > high[1] and low > low[1] then 1 else if high < high[1] and low < low[1] then 2 else 3; You would then add the plot scan statement: plot scan = directionBase == 1; # for uptrend

( at May 20, 2018 9:40 am)