Files

138 lines
5.1 KiB
Plaintext
Raw Permalink Normal View History

2017-12-05 13:16:14 +01:00
//+------------------------------------------------------------------+
//| Volumes.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_style1 0
2021-04-28 17:27:12 +02:00
#property indicator_width1 1
2017-12-05 13:16:14 +01:00
#property indicator_minimum 0.0
//--- input data
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffers
double ExtVolumesBuffer[];
double ExtColorsBuffer[];
//
2021-04-28 17:27:12 +02:00
#include <AZ-INVEST/CustomBarConfig.mqh>
2017-12-05 13:16:14 +01:00
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- buffers
SetIndexBuffer(0,ExtVolumesBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Volumes");
//---- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
2020-02-23 16:21:15 +01:00
customChartIndicator.SetGetVolumesFlag();
2017-12-05 13:16:14 +01:00
//----
}
//+------------------------------------------------------------------+
//| Volumes |
//+------------------------------------------------------------------+
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[])
{
//---check for rates total
if(rates_total<2)
return(0);
2021-04-28 17:27:12 +02:00
2017-12-05 13:16:14 +01:00
//
2021-04-28 17:27:12 +02:00
// Process data through MedianRenko indicator
2017-12-05 13:16:14 +01:00
//
2020-02-23 16:21:15 +01:00
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
2017-12-05 13:16:14 +01:00
return(0);
2021-04-28 17:27:12 +02:00
2020-02-23 16:21:15 +01:00
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
2021-04-28 17:27:12 +02:00
2017-12-05 13:16:14 +01:00
//
// Make the following modifications in the code below:
//
2020-02-23 16:21:15 +01:00
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
2017-12-05 13:16:14 +01:00
//
2020-02-23 16:21:15 +01:00
// customChartIndicator.Open[] should be used instead of open[]
// customChartIndicator.Low[] should be used instead of low[]
// customChartIndicator.High[] should be used instead of high[]
// customChartIndicator.Close[] should be used instead of close[]
2017-12-05 13:16:14 +01:00
//
2021-04-28 17:27:12 +02:00
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
2017-12-05 13:16:14 +01:00
//
2021-04-28 17:27:12 +02:00
// customChartIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
2020-02-23 16:21:15 +01:00
// (!) customChartIndicator.SetGetTimeFlag() must be called in OnInit() for customChartIndicator.Time[] to be used
2017-12-05 13:16:14 +01:00
//
2020-02-23 16:21:15 +01:00
// customChartIndicator.Tick_volume[] should be used instead of TickVolume[]
// customChartIndicator.Real_volume[] should be used instead of Volume[]
// (!) customChartIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
2017-12-05 13:16:14 +01:00
//
2020-02-23 16:21:15 +01:00
// customChartIndicator.Price[] should be used instead of Price[]
// (!) customChartIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for customChartIndicator.Price[] to be used
2017-12-05 13:16:14 +01:00
//
2020-02-23 16:21:15 +01:00
int _prev_calculated = customChartIndicator.GetPrevCalculated();
2017-12-05 13:16:14 +01:00
//
//
//
//--- starting work
int start=_prev_calculated-1;
//--- correct position
if(start<1) start=1;
//--- main cycle
if(InpVolumeType==VOLUME_TICK)
2020-02-23 16:21:15 +01:00
CalculateVolume(start,rates_total,customChartIndicator.Tick_volume);
2017-12-05 13:16:14 +01:00
else
2020-02-23 16:21:15 +01:00
CalculateVolume(start,rates_total,customChartIndicator.Real_volume);
2017-12-05 13:16:14 +01:00
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CalculateVolume(const int nPosition,
const int nRatesCount,
const long &SrcBuffer[])
{
ExtVolumesBuffer[0]=(double)SrcBuffer[0];
ExtColorsBuffer[0]=0.0;
//---
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
//--- get some data from src buffer
double dCurrVolume=(double)SrcBuffer[i];
double dPrevVolume=(double)SrcBuffer[i-1];
//--- calculate indicator
ExtVolumesBuffer[i]=dCurrVolume;
if(dCurrVolume>dPrevVolume)
ExtColorsBuffer[i]=0.0;
else
ExtColorsBuffer[i]=1.0;
}
//---
}
//+------------------------------------------------------------------+