Add aggregation period to study


Category:
0
0

Hi Pete,
We’re happy you’re well and glad to see your recovering nicely.
Question…. With this script I have, how & where would I add the daily aggregation period into the formula?  If I’m staring at a 5 minute chart, I want to know if there’s a doji on the daily chart. I tried to add “period” to the plot, but got an error…….. or…   Would we use “doji()” in the formula below?  Thank you Pete. Take care of yourself 🙂

input period = AggregationPeriod.DAY;
input length = 20;
input bodyFactor = 0.05;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
plot Doji = IsDoji(length, bodyFactor);
AddLabel(yes, if Doji then "Doji" else "", if doji then color.yellow else color.gray);

Marked as spam
Posted by (Questions: 11, Answers: 10)
Asked on June 18, 2019 8:05 am
462 views
0
input period = AggregationPeriod.DAY; input length = 20; input bodyFactor = 0.05; assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor); plot Doji = IsDoji(length, bodyFactor); AddLabel(yes, if Doji then "Doji" else "", if doji then color.yellow else color.gray);
( at June 18, 2019 8:06 am)
0
Private answer

Well the first thing you need to do is make use of that input named "period". As it stands, that input variable is not used anywhere in your code. So I imagine your question is just that. Where the heck do you use that input value? Well you cannot use it in any of the code you have provided.

You are trying to determine if a Doji is present using this special built-in function: isDoji(). Details are found here: http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/IsDoji.html

There is no way to use that special function to read from the daily time frame within an intraday chart. That function only works for the time frame the chart is set to. So you must create your own method for measuring and checking for Doji's. In it's most basic (and strict) form, a Doji is indicated when the close is equal to the open. That special function permits the open and close to be "almost equal".

Do we can do it this way:

input timeFrame = AggregationPeriod.DAY;
def dailyOpen = open(period = timeFrame);
def dailyClose = close(period = timeFrame);
plot previousDayDoji = dailyOpen[1] == dailyClose[1];
AddLabel(previousDayDoji, "Prev Day Doji", Color.YELLOW);

This will get the open and close from the daily time frame. Then check to see if the previous day's open and close where equal. If so, the label will appear. Otherwise the label will not appear at all.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on June 18, 2019 1:29 pm