Author: 2019 © NELODI.com
0 Views
0 Downloads
0 Favorites
NLD_Volume
ÿþ//+-------------------------------------------+

//|                            NLD_Volume.mq5 |

//|                     http://www.nelodi.com |

//|             Copyright (c) 2019 NELODI.com |

//+-------------------------------------------+

#property copyright   "2019 © NELODI.com"

#property link        "http://www.nelodi.com"

#property description "NELODI - Volume"

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  C'63,63,63'

#property indicator_style1  0

#property indicator_width1  3

#property indicator_minimum 0.0

//--- input data

input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes

//---- indicator buffers

double                    ExtVolumesBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit() {

//---- buffers

   SetIndexBuffer(0,ExtVolumesBuffer,INDICATOR_DATA);

//---- name for DataWindow and indicator subwindow label

   IndicatorSetString(INDICATOR_SHORTNAME,"NLD_Volume");

//---- indicator digits

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//----

}

//+------------------------------------------------------------------+

//|  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);

//--- starting work

   int start=prev_calculated-1;

//--- correct position

   if(start<1) start=1;

//--- main cycle

   if(InpVolumeType==VOLUME_TICK)

      CalculateVolume(start,rates_total,tick_volume);

   else

      CalculateVolume(start,rates_total,volume);

//--- 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];

//---

   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];



      if(i==nRatesCount-1) {

         int ps=PeriodSeconds(PERIOD_CURRENT);

         long tnow=SymbolInfoInteger(_Symbol,SYMBOL_TIME);

         long timeleft=ps-((tnow+11*60*60*24)%ps);

         if(ps==60*60*24*7) timeleft-=60*60*24*1;

         if(timeleft<ps) dCurrVolume=dCurrVolume*ps/(ps-timeleft);

      }

      //--- calculate indicator

      ExtVolumesBuffer[i]=dCurrVolume;

   }

//---

}

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---