0
Views
0
Downloads
0
Favorites
chandeqstick_v1
//+---------------------------------------------------------------------+
//| ChandeQStick.mq5 |
//| Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2004@list.ru |
//+---------------------------------------------------------------------+
//| Place the SmoothAlgorithms.mqh file |
//| in the directory: terminal_data_folder\MQL5\Include |
//+---------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
//---- Indicator version
#property version "1.00"
//--- drawing the indicator in a separate window
#property indicator_separate_window
//---- number of indicator buffers
#property indicator_buffers 2
//---- one plot is used
#property indicator_plots 1
//+-----------------------------------+
//| Parameters of indicator drawing |
//+-----------------------------------+
//---- drawing indicator as a four-color histogram
#property indicator_type1 DRAW_COLOR_HISTOGRAM
//--- the following colors are used in the four color histogram
#property indicator_color1 clrDeepPink,clrViolet,clrGray,clrDeepSkyBlue,clrBlue
//--- Indicator line is a solid one
#property indicator_style1 STYLE_SOLID
//--- indicator line width is 2
#property indicator_width1 2
//--- displaying the indicator label
#property indicator_label1 "ChandeQStick"
//+-----------------------------------+
//| CXMA class description |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh>
//+-----------------------------------+
//--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file
CXMA XMA1;
//+-----------------------------------+
//| Indicator input parameters |
//+-----------------------------------+
input Smooth_Method XMA_Method=MODE_SMA; // Smoothing method
input uint XLength=8; // Smoothing depth
input int XPhase=15; // Smoothing parameter
// for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period;
// For VIDIA, it is a CMO period, for AMA, it is a slow moving average period
input int Shift=0; // Horizontal shift of the indicator in bars
//+-----------------------------------+
//--- declaration of dynamic arrays that
//--- will be used as indicator buffers
double IndBuffer[],ColorIndBuffer[];
//--- declaration of the integer variables for the start of data calculation
int min_rates_total;
//+------------------------------------------------------------------+
//| XMA indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- initialization of variables of the start of data calculation
min_rates_total=XMA1.GetStartBars(XMA_Method,XLength,XPhase)+1;
//--- Set dynamic array as an indicator buffer
SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);
//--- shifting the indicator 1 horizontally
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//--- shifting the start of drawing of the indicator
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,0);
//--- set dynamic array as a color index buffer
SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);
//--- initializations of a variable for the indicator short name
string shortname;
string Smooth1=XMA1.GetString_MA_Method(XMA_Method);
StringConcatenate(shortname,"ChandeQStick(",XLength,", ",Smooth1,")");
//--- Creation of the name to be displayed in a separate sub-window and in a pop up help
IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- Determining the accuracy of displaying the indicator values
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- initialization end
}
//+------------------------------------------------------------------+
//| XMA iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // number of bars in history 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[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- checking if the number of bars is enough for the calculation
if(rates_total<min_rates_total) return(0);
//--- declaration of variables with a floating point
double diff,xdiff;
//--- declaration of integer variables and getting already calculated bars
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 calculation of an indicator
first=1; // starting index for calculation of all bars
else first=prev_calculated-1; // starting number for calculation of new bars
//--- main indicator calculation loop
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
diff=(close[bar]-open[bar])/_Point;
xdiff=XMA1.XMASeries(1,prev_calculated,rates_total,XMA_Method,XPhase,XLength,diff,bar,false);
//---
IndBuffer[bar]=xdiff;
}
if(prev_calculated>rates_total || prev_calculated<=0)// Checking for the first start of the indicator calculation
first++;
//--- main cycle of the indicator coloring
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
int clr=2;
if(IndBuffer[bar]>0)
{
if(IndBuffer[bar]>IndBuffer[bar-1]) clr=4;
if(IndBuffer[bar]<IndBuffer[bar-1]) clr=3;
}
if(IndBuffer[bar]<0)
{
if(IndBuffer[bar]<IndBuffer[bar-1]) clr=0;
if(IndBuffer[bar]>IndBuffer[bar-1]) clr=1;
}
ColorIndBuffer[bar]=clr;
}
//---
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
---