Where do the values an indicator shows come from?

 

Hi,

I'm trying to replicate a graphic Price Channel indicator and I've decided to right away copy and paste its code in my EA. The problem is that the indicator shows a value of 4 decimals when you hover the mouse on it, and I have no idea what's it doing: it's not rounding and it's not trimming, sometimes it rounds up, sometimes it doesn't. I'd like to ask to someone who's familiar with indicators where, on its code, is the part that makes it show 4 decimals (and not 5, like the variables "lasthigh" and "lastlow" show on an alert). I attach the code of the indicator. Thanks a lot.

#property copyright "Copyright © 2005, Xaoc"
#property link      "http://forex.xcd.ru/"

#property indicator_chart_window
#property indicator_buffers 2 

#property indicator_color1 Blue 
#property indicator_color2 Red 

double topband[]; 
double botband[]; 

//---- input parameters
extern int       PCPeriod=55;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2); 
    
   SetIndexBuffer(0,topband); 
   SetIndexStyle(0, DRAW_LINE, EMPTY, 2, Blue)
   SetIndexDrawBegin(0,2); 
   IndicatorShortName("PChan"); 
   SetIndexLabel(0,"TOPBAND");  
    
   SetIndexBuffer(1,botband); 
   SetIndexStyle(1, DRAW_LINE, EMPTY, 2, Red); 
   SetIndexDrawBegin(1,2); 
   SetIndexLabel(1,"BOTBAND");  
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    shift,counted_bars=IndicatorCounted(); 
   double lasthigh=0;
   double lastlow=0;
   //double ma40dbl; 
//---- TODO: add your code here 
   //ma40dbl=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,0); 

  //---- check for possible errors 
     if(counted_bars<0) return(-1); 
  //---- last counted bar will be recounted 
     if(counted_bars>0) counted_bars--; 
     //limit=Bars-counted_bars; 
  //---- main loop 
//---- main calculation loop 
   shift=Bars-1; 
   while(shift>=0) 
     { 
     topband[shift]=lasthigh;
     botband[shift]=lastlow;
     lasthigh=High[Highest(NULL,0,MODE_HIGH,PCPeriod,shift)];     
     lastlow=Low[Lowest(NULL,0,MODE_LOW,PCPeriod,shift)];
     shift--;//
     }
//---- 
   
//----
   return(0);
  }
Documentation on MQL5: Math Functions / MathFloor
Documentation on MQL5: Math Functions / MathFloor
  • www.mql5.com
MathFloor - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
marclfp: I've decided to right away copy and paste its code in my EA. T

Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 programming forum #33 2017.05.23

 
William Roeder:

Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 programming forum #33 2017.05.23

That was really helpful. Thanks a lot William.