♥ 0 |
Hi Pete – I started my move over to TOS, and watched your videos on multi monitor setups – very helpful! I just started playing with thinkscript today, as I have a few studies I want to create. My first is rather simple – it is a script to show a label with the ATR, 10% of ATR & 2% of ATR. The script has inputs for # of periods (starting at current period price, going backwards) and the type of average (averageType = Simple, Exponential, Weighted, Wilders and Hull). It seems to match the TOS provided ATR study at the last candle (which is what I want), and it takes up a lot less screen space than a chart over time for the ATR, which is the reason for the script. I have it all working, except when I echo the averageType, it shows a number, which I think is based on an internal conversion the interpreter is doing (Simple = 0, Exponential = 1, Weighted = 2, Wilders = 3 and Hull = 4), when I change inputs in the Customizing Study dialog. I am trying to build the logic with a variable to display a string that is set, based on the number that averageType contains, but for the life of me I can’t get the syntax right… (for example, if the average type = Simple, display “Simple” in the label, rather than the “0” that is displayed) most recent effort was to declare the DFKTMA variable, and then set it to equal the string I want, using nested If thens, but I can’t get even a basic 2 conditional to work. am I attacking this the right way? the commented lines are just the last iteration of about 8 different ways I have tried to set the variable DFKTMA to a string that says “Simple”, rather than the “0” that is is displayed in the label. here is the script: ******************************* input length = 14; #if (averageType == “3”, DFKTMA == “Wilders”, “Test”) ; AvgTrueRange1 = MovingAverage(averageType, TrueRange(high, close, low), length); AddLabel(yes, Concat(” Type of MovingAverage: “, Concat(averageType, Concat(” # of Periods: “, Concat(length, Concat(” ATR: “, Concat(AvgTrueRange1, Concat(” ATR/10%: “, Concat(AvgTrueRange2, Concat(” ATR/2%: “, AvgTrueRange3))))))))), Color.WHITE); RESOLVED
Marked as spam
|
Private answer
thanks much Pete yet another quirky interpreted environment :) Here's the working code: <pre> def AvgTrueRange; input length = 14; AvgTrueRange = MovingAverage(AverageType, TrueRange(high, close, low), length); AddLabel(yes, Concat(" Type of Moving Average: ", Concat((if AverageType == AverageType.Wilders then "Wilders" else if AverageType == AverageType.Simple then "Simple" else if AverageType == AverageType.Hull then "Hull" else if AverageType == AverageType.Exponential then "Exponential" else "Weighted"), Concat(" # of Periods: ", Concat(length, Concat(" ATR: ", Concat(AvgTrueRange, Concat(" 10% ATR: ", Concat(AvgTrueRange10, Concat(" 2% ATR: ", AvgTrueRange2))))))))), Color.WHITE); <pre/>
Marked as spam
|
|
Private answer
There are tons of examples in the Q&A forum showing how to set chart labels. Included in these examples are several that show how to set the text of a label dynamically. I suggest you take some time to review these examples by searching for the term "label" in the forum. The following link is the results you get when you search for that time in the Chart Studies topic: https://www.hahn-tech.com/ans/cat/studies/?question_type=all&search=label You cannot use the input named "averageType" in your expression. That will result in what the language refers to as a "Constant". Which are gernally expressed as numerical values. So you will need to include language within your code to handle every possible selection for the average type. For example:
There is not simple solution to your problem. You have to employ what I call "brute force" techniques. Marked as spam
|
Please log in to post questions.