Re: Coding Help

461
salexes wrote: Thu Aug 03, 2017 3:30 am I have a strange problem regarding rounding numbers.

I was using the Buy Sell Volume V 1.0 indicator via iCustom but now I wanted to integrate it directly into my indicator.... So I did that.
Below you will find the sourcecode of the indicator and my integration into my indicator.

Here is a picture of the strange rounding:
If I round it via NormalizeDouble it Roundsup 76.5 to 77.0 and 25.5 to 26.
Why are the values different ?
What do I need to do to get the exact same values? ("Note: I can not use IndicatorDigits(0); because for the other buffers i do need the numbers behind the . )

BuySellVolume SourceCode:

Code: Select all

//+-------------------------------------------------------------------+
//|                                        Buy_Sell_Volumes_v1.0.mq4  |
//|                                            Copyright © 2013, Pip  |
//|                                    http://www.pricemasterpro.com  |
//| This indicator is for personal use only.                          |
//| Please respect the intellectual rights of the original programmer |
//| and the work of others that contributed to this indicator         |
//| under no circumstances is this indicator to be sold for money or  |
//| to be repackged into a commercial package or to be distributed as |
//| original work by anyone else.                                     |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, Pip; admin@pricemasterpro.com"
#property link      "http://www.pricemasterpro.com/"
//---- indicator settings
#property  indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 6
#property indicator_color1  White
#property indicator_color2  White
#property indicator_color3  Red
#property indicator_color4  Red
#property indicator_color5  Green
#property indicator_color6  Green
#property indicator_width1  1
#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  1
#property indicator_width5  1
#property indicator_width6  1
//---- indicator buffers
double ExtVolumesBufferHisto[];
double ExtVolumesBufferLine[];
double ExtVolumesUpBufferHisto[];
double ExtVolumesUpBufferLine[];
double ExtVolumesDownBufferHisto[];
double ExtVolumesDownBufferLine[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtVolumesBufferHisto);       
   SetIndexBuffer(1,ExtVolumesBufferLine);
   SetIndexBuffer(2,ExtVolumesUpBufferHisto);
   SetIndexBuffer(3,ExtVolumesUpBufferLine);       
   SetIndexBuffer(4,ExtVolumesDownBufferHisto);
   SetIndexBuffer(5,ExtVolumesDownBufferLine);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexStyle(5,DRAW_LINE);
//---- sets default precision format for indicators visualization
   IndicatorDigits(0);   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Buy_Sell Volume Pressure");
   SetIndexLabel(0,"Total Volume");      
   SetIndexLabel(1,"Buy Volume");
   SetIndexLabel(2,"Sell Volume");
//---- sets drawing line empty value
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(3,0.0); 
   SetIndexEmptyValue(5,0.0);      
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Volumes                                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nLimit,nCountedBars;
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted
   if(nCountedBars>0) nCountedBars--;
   nLimit=Bars-nCountedBars;
//----
   for(i=0; i<nLimit; i++)
     {
    double bullp   = MathAbs(iBullsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double bearp   = MathAbs(iBearsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double vol     = iVolume(Symbol(), 0, i);
    double Buyers  = (bullp * vol) / MathMax((bullp + bearp),0.000001);
    double Sellers = (bearp * vol) / MathMax((bullp + bearp),0.000001);
   
         ExtVolumesBufferHisto[i]=vol;
         ExtVolumesBufferLine[i]=vol;
         ExtVolumesUpBufferHisto[i]=Buyers;
         ExtVolumesUpBufferLine[i]=Buyers;
         ExtVolumesDownBufferHisto[i]=Sellers; 
         ExtVolumesDownBufferLine[i]=Sellers;       
     
     }        
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

The calculation is exactly the same:

Code: Select all

int BuySellVolume(int offset, int limit){
   for(int i=offset; i<limit; i++)
     {
    double bullp   = MathAbs(iBullsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double bearp   = MathAbs(iBearsPower(NULL, 0, 1, PRICE_CLOSE, i));
    double vol     = iVolume(Symbol(), 0, i);
    double Buyers  = (bullp * vol) / MathMax((bullp + bearp),0.000001);
    double Sellers = (bearp * vol) / MathMax((bullp + bearp),0.000001);
   
         ExtVolumesBufferHisto[i]=NormalizeDouble(vol,0);
         ExtVolumesUpBufferLine[i]=NormalizeDouble(Buyers,0);
         ExtVolumesDownBufferHisto[i]=NormalizeDouble(Sellers,0);  
     }        
   return(0);
}
From the code it seems that you should check the 6th decimal
Do that and it should be clear


Re: Coding Help

462
mladen wrote: Thu Aug 03, 2017 3:50 am

From the code it seems that you should check the 6th decimal
Do that and it should be clear
I set indicator digits to 7 even but there were only zeros 76.50000000 and 25.0000000. So I still have no idea/clue why the rounding is different.


Re: Coding Help

468
Cladi39 wrote: Fri Aug 04, 2017 6:38 am Please mladen i dont know how to code OBV indicator when is OB/OS beacouse the indicator have fluctuant levels, i want to use it with Icustom when is at bottom and up of the windows.
Unfortunately those points are obvious - only after the fact
There is no way to do that in run-time

Re: Coding Help

470
traderduke wrote: Sat Aug 05, 2017 3:44 am Mladen
could you check out why this 2ma won't due mtf, it works on current.
Thanks Ray

RK-2MA histo-Diff-lines nmc.mq4
I does not show anything on any time frame (not even on current time frame)
Adjust the diff level
Also (you are missing it in the iCustom() call - along with completely wrong parameters order in the iCustom() call - once when you order the parameters as they should be, it should work


Who is online

Users browsing this forum: No registered users and 6 guests