How to discover the two currencies on a specific chart

 

This should most probably a very simple problem to solve.

I want to read the Symbol() of a particular chart and then break up the 6 char string (e.g. EURUSD) into the two currencies involved e.g. EUR and USD and give each one of them a numeric value.

Can anybody please help me to solve this problem?

 
 
StringSubstr. If you want a general solution for all brokers
 
ernest02:

This should most probably a very simple problem to solve.

I want to read the Symbol() of a particular chart and then break up the 6 char string (e.g. EURUSD) into the two currencies involved e.g. EUR and USD and give each one of them a numeric value.

Can anybody please help me to solve this problem?



Reading your post again, I'm not sure what you mean by giving each one a numeric value.

Do you intend to use the extracted string as a variable name?

I would like to know if that is possible, but don't see any easy way.

Only way that I can think of is by having 2 arrays, one array with the currency names and the numeric value stored in the corresponding position of the other array

 
GumRai:
use StringSubstr

Thanks a lot!
 
if(StringFind(cSymbol, fSymbol, 0)>=0)){return(1);}

if (StringFind(Symbol(), "USDJPY", 0)>=0) {Comment("USDJPY");}   //currency =   prefixUSDJPYsuffix
//also you can say
if (StringFind(Symbol(), "JPY", 0)>=0){Comment("JPY");}     //currency has JPY         

Try this out on different chartsymbols....

and you will see if it works

 

First of all I want to thank all of you for your feedback. It is highly appreciated.

GumRai - Yes, I want to use the strings to create a variable "double" value with the string as part of the double name to which I want to assign a value read from a custom indicator.

You see I want to check when one currency strength exceeds/crosses the other. So I need to assign a before value (shift =1) and a current value (shift = 0) to establish when the one crosses the other.

But I do not want to rewrite the code for 50 currencies. I want one EA that I can attach to any chart.

So I have written three lines of code to establish the currencies used on the particular chart as follows:

    string CurrPair = Symbol();
    string FirstCurr = StringSubstr(CurrPair,0,3);
    string SecondCurr = StringSubstr(CurrPair,3,3);

Now I want to assign a double value from the custom indicator to say string (FirstCurr + "shift1") as the shift = 1 value for that currency of the indicator and string (FirstCurr + "shift0") as shift = 0 of the indicator.

The same with SecondCurr.

The problem is I cannot use a string to receive a double value from the indicator and if a I create a double value with that same name it is a completely different variable.

There must be a way to loop through an array to do this.

 
ernest02:

First of all I want to thank all of you for your feedback. It is highly appreciated.

GumRai - Yes, I want to use the strings to create a variable "double" value with the string as part of the double name to which I want to assign a value read from a custom indicator.

You see I want to check when one currency strength exceeds/crosses the other. So I need to assign a before value (shift =1) and a current value (shift = 0) to establish when the one crosses the other.

But I do not want to rewrite the code for 50 currencies. I want one EA that I can attach to any chart.

So I have written three lines of code to establish the currencies used on the particular chart as follows:

Now I want to assign a double value from the custom indicator to say string (FirstCurr + "shift1") as the shift = 1 value for that currency of the indicator and string (FirstCurr + "shift0") as shift = 0 of the indicator.

The same with SecondCurr.

The problem is I cannot use a string to receive a double value from the indicator and if a I create a double value with that same name it is a completely different variable.

There must be a way to loop through an array to do this.


for what reason do you have to find JPY or USD

is it for a file you downloaded and it is giving a input what country you have news like

        <event>
                <title>Manufacturing PMI</title>
                <country>JPY</country>
                <date><![CDATA[09-29-2013]]></date>
                <time><![CDATA[11:15pm]]></time>
                <impact><![CDATA[Low]]></impact>
                <forecast />
                <previous><![CDATA[52.2]]></previous>
        </event>

or

Date,Time,Time Zone,Currency,Event,Importance,Actual,Forecast,Previous
Sun Sep 29,21:45,GMT,nzd,NZD Building Permits (MoM),Low,1.4%,2.5%,-3.4%

in that case you have JPY or USD in a Array

and you can check it this way ( see also code of News events and market times on your chart )

if((StringFind(Symbol(), /*NewsArray*/  news[i][COLUMN_CURRENCY], 0)>=0)){return(/* whatever you want depending on your variable bool, string, int....*/ );}
 
deVries:


for what reason do you have to find JPY or USD

is it for a file you downloaded and it is giving a input what country you have news like

or

in that case you have JPY or USD in a Array

and you can check it this way ( see also code of News events and market times on your chart )


From reading his posts in this thread, he wants to gauge a particular currency's strength, probably looking at it from a different angle to the currency strength meters available.
 
    string CurrPair = Symbol();
    string FirstCurr = StringSubstr(CurrPair,0,3);
    string SecondCurr = StringSubstr(CurrPair,3,3);

This method will not work if Symbol() has prefix

 
deVries:


This method will not work if Symbol() has prefix


I realise that a Symbol that has a prefix will give a wrong result with the code I have written, but I do not want a general EA just one that works with my broker which has no prefixes to their symbols.

Also, I do not want to read some HTML to get a country name or Symbol since I am writing an EA that must detect from a custom indicator when a certain currency strength exceeds/crosses that of the other.

That is why I was hoping to get some guidance on code that I can use to loop through an array to select the two currencies that is applicable to the particular chart and then use this info to create the general double variables that I can populate with the strength of the currency at shift 1 and shift 0.

Reason: