How do I reference particular markets

Questions about MultiCharts and user contributed studies.
AdrianP
Posts: 46
Joined: 02 Sep 2014
Has thanked: 2 times
Been thanked: 1 time

How do I reference particular markets

Postby AdrianP » 24 Jan 2019

My code below successfully references the JPY when it is loaded as a chart, but I have been unsuccessful in working out how to reference other non-currency markets, such as @CL, @ES etc from TS. I've tried various of the function codes referenced in the MC manual, but none work. I'd appreciate if someone could point out what reference function is needed. So it would automatically reference what market is loaded into a chart, and then make the appropriate calculations.

Code: Select all

If SymbolCurrencyCode = JPY then
Value1 = Text_New_s(Date,Time_s,Low-1.0*AverageTrueRange(20), NumtoStr(Round(100*(Close-dn1+absvalue(C-O)),0),0)) else
Value1 = Text_New_s(Date,Time_s,Low-1.0*AverageTrueRange(20), NumtoStr(Round(10000*(Close-dn1+absvalue(C-O)),0),0));
Text_SetColor(Value1, White);
Text_SetStyle(Value1,2,1);
Text_SetSize(Value1,12);

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: How do I reference particular markets

Postby rrams » 24 Jan 2019

Hi AdrianP, I can't tell from your limited code why you need to differentiate between futures and forex. The SymbolRoot() function provides the shortened name of any type of chart symbol to match with. If you need to know which type of financial instrument then Category() returns an integer equal to zero for futures, nine for cash, twelve for forex and so on.

AdrianP
Posts: 46
Joined: 02 Sep 2014
Has thanked: 2 times
Been thanked: 1 time

Re: How do I reference particular markets

Postby AdrianP » 25 Jan 2019

Thanks for your suggestion rrams, but unfortunately I can find no way to use symbolroot within the code. Why isn't there simply a SymbolFuturesCode equivalent? That would make life perfectly easy.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: How do I reference particular markets

Postby rrams » 25 Jan 2019

Adrian make sure to use string comparisons.
If you insert this code into your indicator or signal

Code: Select all

if Category()=0 and InStr(Symbol, "@CL")>0 then print("Found Oil") else print("Found ", Symbol);
and compile and run it on a futures symbol chart;
What shows up in the output tab of the PowerLanguage Editor?

AdrianP
Posts: 46
Joined: 02 Sep 2014
Has thanked: 2 times
Been thanked: 1 time

Re: How do I reference particular markets

Postby AdrianP » 25 Jan 2019

When I inserted your line of code in mine, it proceeded to print out the symbols across ALL my open windows. So half way there :)

What I wish my code to do is recognise the symbol that is loaded on a particular chart so that the code can perform the text calculation as shown.
Which is different for every market. It's basically just calculating a stop distance from 2 different points so I can instantly see it when my setup occurs.
So if @CL is loaded, then clearly the calculation will be different than any currency.

I don't think I really need a reference to category, but its nice to know the term exists.

When I tried typing in "If InStr(Symbol,"@CL") > 0 then XXX the code would not verify. Including categorry()=0 did not help.

Sorry, my coding skills are rather poor :(

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How do I reference particular markets

Postby TJ » 25 Jan 2019

. . .

When I tried typing in "If InStr(Symbol,"@CL") > 0 then XXX the code would not verify. Including categorry()=0 did not help.

Sorry, my coding skills are rather poor :(

Please go to the Wiki,

look up the keyword InStr, and study the definition and usage examples.

AdrianP
Posts: 46
Joined: 02 Sep 2014
Has thanked: 2 times
Been thanked: 1 time

Re: How do I reference particular markets

Postby AdrianP » 25 Jan 2019

Thanks for the suggestion TJ. Sadly it contains exactly the same information I had already seen in the MC help file.
Perhaps you are looking at something different to me, but the usage example's' really doesn't exist. It basically includes one.
Clearly you aren't thinking from the perspective of someone with poor coding skills. But I appreciate your input.


Return to “MultiCharts”