♥ 0 |
Hi Pete, just wondering how to use aggregationPeriod in different periods. For example, def period= aggregationPeriod.Day; plot a=if(period==1, ATR(length = 14, averageType = “WEIGHTED”), Double.NaN); It seems not working. Thanks.
Marked as spam
|
Private answer
Without even taking the time to test this for myself I checked the Thinkscript language reference. Because I didn’t really think that testing for “period == 1” would be anywhere close to the actual value for the daily time frame. VERY IMPORTANT NOTEBefore we go any further I want to mention that you posted this in the “Alerts and Notifications” topic. So long as this pertains to Chart Studies, we can work with secondary aggregation periods. Be aware that secondary aggregation periods are not usually permitted for Scans and Watchlist Columns. Style ElementsBefore I get to the details let me make some comments on style. Please ALWAYS place spaces between variable names and operators. “period==1” is not as readable as “period == 1”. And it gets even muddier when you start doing greater than and less than comparisons. Want some authoritative source for this? Just take some time to review all the code examples given in the Thinkrscript tutorials: http://toslc.thinkorswim.com/center/howToTos/tutorials/Basic.html Also, be sure to avoid using excessive abbreviations even for example code. New folks will see Troubleshooting (what’s that?)Ok, now let’s take a look at what you are trying to do and provide your solution. So when you are testing the numeric value of the aggregation period, it is assumed that you are trying to apply a specific setting for the ATR when the user selects the Daily time frame. Did you try to troubleshoot this code by changing:
to
Yes, the A in AggregationPeriod gets capitalized. Source: http://toslc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod/AggregationPeriod-DAY.html The FixFrom that link I just provided, please notice the description of the daily aggregation period. In particular, notice what it says about the value:
So without doing any testing of my own. My first attempt to try to get this working would be to check if the Give that a try and let us know if it works. Marked as spam
|
Please log in to post questions.
Unfortunately, jx2012 posted a follow up question by using the “Post your Answer” box at the bottom of the thread. This is reserved for new answers that solve the question. This should have been posted here in the comments section. So I will include the follow up comment from jx2012 here:
“Man, you are good. Thanks for your response. I will definitely follow your instruction about the style. I guess that you want to check if period is >= AggregationPeriod.DAY is to make sure that the chart is big enough for the daily data. Correct :-)? I know the below script works. But why plot data = ATR(period = agg); is not working :-)? How to write a correct code for ATR? I am only a newbie and it is difficult to do it on my own. Your help is greatly appreciated.
def agg = AggregationPeriod.DAY;
plot data = close(period = agg);”
From your additional follow up question: “I guess that you want to check if period is >= AggregationPeriod.DAY is to make sure that the chart is big enough for the daily data. Correct :-)?”
Actually I don’t have the slightest clue why your code is checking the aggregation period like this. I don’t take time to try and read between the lines. So if you have some particular goal in mind it’s best to explain that clearly rather than submit some code and expect me to extrapolate your intention.
However I can tell you that: plot data = ATR(period = agg); is completely invalid. On two counts. First, the ATR study requires 2 inputs. Length and Average Type. You are providing only one input, and that input is neither the length nor the average type. Not to mention you cannot reference the ATR study in this way. Why? Because the ATR requires data from the High, Low and Close but it does not accept any of these as inputs. You must use the full code from the ATR study. I will avoid providing additional information until I understand your ultimate goal for this code.
Pete, sorry I might have made you confused. My goal is simple. I could read ATR easily from my daily chart. But I normally used 3 min chart for trading so I need to move very often between min chart and daily chart. Now I think maybe I can put ATR into min chart but I don’t know how to do it :-). Thanks.
Ah hah. Ok that makes things perfectly clear. So you want to plot the daily ATR on a 3 min chart? Or do you just need to see the current daily ATR value on a 3 min chart? If it is the former, please post this as a new request. Title should be something like “Plot daily ATR study on intraday chart”. If it is the later, then you can try one of these two posts:
https://www.hahn-tech.com/ans/add-chart-label-for-average-true-range-atr/
https://www.hahn-tech.com/ans/atr-custom-watch-list/
Pete, thank you for your input. I think I got what I was looking for :-).