Bug or me?

 

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

 
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

 
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

 
It is our bug. Thank you for your message.
 

Fixed

 

Tests fine now. Thank you.

Jellybean

Reason: