Download MetaTrader 5

Bug or me?

To add comments, please log in or register
Take active part in the life of the community. Improve your rating!
Tony
261
Tony 2009.12.10 21:30 

Hi

I have a problem where the spread data in the OnCalculate() parameters sometimes is equal to -bid. It behaves as though the ask value is zero.

When I calculate the spread using the MqlTick values I have no error.

I will attach my test indicator and the output in Experts tab.

Do others have this problem?

Have I coded something wrong?

Is it a bug?


//==============================================================================================
// SpreadTest.mq5
//==============================================================================================

#property copyright ""
#property link      ""
#property version   "1.00"
#property indicator_chart_window

//----------------------------------------------------------------------------------------------
// Custom indicator iteration
//----------------------------------------------------------------------------------------------
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[] )
{
   double SpreadPrice;

   ArraySetAsSeries( spread, true );

   // calculate spread from tick values
   MqlTick LastTick;
   bool OK = SymbolInfoTick( Symbol(), LastTick );
   if( OK )
      SpreadPrice = LastTick.ask - LastTick.bid;
   else
      Print( "SymbolInfoTick() failed. Error = ", GetLastError() );

   // print calculated and timeseries values of spread
   PrintFormat( "bid = %.4f, ask = %.4f, SpreadPrice/_Point = %d, spread[0] = %d",
               LastTick.bid, LastTick.ask, int(SpreadPrice/_Point), spread[0] );

   return( rates_total );
}
//==============================================================================================




Any help appreciated.

Cheers

Jellybean

Paul
784
Paul 2009.12.11 01:57  
Jellybean :

Hi

I have a problem where the spread data in the OnCalculate() parameters sometimes is equal to -bid. It behaves as though the ask value is zero.

When I calculate the spread using the MqlTick values I have no error.

I will attach my test indicator and the output in Experts tab.

Do others have this problem?

Have I coded something wrong?

Is it a bug?

Any help appreciated.

Cheers

Jellybean

 

Looks like a bug to me. 

 

The -146962 is clearly wrong.  For the others, to properly check if Ask-Bid is exactly equal to spread[0], you should use (int)Mathround(SpreadPrice/_Point), since sometimes SpreadPrice/_Point will come up with an answer like 12.9999999999999

Tony
261
Tony 2009.12.11 08:42  
phampton :

 

Looks like a bug to me. 

 

The -146962 is clearly wrong.  For the others, to properly check if Ask-Bid is exactly equal to spread[0], you should use (int)Mathround(SpreadPrice/_Point), since sometimes SpreadPrice/_Point will come up with an answer like 12.9999999999999

Thanks Paul


I guessed that rounding was the reason for the 'good' values not being equal, but thanks for the tip on how to do it.


Any comments from MetaQuotes on the negative spread values?


Cheers

Jellybean


Ilyas
1206
Ilyas 2009.12.11 11:56  
It is our bug. Thank you for your message.
Ilyas
1206
Ilyas 2009.12.21 11:03  

Fixed

Tony
261
Tony 2009.12.29 01:38  

Tests fine now. Thank you.

Jellybean

To add comments, please log in or register