Question about nested If statements, multiple conditions, and concatenation

 

Hi, I am trying to figure this out and am a noob to this, but have done a little programming in my past in school projects

I have an indicator in MT5/MQL5 I am attempting to write. I don't know how to do the concatenation after symbolinfodouble to get the name of the pair from the array symbolNames[p] into longpricecheck[p] 

I am not sure how to structure the nested IF statements, and how to do multiple conditions with the && 

Also how to do the brackets.

Thanks in advance for any advice. 

Here is the code:


void OnTick()
  
//longprice is a global variable, these are the local variables

double longpricecheck[];
int p=0 ;

//populate longpricecheck array variable with current prices for the tick, and compare to longprice[p] array variable
//then do an alert and set the longprice[p] to null once the alert has been made.

for(p=ArraySize(symbolNames)-1; p>=0; p--){
 if (longprice[p] > 0) 
        (longpricecheck[p] = SymbolInfoDouble(" +symbolNames[p] ",SYMBOL_ASK)); 
       if (longprice[p] > longpricecheck[p])   
		Alert("Ask above the line") //&& longprice[p] = NULL;
       
 

You need to compile your code - you will immediately see the description of the error (the compiler will tell you the name of the error).

More: Please insert code   correctly: when editing a post, click Code  and paste your code in the popup window (the first time I edited your post and inserted the code correctly)

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- longprice is a global variable, these are the local variables
   double longpricecheck[];
   int p=0;
//--- populate longpricecheck array variable with current prices for the tick, and compare to longprice[p] array variable
//--- then do an alert and set the longprice[p] to null once the alert has been made.
   for(p=ArraySize(symbolNames)-1; p>=0; p--)
     {
      if(longprice[p]>0)
         (longpricecheck[p]=SymbolInfoDouble(symbolNames[p],SYMBOL_ASK));
      if(longprice[p]>longpricecheck[p])
         Alert("Ask above the line"); //&& longprice[p] = NULL;
     }
  }


MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 

Thank you for fixing my code block. It was my first time posting here. At least I got the braces fixed.

It gives me no error. I need to write code to load the longprice array, and then see what it does when compiled. I think the symbolNames[p] needs to be in quotes, but will figure it out.

 
checkmate1 # :

*** I think the symbolNames[p] needs to be in quotes, but will figure it out.

Okay, in that case I won't show your error. If you can't figure it out, then I'll help you.

 
Vladimir Karputov #:

Okay, in that case I won't show your error. If you can't figure it out, then I'll help you.

I figured it out. Thanks for your insight. I didn't need the bracket around the line under the first If statement. I just added an additional if statement instead of doing the && idea I commented off. I just set the variable to 0 instead of Null also.

 
checkmate1 # :

I figured it out. Thanks for your insight. I didn't need the bracket around the line under the first If statement. I just added an additional if statement instead of doing the && idea I commented off. I just set the variable to 0 instead of Null also.

Yes, you got it right. Well done, you solved the problem yourself!

Reason: