#property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_level1 0 //--- plot Line 1 #property indicator_label1 "Line 1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int InpBB_Period = 21; //--- indicator buffers double Buffer_VolumeIntensity[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, Buffer_VolumeIntensity); //--- 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[]) { //--- int i, j, limit; if (prev_calculated < 0) return(-1); if (prev_calculated == 0) limit = rates_total - InpBB_Period; else limit = rates_total - prev_calculated + 1; for (i = limit; i >= 0; i--) { double sum_Intensity = 0.0; int count = i + (InpBB_Period - 1); int n = 0; for(j = i; j <= count; j++) { if (high[j] - low[j] > 0) { sum_Intensity += (2 * close[j] - high[j] - low[j]) / (high[j] - low[j]); n++; } } Buffer_VolumeIntensity[i] = NormalizeDouble(sum_Intensity / n, Digits); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Thanks a lot Nagisa, this is perfectly working fine on all charts too. I have not yet tried in Tester, but hope it will working there too.
just quick questions close[] and Close[] are different, and is it necessary to use OnCalculate() ?
I will explore further on how to create a function for this, as I have separate functions file as a single source for these values for indicator as well as my EA.
int OnCalculate(const int rates_total, // Number of bars available for calculation const int prev_calculated, // Number of bars calculated in previous call 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[]) { // Local variables int i; // Bar index number int limit; // int periodMA = (InpBB_Period * 2); // volume to be divided by Moving Average prices if(prev_calculated < 0) return(-1); if(prev_calculated == 0) limit = rates_total - periodMA; else limit = rates_total - prev_calculated + 1; for (i = limit; i >= 0; i--) { double avg_Price = iMA(NULL,PERIOD_CURRENT,periodMA,0,MODE_SMA,PRICE_CLOSE,i); Normalized_Volume[i] = NormalizeDouble((volume[i] / avg_Price)*(100*get_Pips()),0); } // Number of Bars calculated in this call = return value of prev_calculated for next call return(rates_total); }Nagisa Unada:
"start()" was used in the old MT4. It does work now, but it should not be used for new system.
Thanks for update. Most examples on MT4 site still uses it, so I was not aware that it is outdated. The VolIndicater suggested by you is working perfectly with Tester too.
I am still unable to understand the error I am making while writing code. As while i am trying to code the other indicators (Normalised Volume, BandWidth and %b) i continue to get the problem of not working on all time frames and in tester.
If you don't mind, may I request you to help me out.
- www.mql5.com
Normalized_Volume[i] = NormalizeDouble(((double)tick_volume[i] / avg_Price) * (100 * get_Pips()), 0);
volume[] doesn't have values.
What's the "get_Pips()" ? I don't know it.
volume[] doesn't have values.
What's the "get_Pips()" ? I don't know it.
Wollaa ...
Thanks so much Nagisa, TickVolume worked well. I have also managed to figure out the PercentB and BandWidth Indicators, so 4 are working now with your support.
get_Pips(), I have created a function to calculate PIP value based on currency system of broker. In this case it is 0.0001.
What is the use of (double)tick_volume[i] ? My Indicator working fine without double, so can I drop it out of code?
What is the use of (double)tick_volume[i] ? My Indicator working fine without double, so can I drop it out of code?
double Normalized_Volume[]
double avg_Price
long tick_volume[]
It use a "long" variable to calculate the result of the "double", so I'm matching the variable types as a precaution.
double Normalized_Volume[]
double avg_Price
long tick_volume[]
It use a "long" variable to calculate the result of the "double", so I'm matching the variable types as a precaution.
sounds reasonable :) thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
sum_Intensity = sum_Intensity + ((2*Close[i])-High[i]-Low[i])/(High[i]-Low[i]);
Shows ZERO Divide Error while running the indicator and don't create line of indicator. However, if I run this in a script, it works fine and shows the values perfectly.