Comment Fix

 

Good morning 


I have a feeling there is a simple fix to the solution and I risk looking super dumb. 

But here goes...

The code below compiles fine, however I cannot get the RichterScale calculation to post the needed calculation in MetaTrader.


int MaxVolumePos;
long MaxVolumeVal;
int MinVolumePos;
long MinVolumeVal; 
long CurrentVolume;
long AverageVolume;
long BarCount = Bars;




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+-------------------------------------------------------------------+
void OnTick()
  {
   if (ArraySize(Volume)>1)
      {      
       MaxVolumePos = ArrayMaximum(Volume, WHOLE_ARRAY, 1);
       MaxVolumeVal = Volume[MaxVolumePos];
       MinVolumePos = ArrayMinimum(Volume, WHOLE_ARRAY, 1);
       MinVolumeVal = Volume[MinVolumePos];
       CurrentVolume = Volume[0];
       long RichterScale = (Volume[0]/(MaxVolumeVal));
       long SumVolume=0;
       for (int i=1;i<Bars; i++)
       {
        SumVolume = (SumVolume + Volume[i]);
        AverageVolume = (SumVolume/(BarCount-1));
       }
       Print(RichterScale);
       Comment(StringFormat("Volume Scouter Report:\n RichterScale:%G \n CurrentVolume:%G \n AverageVolume:%G \n MaxVolumePos:%G\n MaxVolumeVal:%G\n MinVolumePos:%G\n MinVolumeVal:%G",RichterScale,CurrentVolume,AverageVolume,MaxVolumePos,MaxVolumeVal,MinVolumePos,MinVolumeVal));
       //if (RichterScale>70)
 

Hi please try

DoubleToString(RichterScale,0)

or

(string)RichterScale,
 
Robocop01: I have a feeling there is a simple fix to the solution and I risk looking super dumb. 

But here goes... The code below compiles fine, however I cannot get the RichterScale calculation to post the needed calculation in MetaTrader.

Given that “MaxVolumeVal” is a long and that "Volume[]" might also be a long, then should the value of "MaxVolumeVal" be greater than "Volume[0]", then the result will always be 0 because you are carrying out integer division (ie. a long divided by a long).

Example: for integer division 1/2 = 0, 3/4 = 0, while floating point division, 1/2 = 0.5, 3/4 = 0.75 

So, you will have to work with doubles or at least cast the longs to doubles to get a meaningful value. Obviously, "RichterScale" will also have to a double.

This also applies to other variables, such as "AverageVolume", etc.