Need help with MT4 indicator.

 
Good day dear colleagues.

Please help me with the following problem: I collect data into 2 arrays ( iClose[i]-iClose[i+1] ) and, depending on > or < 0, distribute them. Next, I need to find the average value, I sum them over a certain period. And then I divide by this period.
But when dividing by a period, I get something like: 4-05e.
Please tell me how this can be solved?

I am attaching the code:
 //Calculating: 
   for ( int i= 0 ; i<rates_total; i++)
     {
       //Disstribution 
       double Different= iClose ( NULL , 0 ,i)- iClose ( NULL , 0 ,i+ 1 );
       if (Different> 0 )
        {
         InfoUp[i]=Different;
        }
       if (Different< 0 )
        {
         InfoDown[i]= MathAbs (Different);
        }
     }
   for ( int i= 0 ; i<rates_total; i++)
     {
       double UP= 0 , Down= 0 , AverUP= 0 , AverDown= 0 , StdU= 0 , StDD= 0 ;
       //CalculateResult&Counting 
       for ( int x=i; x<=i+LimitsForDeviation; x++)
        {
         UP=UP+InfoUp[x]; //SUM         
         Down=Down+InfoDown[x]; //SUM 
        }
      AverUP=UP/LimitsForDeviation;
      AverDown=Down/LimitsForDeviation;
Thanks to everyone who can help.
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Always post all relevant code. You reference two arrays, but didn't post the definition, whether they are resized or buffers, etc.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. You sum your arrays. What about those elements that have no value. Did you set their empty value to zero, or are you summing EMPTY_VALUE?

  4. What about bar zero changing direction? You will have both arrays set.

 
Your topic has been moved to the section: MQL4 e MetaTrader 4 — In the future, please consider which section is most appropriate for your query
MQL5 forum: Expert Advisors and Automated Trading
MQL5 forum: Expert Advisors and Automated Trading
  • www.mql5.com
How to create an Expert Advisor (a trading robot) for Forex trading
 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Always post all relevant code. You reference two arrays, but didn't post the definition, whether they are resized or buffers, etc.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. You sum your arrays. What about those elements that have no value. Did you set their empty value to zero, or are you summing EMPTY_VALUE?

  4. What about bar zero changing direction? You will have both arrays set.

//+------------------------------------------------------------------+
//|                                                 PRODeviation.mq4 |
//|                                                          VockCap |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "VockCap"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_plots   3
extern double UpLevel=75;
extern double DownLevel=25;
extern int LimitsForDeviation=10;
//--- plot ProDeviation
#property indicator_label1  "ProDeviation"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color1  clrBlue
#property indicator_color2  clrGreen
#property indicator_color3  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_style2  STYLE_SOLID
#property indicator_style3  STYLE_SOLID
#property indicator_width1  1
#property indicator_width2  2
#property indicator_width3  2
//--- indicator buffers
double ProDeviationBuffer[];
double SDU[];
double SDD[];
double InfoUp[];
double InfoDown[];
double MAUP[];
double MADOWN[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ProDeviationBuffer);
   SetIndexBuffer(1,SDU);
   SetIndexBuffer(2,SDD);
   SetIndexDrawBegin(0,0);
   SetIndexDrawBegin(1,0);
   SetIndexDrawBegin(2,0);
   SetIndexLabel(0,"ProDeviation");
   SetIndexLabel(1,"Signal Buy");
   SetIndexLabel(2,"Signal Sell");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
//DemoCheck:
   if(TimeCurrent()>D'07.07.2023')
     {
      return(0);
     }
//ArrayResize:
   ArrayResize(SDU,rates_total+LimitsForDeviation*2,10);
   ArrayResize(SDD,rates_total+LimitsForDeviation*2,10);
   ArrayResize(ProDeviationBuffer,rates_total+LimitsForDeviation*2,10);
   ArrayResize(InfoUp,rates_total+LimitsForDeviation*2,10);
   ArrayResize(InfoDown,rates_total+LimitsForDeviation*2,10);
   ArrayResize(MAUP,rates_total+LimitsForDeviation*2,10);
   ArrayResize(MADOWN,rates_total+LimitsForDeviation*2,10);
//Calculating:
   for(int i=0; i<rates_total; i++)
     {
      //Disstribution
      double Different=iClose(NULL,0,i)-iClose(NULL,0,i+1);
      if(Different>0)
        {
         InfoUp[i]=Different;
        }
      if(Different<0)
        {
         InfoDown[i]=MathAbs(Different);
        }
     }
   for(int i=0; i<rates_total; i++)
     {
      double UP=0, Down=0, AverUP=0, AverDown=0, StdU=0, StDD=0;
      //CalculateResult&Counting
      for(int x=i; x<=i+LimitsForDeviation; x++)
        {
         UP=UP+InfoUp[x]; //SUM       
         Down=Down+InfoDown[x]; //SUM
        }
      AverUP=UP/LimitsForDeviation;
      AverDown=Down/LimitsForDeviation;
      for(int ii=i; ii<=i+LimitsForDeviation; ii++)
        {
         StdU+=(InfoUp[ii]-AverUP)*(InfoUp[ii]-AverUP);
         StDD+=(InfoDown[ii]-AverDown)*(InfoDown[ii]-AverDown);
        }
      double trueStdU=MathSqrt(StdU/(LimitsForDeviation-1));
      double trueStdD=MathSqrt(StDD/(LimitsForDeviation-1));
      double Y=0;
      if(trueStdU!=0&&trueStdD!=0)
        {
         Y=trueStdU/trueStdD;
        }
      double RSI=100-100/(1+Y);
      if(RSI<DownLevel)
        {
         SDU[i]=RSI;
        }
      if(RSI>UpLevel)
        {
         SDD[i]=RSI;
        }
      ProDeviationBuffer[i]=RSI;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Greetings!

This is all code: