How do you plot variable based on different TimeFrame than Chart


Category:
0
0

Here is the code in its simplest form:  This will work fine if  the 1 minute timeframe is not specified.    You will see up arrow in many places.  So how do you compose a boolean variable  based on elements from a different timeframe in such a manner you can plot it?

def Min1= AggregationPeriod.Min;

def LongOpen= Volume(period=Min1)> 2 *Average(volume(period=Min1),12);

 

plot upTrendAlert = if longOpen then 1 else Double.NaN; #Does not chart as well

upTrendAlert.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

upTrendAlert.SetDefaultColor(Color.CYAN);

upTrendAlert.SetLineWeight(3);

RESOLVED
Marked as spam
Posted by (Questions: 13, Answers: 18)
Asked on January 17, 2018 2:54 pm
545 views
0
Private answer

First rule of multiple time frames. You can only read from higher or equal time frames.

So if you have your variable reading from the 1 min time frame, you can only plot that on a chart set to the 1 min time frame. And your variable will read from that same 1 min time frame. Any time frame higher than 1 min will generate an error. (check the exclamation point in the upper left corner of your chart).

Let’s use the daily time frame to create an example.

def priceC = close(period = AggregationPeriod.DAY);

In this example, we have a variable named priceC that is set to the close of the daily time frame for the plotted symbol. When the chart is set to 1 Day time frame, it produces exactly the same value as this:

def priceC = close;

However when you change the chart time frame to less than 1 day, the first line of code returns the close from the 1 Day time frame. Set the chart to any time frame higher than 1 day and nothing plots, check for errors in the upper left corner of the chart.

I’m not sure this answers your question. It’s just that your example seemed to indicate this was the crucial concept you were lacking. We have covered multiple time frame indicators in great detail. Some are the subject of videos, while others are located right here in the Q&A forum. I suggest you view these two videos and examine the code carefully. They provide several examples of boolean variables derived from higher time frames.

https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 17, 2018 6:20 pm
0

I looked at all the post having Time Frame in them. None mentioned one can not read lower time frames. I remember the video on the MTF study, but did not seem to go over the coding of it-likely you mentioned it in passing. I see now the script codes only from short time frame to long though- even a check in it. I guess I am use to having a real manual for a language, not a glossary that is called manual. I searched “Time Frame” in that reference, and got no such rule, but obviously you are right and that make sense. Just seemed like a crazy limitation to have in a trading language. Thank you again. I don’t what to say. I have ask these questions. I am only use to learning a language from a real manual or book, not bits from glossaries and videos.

( at January 17, 2018 10:11 pm)
0

I understand. From a trading platform perspective, it is “common knowledge” that a single 5 min candle is made up of 5 separate 1 min candles. The higher time frame is always composed from the lower. If we were to reference the 1 min time frame from the 5 min chart, we don’t have any way to graph those 5 separate 1 min candles for each 5 min candle on the chart. At best, we could only derive their average value, and graph that on the chart. Such can be accomplished using the language in TradingView.com. But I know of no other trading platform that permits this. It’s just not done. Because you ALWAYS loose information when doing so. And losing information is always bad.

So I take it you have not worked through the Thinkscript tutorial yet?

They have two courses.
Basic: http://toslc.thinkorswim.com/center/howToTos/tutorials/Basic.html
Advanced: http://toslc.thinkorswim.com/center/howToTos/tutorials/Advanced.html
Within the advanced section there is a page that covers multiple time frames. (technically defined as referencing secondary aggregations): http://toslc.thinkorswim.com/center/howToTos/tutorials/Advanced/Chapter-11—Referencing-Secondary-Aggregation.html

Hope this all helps.

( at January 18, 2018 8:12 am)