0
Views
0
Downloads
0
Favorites
SinTrend
//+------------------------------------------------------------------+
//| SinTrend.mq5 |
//| Copyright © 2005, DVYU |
//| http://www.DVYU.ox/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, DVYU"
#property link "http://www.DVYU.ox/"
//---- indicator version
#property version "1.00"
//---- drawing the indicator in a separate window
#property indicator_separate_window
//---- number of indicator buffers 2
#property indicator_buffers 2
//---- only one plot is used
#property indicator_plots 1
//+----------------------------------------------+
//| Indicator drawing parameters |
//+----------------------------------------------+
//---- drawing the indicator as a three-color histogram
#property indicator_type1 DRAW_COLOR_HISTOGRAM
//---- the following colors are used in the histogram
#property indicator_color1 Gray,DeepPink,DodgerBlue
//---- indicator line is a solid one
#property indicator_style1 STYLE_SOLID
//---- indicator line width is equal to 2
#property indicator_width1 2
//---- displaying the indicator label
#property indicator_label1 "SinTrend"
//+----------------------------------------------+
//| Horizontal levels display parameters |
//+----------------------------------------------+
#property indicator_level2 0.0
#property indicator_levelcolor Gray
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| Enumeration for the time series selection |
//+----------------------------------------------+
enum Applied_price_ // Type of constant
{
PRICE_CLOSE_ = 1, // Close
PRICE_OPEN_, // Open
PRICE_HIGH_, // High
PRICE_LOW_, // Low
PRICE_MEDIAN_, // Median Price (HL/2)
PRICE_TYPICAL_, // Typical Price (HLC/3)
PRICE_WEIGHTED_, // Weighted Close (HLCC/4)
PRICE_SIMPLE, // Simple Price (OC/2)
PRICE_QUARTER_, // Quarted Price (HLOC/4)
PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price
PRICE_TRENDFOLLOW1_ // TrendFollow_2 Price
};
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input int g_period=30; // Period
input Applied_price_ IPC=PRICE_CLOSE; // Applied price
//+----------------------------------------------+
//---- declaration of dynamic arrays that
//---- will be used as indicator buffers
double ExtBuffer[],ColorExtBuffer[];
//---- declaration of the integer variables for the start of data calculation
int min_rates_total;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- initialization of variables of the start of data calculation
min_rates_total=g_period+1;
//---- set ExtBuffer[] dynamic array as an indicator buffer
SetIndexBuffer(0,ExtBuffer,INDICATOR_DATA);
//---- shifting the start of drawing MAPeriod indicator
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- set ColorExtBuffer[] dynamic array as an indicator buffer
SetIndexBuffer(1,ColorExtBuffer,INDICATOR_COLOR_INDEX);
//---- performing the shift of the beginning of the indicator drawing
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//---- name for the data window and the label for sub-windows
string short_name="SinTrend";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history at the current tick
const int prev_calculated,// number of bars calculated at previous call
const datetime &time[],
const double &open[],
const double& high[], // price array of maximums of price for the indicator calculation
const double& low[], // price array of minimums of price 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 the calculation
if(rates_total<min_rates_total) return(0);
//---- declarations of local variables
int first,bar;
//---- calculation of the 'first' starting index for the bars recalculation loop
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation
first=min_rates_total+1; // starting index for calculation of all bars
else first=prev_calculated-1; // starting index for calculation of new bars
//---- main indicator calculation loop
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
ExtBuffer[bar]=MathSin((PriceSeries(IPC,bar,open,low,high,close)-PriceSeries(IPC,bar-g_period,open,low,high,close))/g_period);
ColorExtBuffer[bar]=0;
if(ExtBuffer[bar]>0) ColorExtBuffer[bar]=2;
if(ExtBuffer[bar]<0) ColorExtBuffer[bar]=1;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
//| Getting values of a price time series |
//+------------------------------------------------------------------+
double PriceSeries(uint applied_price, // applied price
uint bar, // index of shift relative to the current bar for a specified number of periods back or forward
const double &Open[],
const double &Low[],
const double &High[],
const double &Close[])
{
//----
switch(applied_price)
{
//---- price constants from the ENUM_APPLIED_PRICE enumeration
case PRICE_CLOSE: return(Close[bar]);
case PRICE_OPEN: return(Open [bar]);
case PRICE_HIGH: return(High [bar]);
case PRICE_LOW: return(Low[bar]);
case PRICE_MEDIAN: return((High[bar]+Low[bar])/2.0);
case PRICE_TYPICAL: return((Close[bar]+High[bar]+Low[bar])/3.0);
case PRICE_WEIGHTED: return((2*Close[bar]+High[bar]+Low[bar])/4.0);
//----
case 8: return((Open[bar] + Close[bar])/2.0);
case 9: return((Open[bar] + Close[bar] + High[bar] + Low[bar])/4.0);
//----
case 10:
{
if(Close[bar]>Open[bar])return(High[bar]);
else
{
if(Close[bar]<Open[bar])
return(Low[bar]);
else return(Close[bar]);
}
}
//----
case 11:
{
if(Close[bar]>Open[bar])return((High[bar]+Close[bar])/2.0);
else
{
if(Close[bar]<Open[bar])
return((Low[bar]+Close[bar])/2.0);
else return(Close[bar]);
}
break;
}
//----
default: return(Close[bar]);
}
//----
}
//+------------------------------------------------------------------+
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
---