0
Views
0
Downloads
0
Favorites
MomemtInTime
//+------------------------------------------------------------------+
//| MomemtInTime.mq5 |
//| Copyright © 2010, LeMan. |
//| b-market@mail.ru |
//+------------------------------------------------------------------+
//---- author of the indicator
#property copyright "Copyright © 2010, LeMan."
#property link "b-market@mail.ru"
//---- indicator version number
#property version "1.00"
//---- drawing indicator in a separate window
#property indicator_separate_window
//----two buffers are used for calculation of drawing of the indicator
#property indicator_buffers 2
//---- two plots are used
#property indicator_plots 2
//+----------------------------------------------+
//| CG indicator drawing parameters |
//+----------------------------------------------+
//---- drawing indicator 1 as a line
#property indicator_type1 DRAW_LINE
//---- red color is used as the color of the bullish line of the indicator
#property indicator_color1 Red
//---- line of the indicator 1 is a continuous curve
#property indicator_style1 STYLE_SOLID
//---- thickness of line of the indicator 1 is equal to 1
#property indicator_width1 1
//---- displaying of the bullish label of the indicator
#property indicator_label1 "MomemtInTime Oscillator"
//+----------------------------------------------+
//| Trigger indicator drawing parameters |
//+----------------------------------------------+
//---- drawing the indicator 2 as a label
#property indicator_type2 DRAW_ARROW
//---- light green color is used as the color of the indicator line
#property indicator_color2 Lime
//---- indicator 2 width is equal to 1
#property indicator_width2 1
//---- displaying of the bearish label of the indicator
#property indicator_label2 "MomemtInTime"
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input string tm="00:00";// time in the format hours:minutes
input int Shift=0; // horizontal shift of the indicator in bars
//+----------------------------------------------+
//---- declaration of dynamic arrays that further
//---- will be used as indicator buffers
double OscBuffer[];
double MomBuffer[];
//---- declaration of the integer variables for the start of data calculation
int min_rates_total;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- Initialization of variables of the start of data calculation
min_rates_total=2;
//---- set dynamic array as an indicator buffer
SetIndexBuffer(0,OscBuffer,INDICATOR_DATA);
//---- shifting the indicator 1 horizontally by Shift
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---- shifting the start of drawing of the indicator 1
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- set dynamic array as an indicator buffer
SetIndexBuffer(1,MomBuffer,INDICATOR_DATA);
//---- shifting the indicator 2 horizontally by Shift
PlotIndexSetInteger(1,PLOT_SHIFT,Shift);
//---- shifting the beginning of drawing of the indicator 2
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- indicator symbol
PlotIndexSetInteger(1,PLOT_ARROW,108);
//---- initializations of variable for indicator short name
string shortname;
StringConcatenate(shortname,"MomemtInTime(",tm,", ",Shift,")");
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---- determination of accuracy of displaying the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(
const int rates_total, // amount of history in bars at the current tick
const int prev_calculated,// amount of history in bars at the previous tick
const datetime &time[],
const double &open[],
const double& high[], // price array of maximums of price for the calculation of indicator
const double& low[], // price array of price lows for the indicator calculation
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
)
{
//---- checking the number of bars to be enough for calculation
if(rates_total<min_rates_total) return(0);
//---- declaration of local variables
int first,bar;
static double Open=0.0;
//---- calculation of the starting number 'first' for the cycle of recalculation of bars
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
{
first=min_rates_total; // starting index for calculation of all bars
}
else first=prev_calculated-1; // starting number for calculation of new bars
//---- main cycle of calculation of the indicator
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
MomBuffer[bar]=EMPTY_VALUE;
if(TimeToString(time[bar],TIME_MINUTES)==tm)
{
Open=open[bar];
MomBuffer[bar]=0.0;
}
OscBuffer[bar]=NormalizeDouble(close[bar]-Open,_Digits);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---