Checking if instrument is a future


Category:
0
0

Hi, do you know if there’s a simple way to check the symbol of a traded instrument and tell that is a future in ToS?
I was thinking to do a quick check on the symbol name and check if that contains the typical / ToS uses for futures but think script is not very string friendly apparently.
Also, it seems like the variable from GetSymbol() can’t be assigned to a variable either.
Do you know if there’s another way to wok on symbols to check what they refer to?
Thanks.

Marked as spam
Posted by (Questions: 7, Answers: 9)
Asked on June 12, 2020 5:09 am
225 views
1
Private answer

There is nothing built for that purpose in the Thinkorswim language at this time. However there is one potential workaround. It only applies to the root symbol and NOT the actual contract. For example the root contract for Euro futures is "/6E" while the current live contract is "/6EU20". It works for "/6E" but not for the live contract.

While testing this the platform was performing very poorly so there was a a significant delay in this code acknowledging the futures contract when initially loading a ticker symbol on the chart. Perhaps when the platform is not overloaded it will react more quickly. But like I said, this is a workaround so don't try using this for anything that considered "mission critical" until you use this for a while and get to know how well it works under various conditions.

rec trackChangeEvents = if HasContractChangeevent() then 1 else trackChangeEvents[1];
AddLabel(yes, if trackChangeEvents > 0 then "Futures Contract" else "Non-Futures", Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 12, 2020 7:50 am
0
That's indeed a very smart workaround. The only issue I have is that it seems my ToS does not accept that function (HasContractChangeevent()) for some reason. Very strange...
( at June 12, 2020 9:34 am)
0
I applied this to a chart and tested it on daily as well as intraday time frames. Not sure if it works for other tools such as scans, study alerts or custom quotes. One thing is certain, the historical data needs to include the most recent contract rollover. This will be out of range for most intraday time frames on scans, study alerts and custom quotes. Even on the chart, you need to make sure to include 90 days or so of data so that there is a contract rollover event somewhere on that chart.
( at June 12, 2020 10:17 am)
0
Right Pete, makes sense. Thanks a lot.
( at June 12, 2020 10:23 am)