Strange problem

 

Hi,

I have a loop where I compare double values with another double like this:


double x = 4.0;

for ( loop )
{

  if(value > x) Print(value);

}


The problem is the output looks like this:

14.94  
0.79  
4.50 
2.61
3.97
1.50
9.34
0.85

Why does it print values that are not greater than x ?

 
meta_trader2352345: Why does it print values that are not greater than x ?

Do not post code that will not even compile.

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.

Always post all relevant code (using Code button) or attach the source file. Or use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:

Do not post code that will not even compile.

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.

Always post all relevant code (using Code button) or attach the source file. Or use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

There's nothing else to it really. I have already narrowed down the problem for you.
 
meta_trader2352345 #There's nothing else to it really. I have already narrowed down the problem for you.

No you have not! You have only presented a summary of what you think is required. The code you have presented does not show the issue.

If you really want help, then show your actual code with the real issue.

If you don't want to show your actual code, then please use the built-in debugger in MetaEditor to debug your code and find the problem.

 
mind reading engaged ....... troooom  kaboom  .....
double x = 4.0;

for ( loop )
{
if(value > x) //  <------<<  when this is true 
{
 Print(value); // then only will this print . 
}
Print(value); // <-------<< Print outside of an if statement will print the value every time the loop is run .    :-)
}
 
Christopher Hubert Gainsford #:
 Print outside of an if statement will print the value every time the loop is run .
Unfortunately not the case. 
 
Christopher Hubert Gainsford #:
mind reading engaged ....... troooom  kaboom  .....

😂

i was thinking maybe #property strict and value is declared elsewhere 

 
Fernando Carreiro #:

No you have not! You have only presented a summary of what you think is required. The code you have presented does not show the issue.

If you really want help, then show your actual code with the real issue.

If you don't want to show your actual code, then please use the built-in debugger in MetaEditor to debug your code and find the problem.

Fine I will post the real code if you guys insist.

#property strict

void OnStart()
{

bool OnlyMarketWatch = true;
double minimum_rate = 4.0;


for(int pos=0;pos < SymbolsTotal(OnlyMarketWatch); pos++)
   {
    string symbol = SymbolName(pos,OnlyMarketWatch);
    double swap_long = MarketInfo(symbol,MODE_SWAPLONG);
    double swap_short = MarketInfo(symbol,MODE_SWAPSHORT);
    double swap_type = MarketInfo(symbol,MODE_SWAPTYPE);
  
   
   if(swap_type==0) 
      {

       if(swap_long > minimum_rate) 
          {
           Print(swap_long); 
           }

        if (swap_short > minimum_rate) 
         {
         Print(swap_short); 
         } 

      } 
   
   
   }  
   

} 
 
Lorentzos Roussos #:

😂

i was thinking maybe #property strict and value is declared elsewhere 

#property strict ?
 
meta_trader2352345 #:

Fine I will post the real code if you guys insist.

theres nothing wrong with it 

 
meta_trader2352345 #: Fine I will post the real code if you guys insist.

It seems that what is "wrong" is that you are not identifying your Prints, so you are unable to see which print belongs to what, leading to confusion.

And while your are it, best to print out the value of "minimum_rate" to make sure of its value, just as a debugging precaution.

if(swap_long > minimum_rate) 
{
   Print( "swap_long: ", swap_long, ", minimum_rate: ", minimum_rate ); 
}

if (swap_short > minimum_rate) 
{
   Print( "swap_short: ", swap_short, ", minimum_rate: ", minimum_rate ); 
}
EDIT: You might want to Print out the Symbol's name as well to help identify the values and make sure they are in agreement with the contract specifications.
Reason: