Nested if statements

 


Hopefully someone can help, my knowledge on mt4 code is limited, I am trying to wright nested if statements, what I am trying to do is:

if NAME(variable)=string1(typed into code) then insert number(double typed into code) into RESULT(variable), else if NAME=string2 insert

a different number into RESULT. This continues until match is found or value 0.0 is inserted into RESULT.

Forgot to mention, NAME is the symbol attached to, us ing Symbol(); to obtain.

Thankyou

 
  1. Your post is unintelligible. Symbol()(variable)=string makes no sense.

  2. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

 
William Roeder:
  1. Your post is unintelligible. Symbol()(variable)=string makes no sense.

  2. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

Didn't realise I had, only use mt4 so going onto mt5 was not a deliberate choice. Variable (NAME) is a string and it is compiled from symbol(), to me everything I wrote was in a logical place, but maybe this is why I have struggled to get this code working. 

 
jstap:

Didn't realise I had, only use mt4 so going onto mt5 was not a deliberate choice. Variable (NAME) is a string and it is compiled from symbol(), to me everything I wrote was in a logical place, but maybe this is why I have struggled to get this code working. 

Show your actual code.

Use the code button (Alt+S) when pasting code.

 
Keith Watford:

Show your actual code.

Use the code button (Alt+S) when pasting code.

The following code is what I have ended back at, all variables contain required info (I think), this code doesn't contain else as just getting 1 if working is what I am concentrating on, also code when working is added to other code to get final result (bite size learning seems to help).

        if (string NAME = string TEST == true)
{
        string RESULT = string INTO;
}
 
jstap:

Didn't realise I had, only use mt4 so going onto mt5 was not a deliberate choice.

Variable (NAME) is a string and it is compiled from symbol(),

        if (string NAME = string TEST == true)
  1. It was you that mentioned MT4 (in your original post).
  2. Symbo() is a function call. You can't compile from it. You post makes no sense.
  3. Babel; invalid code.
 
William Roeder:
  1. It was you that mentioned MT4 (in your original post).
  2. Symbo() is a function call. You can't compile from it. You post makes no sense.
  3. Babel; invalid code.


This screen shot shows what I gat in a variable from symbol() (2nd up bottom right), this is achieved by a 3rd party software so the full code to achieve this is not known, I can also add other snippets of code that is mql4 specific, in the top right it shows a value from another variable, but I think if |I could achieve this from added code it would all run a little smother and correctly.

 
jstap: Hopefully someone can help, my knowledge on mt4 code is limited, I am trying to wright nested if statements, what I am trying to do is:

if NAME(variable)=string1(typed into code) then insert number(double typed into code) into RESULT(variable), else if NAME=string2 insert a different number into RESULT. This continues until match is found or value 0.0 is inserted into RESULT. Forgot to mention, NAME is the symbol attached to, us ing Symbol(); to obtain.

jstap:

The following code is what I have ended back at, all variables contain required info (I think), this code doesn't contain else as just getting 1 if working is what I am concentrating on, also code when working is added to other code to get final result (bite size learning seems to help).

It is very difficult to understand your question because it seems you know very little about MQL or even coding in general, but is this perhaps what you are trying to explain?

string Name   = Symbol(), Test[]  = { "EURUSD", "EURGBP", "USDJPY" };
double Result = 0,        Value[] = { 15.0,     20.0,     25.0     };

int Count = ArraySize( Test );

for( int i = 0; i < Count; i++ )
{
   if( Name == Test[i] )
   {
      Result = Value[i];
      break;
   }
}

Please note, that this code is untested and uncompiled. It serves only to see if we can figure out what you are trying to ask.

 
Fernando Carreiro:

It is very difficult to understand your question because it seems you know very little about MQL or even coding in general, but is this perhaps what you are trying to explain?

Please note, that this code is untested and uncompiled. It serves only to see if we can figure out what you are trying to ask.

Thank you for this, it looks like this may do what I am trying to achieve, I will try to use now and see what happens.

 
Fernando Carreiro:

It is very difficult to understand your question because it seems you know very little about MQL or even coding in general, but is this perhaps what you are trying to explain?

Please note, that this code is untested and uncompiled. It serves only to see if we can figure out what you are trying to ask.

After a while trying to get this code to work I have failed, I am getting compilation errors, (see picture).



I do not think it is your code as this code works perfectly:


for (int i=0; i <= SymbolsTotal(false); i++)
        {
                if(StringFind(SymbolName(i, false), namepart)!=-1)
                {
                        sym = SymbolName(i, false);
                        break;
                }
        }

can you see what I am doing wrong?

 
jstap: After a while trying to get this code to work I have failed, I am getting compilation errors, (see picture). I do not think it is your code as this code works perfectly: can you see what I am doing wrong?

Sorry, but you are using a 3rd party tool, to build an EA. That builder is known for creating very bad code. It also means you don't understand MQL coding at all, so you will be unable to properly apply any advice we give you.

Reason: