Accessing Variable from Another Custom Study


Category:
0
0

Hi Peter,

I wanted to know if you know if it’s possible to access a variable from another custom study. I need to access a variable that is on the daily time frame, but use it in a calculation on the minute chart. I’ve tried the method of changing the aggression period for that particular variable but results in other occasional bugs.

 

Would be great to know if this is also available on accessing variables from another study in the same scan as well

(1 scan with 3x different study criteria, but wanting all 3 to access the same variable for “scan day”)

 

Thanks!

Marked as spam
Posted by (Questions: 7, Answers: 9)
Asked on October 9, 2020 8:30 pm
47 views
0
Private answer

Perhaps if you explain the entire goal you are trying to achieve, in detail, I can explain how to get there. But referencing a variable in another study is completely impossible in Thinkorswim. Sandboxed.

However you can access the value of a plot from another study. Plenty of examples of that here in the forum.

The time frame is always dictated by the location you apply the code.

Seems you are seeking a solution while assuming a specific path to that solution. (plenty of examples of that in this forum as well).

I suggest you extend your thinking outside of that box.

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on October 9, 2020 8:52 pm
0
I'd love to. I'm historically gathering data on a breakout play over a "resistance day-high". Study 1 - on a 5Y:1D chart I define the resistance day high by using TOS fold loop to step back 1 bar at a time and locate the nearest day that had heavy volume and log the high. If the current day opened below that, I log it as the "nearest resistance" point Study 2 - on a 3D:1M chart I need the value from above for various variables I gather data on the minute. I'm able to use the same 'for' loop on the minute study & define the period as 'day'. The problem occurs when I have the loop run through too many iterations. I can have it go as far back as 1Y (252 bars), but not 5, as it results in “0” logged I use the same code on my 5Y:1D chart but don't define the aggregation period. My initial question would be to call upon the final value assigned on the 5Y study, and hope it doesn't result in '0' as it does on my 3D:1M chart, since it works just fine on the 5 year
( at October 9, 2020 11:02 pm)
0
Fold loop Code: (offset by 2) #Step 1: Finding the resistance day def bars_ago_resistance_set = fold n1 = (2) to (days_duration_to_test + 2) with temp_value1 = Double.NaN while IsNaN(temp_value1) do if volume(period = AggregationPeriod.DAY)[n1] >= (average_daily_volume * average_volume_multiplier) then n1 else Double.NaN; #Step 2: Use "bars_ago_resistance_set" to find the high of that day, as well as volume and various variables of that day def resistance_day_high = fold n2 = (2) to (days_duration_to_test + 2) with temp_value2 = Double.NaN while IsNaN(temp_value2) do if n2 == bars_ago_resistance_set then high(period = AggregationPeriod.DAY)[n2] else Double.NaN; Bonus Question: There's no way to convert a double to an int, correct? I would have loved to simplify my 'resistance_day_high' by using the below, but TOS wouldn't allow using a double and I tried long & hard to find a way to convert a double to an int: def resistance_day_high = high[bars_ago_resistance_set];
( at October 9, 2020 11:03 pm)
0
Thanks for taking the time to explain what you are working on. I have some great news for you. The platform you are trying to use for this is completely inadequate for the task. A good analogy may be something along the lines of trying to push a camel through the eye of a needle. There are many other platforms out there which are very well suited for market research. Thinkorswim does not even rank at the bottom of that list. I suggest you move your research work to a platform named AmiBroker: http://www.amibroker.com/
( at October 10, 2020 9:37 am)
0
I will also add another bit of insight. Learn to write the code to capture the data from left to right instead of trying to use a loop to read the chart backwards. This may or may not be possible in you specific case. I cannot afford to take the time to evaluate that. But I almost never use the fold statement on Thinkorswim. I hate it with great passion. Most stupid idiot thing I have ever seen in a scripting language. Almost anything you do with a fold can be accomplished using statements that read the chart from left to right. They are massively more efficient, robust and flexible than that stupid excuse for a looping structure that Thinkorswim calls "fold".
( at October 10, 2020 9:42 am)
0
Thanks for the input, I'll be sure to check out that platform & also do my best to use left to right operations!
( at October 10, 2020 11:51 am)