First commit [09/03/2018]

This commit is contained in:
Pierre8rTeam
2018-03-09 16:43:19 +01:00
commit 25e9006a0b
375 changed files with 294601 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
//+------------------------------------------------------------------+
//| AD.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Accumulation/Distribution"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_label1 "A/D"
//--- input params
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volume type
//---- buffers
double ExtADbuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- indicator short name
IndicatorSetString(INDICATOR_SHORTNAME,"A/D");
//---- index buffer
SetIndexBuffer(0,ExtADbuffer);
//--- set index draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Accumulation/Distribution |
//+------------------------------------------------------------------+
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 bars count
if(rates_total<2)
return(0); //exit with zero result
//--- get current position
int pos=prev_calculated-1;
if(pos<0) pos=0;
//--- calculate with appropriate volumes
if(InpVolumeType==VOLUME_TICK)
Calculate(rates_total,pos,high,low,close,tick_volume);
else
Calculate(rates_total,pos,high,low,close,volume);
//----
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculating with selected volume |
//+------------------------------------------------------------------+
void Calculate(const int rates_total,const int pos,
const double &high[],
const double &low[],
const double &close[],
const long &volume[])
{
double hi,lo,cl;
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- get some data from arrays
hi=high[i];
lo=low[i];
cl=close[i];
//--- calculate new AD
double sum=(cl-lo)-(hi-cl);
if(hi==lo) sum=0.0;
else sum=(sum/(hi-lo))*volume[i];
if(i>0) sum+=ExtADbuffer[i-1];
ExtADbuffer[i]=sum;
}
//----
}
//+------------------------------------------------------------------+
+152
View File
@@ -0,0 +1,152 @@
//+------------------------------------------------------------------+
//| ADX.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Average Directional Movement Index"
#include <MovingAverages.mqh>
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_type2 DRAW_LINE
#property indicator_color2 YellowGreen
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
#property indicator_type3 DRAW_LINE
#property indicator_color3 Wheat
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
#property indicator_label1 "ADX"
#property indicator_label2 "+DI"
#property indicator_label3 "-DI"
//--- input parameters
input int InpPeriodADX=14; // Period
//---- buffers
double ExtADXBuffer[];
double ExtPDIBuffer[];
double ExtNDIBuffer[];
double ExtPDBuffer[];
double ExtNDBuffer[];
double ExtTmpBuffer[];
//--- global variables
int ExtADXPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input parameters
if(InpPeriodADX>=100 || InpPeriodADX<=0)
{
ExtADXPeriod=14;
printf("Incorrect value for input variable Period_ADX=%d. Indicator will use value=%d for calculations.",InpPeriodADX,ExtADXPeriod);
}
else ExtADXPeriod=InpPeriodADX;
//---- indicator buffers
SetIndexBuffer(0,ExtADXBuffer);
SetIndexBuffer(1,ExtPDIBuffer);
SetIndexBuffer(2,ExtNDIBuffer);
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,ExtTmpBuffer,INDICATOR_CALCULATIONS);
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXPeriod<<1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXPeriod);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXPeriod);
//--- indicator short name
string short_name="ADX("+string(ExtADXPeriod)+")";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- change 1-st index label
PlotIndexSetString(0,PLOT_LABEL,short_name);
//---- end of initialization function
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//--- checking for bars count
if(rates_total<ExtADXPeriod)
return(0);
//--- detect start position
int start;
if(prev_calculated>1) start=prev_calculated-1;
else
{
start=1;
ExtPDIBuffer[0]=0.0;
ExtNDIBuffer[0]=0.0;
ExtADXBuffer[0]=0.0;
}
//--- main cycle
for(int i=start;i<rates_total && !IsStopped();i++)
{
//--- get some data
double Hi =high[i];
double prevHi=high[i-1];
double Lo =low[i];
double prevLo=low[i-1];
double prevCl=close[i-1];
//--- fill main positive and main negative buffers
double dTmpP=Hi-prevHi;
double dTmpN=prevLo-Lo;
if(dTmpP<0.0) dTmpP=0.0;
if(dTmpN<0.0) dTmpN=0.0;
if(dTmpP>dTmpN) dTmpN=0.0;
else
{
if(dTmpP<dTmpN) dTmpP=0.0;
else
{
dTmpP=0.0;
dTmpN=0.0;
}
}
//--- define TR
double tr=MathMax(MathMax(MathAbs(Hi-Lo),MathAbs(Hi-prevCl)),MathAbs(Lo-prevCl));
//---
if(tr!=0.0)
{
ExtPDBuffer[i]=100.0*dTmpP/tr;
ExtNDBuffer[i]=100.0*dTmpN/tr;
}
else
{
ExtPDBuffer[i]=0.0;
ExtNDBuffer[i]=0.0;
}
//--- fill smoothed positive and negative buffers
ExtPDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtPDIBuffer[i-1],ExtPDBuffer);
ExtNDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtNDIBuffer[i-1],ExtNDBuffer);
//--- fill ADXTmp buffer
double dTmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
if(dTmp!=0.0)
dTmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/dTmp);
else
dTmp=0.0;
ExtTmpBuffer[i]=dTmp;
//--- fill smoothed ADX buffer
ExtADXBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtADXBuffer[i-1],ExtTmpBuffer);
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+184
View File
@@ -0,0 +1,184 @@
//+------------------------------------------------------------------+
//| ADXW.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Average Directional Movement Index"
#property description "by Welles Wilder"
#include <MovingAverages.mqh>
//---
#property indicator_separate_window
#property indicator_buffers 10
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
#property indicator_color2 YellowGreen
#property indicator_type3 DRAW_LINE
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
#property indicator_color3 Wheat
#property indicator_label1 "ADX Wilder"
#property indicator_label2 "+DI"
#property indicator_label3 "-DI"
//--- input parameters
input int InpPeriodADXW=14; // Period
//---- buffers
double ExtADXWBuffer[];
double ExtPDIBuffer[];
double ExtNDIBuffer[];
double ExtPDSBuffer[];
double ExtNDSBuffer[];
double ExtPDBuffer[];
double ExtNDBuffer[];
double ExtTRBuffer[];
double ExtATRBuffer[];
double ExtDXBuffer[];
//--- global variable
int ExtADXWPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input parameters
if(InpPeriodADXW>=100 || InpPeriodADXW<=0)
{
ExtADXWPeriod=14;
printf("Incorrect value for input variable InpPeriodADXW=%d. Indicator will use value=%d for calculations.",InpPeriodADXW,ExtADXWPeriod);
}
else ExtADXWPeriod=InpPeriodADXW;
//---- indicator buffers
SetIndexBuffer(0,ExtADXWBuffer);
SetIndexBuffer(1,ExtPDIBuffer);
SetIndexBuffer(2,ExtNDIBuffer);
//--- calculation buffers
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,ExtDXBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,ExtTRBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(7,ExtATRBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(8,ExtPDSBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(9,ExtNDSBuffer,INDICATOR_CALCULATIONS);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXWPeriod<<1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
//--- indicator short name
string short_name="ADX Wilder("+string(ExtADXWPeriod)+")";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- change 1-st index label
PlotIndexSetString(0,PLOT_LABEL,short_name);
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,2);
//---- end of initialization function
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//--- checking for bars count
if(rates_total<ExtADXWPeriod)
return(0);
//--- detect start position
int start;
if(prev_calculated>1) start=prev_calculated-1;
else
{
start=1;
for(int i=0;i<ExtADXWPeriod;i++)
{
ExtADXWBuffer[i]=0;
ExtPDIBuffer[i]=0;
ExtNDIBuffer[i]=0;
ExtPDSBuffer[i]=0;
ExtNDSBuffer[i]=0;
ExtPDBuffer[i]=0;
ExtNDBuffer[i]=0;
ExtTRBuffer[i]=0;
ExtATRBuffer[i]=0;
ExtDXBuffer[i]=0;
}
}
//--- main cycle
for(int i=start;i<rates_total && !IsStopped();i++)
{
//--- get some data
double Hi =high[i];
double prevHi=high[i-1];
double Lo =low[i];
double prevLo=low[i-1];
double prevCl=close[i-1];
//--- fill main positive and main negative buffers
double dTmpP=Hi-prevHi;
double dTmpN=prevLo-Lo;
if(dTmpP<0.0) dTmpP=0.0;
if(dTmpN<0.0) dTmpN=0.0;
if(dTmpN==dTmpP)
{
dTmpN=0.0;
dTmpP=0.0;
}
else
{
if(dTmpP<dTmpN) dTmpP=0.0;
else dTmpN=0.0;
}
ExtPDBuffer[i]=dTmpP;
ExtNDBuffer[i]=dTmpN;
//--- define TR
double tr=MathMax(MathMax(MathAbs(Hi-Lo),MathAbs(Hi-prevCl)),MathAbs(Lo-prevCl));
//--- write down TR to TR buffer
ExtTRBuffer[i]=tr;
//--- fill smoothed positive and negative buffers and TR buffer
if(i<ExtADXWPeriod)
{
ExtATRBuffer[i]=0.0;
ExtPDIBuffer[i]=0.0;
ExtNDIBuffer[i]=0.0;
}
else
{
ExtATRBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtATRBuffer[i-1],ExtTRBuffer);
ExtPDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtPDSBuffer[i-1],ExtPDBuffer);
ExtNDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtNDSBuffer[i-1],ExtNDBuffer);
}
//--- calculate PDI and NDI buffers
if(ExtATRBuffer[i]!=0.0)
{
ExtPDIBuffer[i]=100.0*ExtPDSBuffer[i]/ExtATRBuffer[i];
ExtNDIBuffer[i]=100.0*ExtNDSBuffer[i]/ExtATRBuffer[i];
}
else
{
ExtPDIBuffer[i]=0.0;
ExtNDIBuffer[i]=0.0;
}
//--- Calculate DX buffer
double dTmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
if(dTmp!=0.0) dTmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/dTmp);
else dTmp=0.0;
ExtDXBuffer[i]=dTmp;
//--- fill ADXW buffer as smoothed DX buffer
ExtADXWBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtADXWBuffer[i-1],ExtDXBuffer);
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+130
View File
@@ -0,0 +1,130 @@
//+------------------------------------------------------------------+
//| AMA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property description "Adaptive Moving Average"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//---- plot ExtAMABuffer
#property indicator_label1 "AMA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- default applied price
#property indicator_applied_price PRICE_OPEN
//--- input parameters
input int InpPeriodAMA=10; // AMA period
input int InpFastPeriodEMA=2; // Fast EMA period
input int InpSlowPeriodEMA=30; // Slow EMA period
input int InpShiftAMA=0; // AMA shift
//--- indicator buffers
double ExtAMABuffer[];
//--- global variables
double ExtFastSC;
double ExtSlowSC;
int ExtPeriodAMA;
int ExtSlowPeriodEMA;
int ExtFastPeriodEMA;
//+------------------------------------------------------------------+
//| AMA initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- check for input values
if(InpPeriodAMA<=0)
{
ExtPeriodAMA=10;
printf("Input parameter InpPeriodAMA has incorrect value (%d). Indicator will use value %d for calculations.",
InpPeriodAMA,ExtPeriodAMA);
}
else ExtPeriodAMA=InpPeriodAMA;
if(InpSlowPeriodEMA<=0)
{
ExtSlowPeriodEMA=30;
printf("Input parameter InpSlowPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
InpSlowPeriodEMA,ExtSlowPeriodEMA);
}
else ExtSlowPeriodEMA=InpSlowPeriodEMA;
if(InpFastPeriodEMA<=0)
{
ExtFastPeriodEMA=2;
printf("Input parameter InpFastPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
InpFastPeriodEMA,ExtFastPeriodEMA);
}
else ExtFastPeriodEMA=InpFastPeriodEMA;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtAMABuffer,INDICATOR_DATA);
//--- set shortname and change label
string short_name="AMA("+IntegerToString(ExtPeriodAMA)+","+
IntegerToString(ExtFastPeriodEMA)+","+
IntegerToString(ExtSlowPeriodEMA)+")";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
PlotIndexSetString(0,PLOT_LABEL,short_name);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA);
//--- set index shift
PlotIndexSetInteger(0,PLOT_SHIFT,InpShiftAMA);
//--- calculate ExtFastSC & ExtSlowSC
ExtFastSC=2.0/(ExtFastPeriodEMA+1.0);
ExtSlowSC=2.0/(ExtSlowPeriodEMA+1.0);
//--- OnInit done
return(0);
}
//+------------------------------------------------------------------+
//| AMA iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
int i;
//--- check for rates count
if(rates_total<ExtPeriodAMA+begin)
return(0);
//--- draw begin may be corrected
if(begin!=0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);
//--- detect position
int pos=prev_calculated-1;
//--- first calculations
if(pos<ExtPeriodAMA+begin)
{
pos=ExtPeriodAMA+begin;
for(i=0;i<pos-1;i++) ExtAMABuffer[i]=0.0;
ExtAMABuffer[pos-1]=price[pos-1];
}
//--- main cycle
for(i=pos;i<rates_total && !IsStopped();i++)
{
//--- calculate SSC
double dCurrentSSC=(CalculateER(i,price)*(ExtFastSC-ExtSlowSC))+ExtSlowSC;
//--- calculate AMA
double dPrevAMA=ExtAMABuffer[i-1];
ExtAMABuffer[i]=pow(dCurrentSSC,2)*(price[i]-dPrevAMA)+dPrevAMA;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate ER value |
//+------------------------------------------------------------------+
double CalculateER(const int nPosition,const double &PriceData[])
{
double dSignal=fabs(PriceData[nPosition]-PriceData[nPosition-ExtPeriodAMA]);
double dNoise=0.0;
for(int delta=0;delta<ExtPeriodAMA;delta++)
dNoise+=fabs(PriceData[nPosition-delta]-PriceData[nPosition-delta-1]);
if(dNoise!=0.0)
return(dSignal/dNoise);
return(0.0);
}
//+------------------------------------------------------------------+
+112
View File
@@ -0,0 +1,112 @@
//+------------------------------------------------------------------+
//| ASI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Accumulation Swing Index"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_style1 0
#property indicator_width1 1
#property indicator_label1 "ASI"
//--- input parameter
input double InpT=300.0; // T (maximum price changing)
//---- indicator buffers
double ExtASIBuffer[];
double ExtSIBuffer[];
double ExtTRBuffer[];
//--- global variables
double ExtTpoints,ExtT;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(fabs(InpT)>1e-7)
ExtT=InpT;
else
{
ExtT=300.0;
printf("Input parameter T has wrong value. Indicator will use T = %f.",ExtT);
}
//--- define buffers
SetIndexBuffer(0,ExtASIBuffer);
SetIndexBuffer(1,ExtSIBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtTRBuffer,INDICATOR_CALCULATIONS);
//--- draw begin settings
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- calculate ExtTpoints value
if(fabs(_Point)>1e-7)
ExtTpoints=ExtT*_Point;
else
ExtTpoints=ExtT*pow(10,-_Digits);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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 bars count
if(rates_total<2) return(0);
//---
int pos;
//--- start calculation
pos=prev_calculated-1;
//--- correct position, when it's first iteration
if(pos<=0)
{
pos=1;
ExtASIBuffer[0]=0.0;
ExtSIBuffer[0]=0.0;
ExtTRBuffer[0]=high[0]-low[0];
}
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- get some data
double dPrevClose=close[i-1];
double dPrevOpen=open[i-1];
double dClose=close[i];
double dHigh=high[i];
double dLow=low[i];
//--- fill TR buffer
ExtTRBuffer[i]=MathMax(dHigh,dPrevClose)-MathMin(dLow,dPrevClose);
double ER=0.0;
if(!(dPrevClose>=dLow && dPrevClose<=dHigh))
{
if(dPrevClose>dHigh) ER=MathAbs(dHigh-dPrevClose);
if(dPrevClose<dLow) ER=MathAbs(dLow-dPrevClose);
}
double K=MathMax(MathAbs(dHigh-dPrevClose),MathAbs(dLow-dPrevClose));
double SH=MathAbs(dPrevClose-dPrevOpen);
double R=ExtTRBuffer[i]-0.5*ER+0.25*SH;
//--- calculate SI value
if(R==0.0 || ExtTpoints==0.0) ExtSIBuffer[i]=0.0;
else ExtSIBuffer[i]=50*(dClose-dPrevClose+0.5*(dClose-open[i])+
0.25*(dPrevClose-dPrevOpen))*(K/ExtTpoints)/R;
//--- write down ASI buffer value
ExtASIBuffer[i]=ExtASIBuffer[i-1]+ExtSIBuffer[i];
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+96
View File
@@ -0,0 +1,96 @@
//+------------------------------------------------------------------+
//| ATR.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Average True Range"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_label1 "ATR"
//--- input parameters
input int InpAtrPeriod=14; // ATR period
//--- indicator buffers
double ExtATRBuffer[];
double ExtTRBuffer[];
//--- global variable
int ExtPeriodATR;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(InpAtrPeriod<=0)
{
ExtPeriodATR=14;
printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
}
else ExtPeriodATR=InpAtrPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
//--- name for DataWindow and indicator subwindow label
string short_name="ATR("+string(ExtPeriodATR)+")";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
PlotIndexSetString(0,PLOT_LABEL,short_name);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count
if(rates_total<=ExtPeriodATR)
return(0); // not enough bars for calculation
//--- preliminary calculations
if(prev_calculated==0)
{
ExtTRBuffer[0]=0.0;
ExtATRBuffer[0]=0.0;
//--- filling out the array of True Range values for each period
for(i=1;i<rates_total && !IsStopped();i++)
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
//--- first AtrPeriod values of the indicator are not calculated
double firstValue=0.0;
for(i=1;i<=ExtPeriodATR;i++)
{
ExtATRBuffer[i]=0.0;
firstValue+=ExtTRBuffer[i];
}
//--- calculating the first value of the indicator
firstValue/=ExtPeriodATR;
ExtATRBuffer[ExtPeriodATR]=firstValue;
limit=ExtPeriodATR+1;
}
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+140
View File
@@ -0,0 +1,140 @@
//+------------------------------------------------------------------+
//| Accelerator.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Accelerator/Decelerator"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_width1 2
#property indicator_label1 "AC"
//--- indicator buffers
double ExtACBuffer[];
double ExtColorBuffer[];
double ExtFastBuffer[];
double ExtSlowBuffer[];
double ExtAOBuffer[];
double ExtSMABuffer[];
//--- handles for MAs
int ExtFastSMAHandle;
int ExtSlowSMAHandle;
//--- bars minimum for calculation
#define DATA_LIMIT 37
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtACBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtAOBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,ExtSMABuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME,"AC");
//--- get handles
ExtFastSMAHandle=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN);
ExtSlowSMAHandle=iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
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<DATA_LIMIT)
return(0); // not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastSMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowSMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get FastSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
{
Print("Getting fast SMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
{
Print("Getting slow SMA is failed! Error",GetLastError());
return(0);
}
//--- calculations
int i,limit;
//--- first calculation or number of bars was changed
if(prev_calculated<=33)
{
for(i=0;i<33;i++)
{
ExtACBuffer[i]=0.0;
ExtAOBuffer[i]=0.0;
}
limit=33;
}
else limit=prev_calculated-1;
//--- main loop of calculations
for(i=limit;i<DATA_LIMIT;i++)
{
ExtACBuffer[i]=0.0;
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
}
for(; i<rates_total && !IsStopped(); i++)
{
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
double sumAO=0.0;
for(int j=0;j<5;j++) sumAO+=ExtAOBuffer[i-j];
ExtSMABuffer[i]=sumAO/5.0;
ExtACBuffer[i]=ExtAOBuffer[i]-ExtSMABuffer[i];
if(ExtACBuffer[i]>=ExtACBuffer[i-1])
ExtColorBuffer[i]=0.0; // set color Green
else
ExtColorBuffer[i]=1.0; // set color Red
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+145
View File
@@ -0,0 +1,145 @@
//+------------------------------------------------------------------+
//| Alligator.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_chart_window
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_label1 "Jaws"
#property indicator_label2 "Teeth"
#property indicator_label3 "Lips"
//---- input parameters
input int InpJawsPeriod=13; // Jaws period
input int InpJawsShift=8; // Jaws shift
input int InpTeethPeriod=8; // Teeth period
input int InpTeethShift=5; // Teeth shift
input int InpLipsPeriod=5; // Lips period
input int InpLipsShift=3; // Lips shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
//---- indicator buffers
double ExtJaws[];
double ExtTeeth[];
double ExtLips[];
//---- handles for moving averages
int ExtJawsHandle;
int ExtTeethHandle;
int ExtLipsHandle;
//--- bars minimum for calculation
int ExtBarsMinimum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- indicator buffers mapping
SetIndexBuffer(0,ExtJaws,INDICATOR_DATA);
SetIndexBuffer(1,ExtTeeth,INDICATOR_DATA);
SetIndexBuffer(2,ExtLips,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpTeethPeriod-1);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpLipsPeriod-1);
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpJawsShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpTeethShift);
PlotIndexSetInteger(2,PLOT_SHIFT,InpLipsShift);
//---- name for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"Jaws("+string(InpJawsPeriod)+")");
PlotIndexSetString(1,PLOT_LABEL,"Teeth("+string(InpTeethPeriod)+")");
PlotIndexSetString(2,PLOT_LABEL,"Lips("+string(InpLipsPeriod)+")");
//--- get MA's handles
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
//--- bars minimum for calculation
ExtBarsMinimum=InpJawsPeriod+InpJawsShift;
if(ExtBarsMinimum<(InpTeethPeriod+InpTeethShift))
ExtBarsMinimum=InpTeethPeriod+InpTeethShift;
if(ExtBarsMinimum<(InpLipsPeriod+InpLipsPeriod))
ExtBarsMinimum=InpLipsPeriod+InpLipsPeriod;
//--- initialization done
}
//+------------------------------------------------------------------+
//| Alligator OnCalculate function |
//+------------------------------------------------------------------+
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<ExtBarsMinimum)
return(0); // not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtJawsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtJawsHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtTeethHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtTeethHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtLipsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtLipsHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJaws)<=0)
{
Print("getting ExtJawsHandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeeth)<=0)
{
Print("getting ExtTeethHandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLips)<=0)
{
Print("getting ExtLipsHandle is failed! Error",GetLastError());
return(0);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+120
View File
@@ -0,0 +1,120 @@
//+------------------------------------------------------------------+
//| Awesome_Oscillator.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 4
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_width1 1
#property indicator_label1 "AO"
//--- indicator buffers
double ExtAOBuffer[];
double ExtColorBuffer[];
double ExtFastBuffer[];
double ExtSlowBuffer[];
//--- handles for MAs
int ExtFastSMAHandle;
int ExtSlowSMAHandle;
//--- bars minimum for calculation
#define DATA_LIMIT 33
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- indicator buffers mapping
SetIndexBuffer(0,ExtAOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,33);
//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME,"AO");
//--- get handles
ExtFastSMAHandle=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN);
ExtSlowSMAHandle=iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN);
//---- initialization done
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
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<=DATA_LIMIT)
return(0);// not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastSMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowSMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get FastSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
{
Print("Getting fast SMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
{
Print("Getting slow SMA is failed! Error",GetLastError());
return(0);
}
//--- first calculation or number of bars was changed
int i,limit;
if(prev_calculated<=DATA_LIMIT)
{
for(i=0;i<DATA_LIMIT;i++)
ExtAOBuffer[i]=0.0;
limit=DATA_LIMIT;
}
else limit=prev_calculated-1;
//--- main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
if(ExtAOBuffer[i]>ExtAOBuffer[i-1])ExtColorBuffer[i]=0.0; // set color Green
else ExtColorBuffer[i]=1.0; // set color Red
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+140
View File
@@ -0,0 +1,140 @@
//+------------------------------------------------------------------+
//| BB.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Bollinger Bands"
#include <MovingAverages.mqh>
//---
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_color2 LightSeaGreen
#property indicator_type3 DRAW_LINE
#property indicator_color3 LightSeaGreen
#property indicator_label1 "Bands middle"
#property indicator_label2 "Bands upper"
#property indicator_label3 "Bands lower"
//--- input parametrs
input int InpBandsPeriod=20; // Period
input int InpBandsShift=0; // Shift
input double InpBandsDeviations=2.0; // Deviation
//--- global variables
int ExtBandsPeriod,ExtBandsShift;
double ExtBandsDeviations;
int ExtPlotBegin=0;
//---- indicator buffer
double ExtMLBuffer[];
double ExtTLBuffer[];
double ExtBLBuffer[];
double ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input values
if(InpBandsPeriod<2)
{
ExtBandsPeriod=20;
printf("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
}
else ExtBandsPeriod=InpBandsPeriod;
if(InpBandsShift<0)
{
ExtBandsShift=0;
printf("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
}
else
ExtBandsShift=InpBandsShift;
if(InpBandsDeviations==0.0)
{
ExtBandsDeviations=2.0;
printf("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
}
else ExtBandsDeviations=InpBandsDeviations;
//--- define buffers
SetIndexBuffer(0,ExtMLBuffer);
SetIndexBuffer(1,ExtTLBuffer);
SetIndexBuffer(2,ExtBLBuffer);
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
//--- set index labels
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
//--- indexes draw begin settings
ExtPlotBegin=ExtBandsPeriod-1;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
//--- indexes shift settings
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- variables
int pos;
//--- indexes draw begin settings, when we've recieved previous begin
if(ExtPlotBegin!=ExtBandsPeriod+begin)
{
ExtPlotBegin=ExtBandsPeriod+begin;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
}
//--- check for bars count
if(rates_total<ExtPlotBegin)
return(0);
//--- starting calculation
if(prev_calculated>1) pos=prev_calculated-1;
else pos=0;
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- middle line
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,price);
//--- calculate and write down StdDev
ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod);
//--- upper line
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
//--- lower line
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
//---
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate Standard Deviation |
//+------------------------------------------------------------------+
double StdDev_Func(int position,const double &price[],const double &MAprice[],int period)
{
//--- variables
double StdDev_dTmp=0.0;
//--- check for position
if(position<period) return(StdDev_dTmp);
//--- calcualte StdDev
for(int i=0;i<period;i++) StdDev_dTmp+=MathPow(price[position-i]-MAprice[position],2);
StdDev_dTmp=MathSqrt(StdDev_dTmp/period);
//--- return calculated value
return(StdDev_dTmp);
}
//+------------------------------------------------------------------+
+132
View File
@@ -0,0 +1,132 @@
//+------------------------------------------------------------------+
//| BW-ZoneTrade.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_chart_window
#property indicator_buffers 7
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 Green,Red,Gray
#property indicator_width1 3
#property indicator_label1 "Open;High;Low;Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
double ExtAOBuffer[];
double ExtACBuffer[];
//--- handles of indicators
int ExtACHandle;
int ExtAOHandle;
//--- bars minimum for calculation
#define DATA_LIMIT 38
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(5,ExtACBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,ExtAOBuffer,INDICATOR_CALCULATIONS);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
IndicatorSetString(INDICATOR_SHORTNAME,"BW ZoneTrade");
//--- don't show indicator data in DataWindow
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
//--- sets first candle from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
//--- get handles
ExtACHandle=iAC(NULL,0);
ExtAOHandle=iAO(NULL,0);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Trade zone by Bill Williams |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count
if(rates_total<DATA_LIMIT)
return(0);// not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtACHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtACHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtAOHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtAOHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get AC buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtACHandle,0,0,to_copy,ExtACBuffer)<=0)
{
Print("Getting iAC is failed! Error",GetLastError());
return(0);
}
//--- get AO buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtAOHandle,0,0,to_copy,ExtAOBuffer)<=0)
{
Print("Getting iAO is failed! Error",GetLastError());
return(0);
}
//--- set first bar from what calculation will start
if(prev_calculated<DATA_LIMIT)
limit=DATA_LIMIT;
else
limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtOBuffer[i]=open[i];
ExtHBuffer[i]=high[i];
ExtLBuffer[i]=low[i];
ExtCBuffer[i]=close[i];
//--- set color for candle
ExtColorBuffer[i]=2.0; // set gray Color
//--- check for Green Zone and set Color Green
if(ExtACBuffer[i]>ExtACBuffer[i-1] && ExtAOBuffer[i]>ExtAOBuffer[i-1])
ExtColorBuffer[i]=0.0;
//--- check for Red Zone and set Color Red
if(ExtACBuffer[i]<ExtACBuffer[i-1] && ExtAOBuffer[i]<ExtAOBuffer[i-1])
ExtColorBuffer[i]=1.0;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+93
View File
@@ -0,0 +1,93 @@
//+------------------------------------------------------------------+
//| Bears.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Bears Power"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 Silver
#property indicator_width1 2
//--- input parameters
input int InpBearsPeriod=13; // Period
//--- indicator buffers
double ExtBearsBuffer[];
double ExtTempBuffer[];
//--- handle of EMA
int ExtEmaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtBearsBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBearsPeriod-1);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Bears("+(string)InpBearsPeriod+")");
//--- get MA handle
ExtEmaHandle=iMA(NULL,0,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count
if(rates_total<InpBearsPeriod)
return(0);// not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtEmaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtEmaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
{
Print("getting ExtEmaHandle is failed! Error",GetLastError());
return(0);
}
//--- first calculation or number of bars was changed
if(prev_calculated<InpBearsPeriod)
limit=InpBearsPeriod;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtBearsBuffer[i]=low[i]-ExtTempBuffer[i];
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+93
View File
@@ -0,0 +1,93 @@
//+------------------------------------------------------------------+
//| Bulls.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Bulls Power"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 Silver
#property indicator_width1 2
//--- input parameters
input int InpBullsPeriod=13; // Period
//--- indicator buffers
double ExtBullsBuffer[];
double ExtTempBuffer[];
//--- MA handle
int ExtEmaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtBullsBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBullsPeriod-1);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Bulls("+(string)InpBullsPeriod+")");
//--- get handle for MA
ExtEmaHandle=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count
if(rates_total<InpBullsPeriod)
return(0);// not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(ExtEmaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtEmaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
{
Print("getting ExtEmaHandle is failed! Error",GetLastError());
return(0);
}
//--- first calculation or number of bars was changed
if(prev_calculated<InpBullsPeriod)
limit=InpBullsPeriod;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i];
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+94
View File
@@ -0,0 +1,94 @@
//+------------------------------------------------------------------+
//| CCI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Commodity Channel Index"
#include <MovingAverages.mqh>
//---
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_level1 -100.0
#property indicator_level2 100.0
#property indicator_applied_price PRICE_TYPICAL
//--- input parametrs
input int InpCCIPeriod=14; // Period
//--- global variable
int ExtCCIPeriod;
//---- indicator buffer
double ExtSPBuffer[];
double ExtDBuffer[];
double ExtMBuffer[];
double ExtCCIBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value of period
if(InpCCIPeriod<=0)
{
ExtCCIPeriod=14;
printf("Incorrect value for input variable InpCCIPeriod=%d. Indicator will use value=%d for calculations.",InpCCIPeriod,ExtCCIPeriod);
}
else ExtCCIPeriod=InpCCIPeriod;
//--- define buffers
SetIndexBuffer(0,ExtCCIBuffer);
SetIndexBuffer(1,ExtDBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtMBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtSPBuffer,INDICATOR_CALCULATIONS);
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"CCI("+string(ExtCCIPeriod)+")");
//--- indexes draw begin settings
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtCCIPeriod-1);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,2);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- variables
int i,j;
double dTmp,dMul=0.015/ExtCCIPeriod;
//--- start calculation
int StartCalcPosition=(ExtCCIPeriod-1)+begin;
//--- check for bars count
if(rates_total<StartCalcPosition)
return(0);
//--- correct draw begin
if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartCalcPosition+(ExtCCIPeriod-1));
//--- calculate position
int pos=prev_calculated-1;
if(pos<StartCalcPosition)
pos=StartCalcPosition;
//--- main cycle
for(i=pos;i<rates_total && !IsStopped();i++)
{
//--- SMA on price buffer
ExtSPBuffer[i]=SimpleMA(i,ExtCCIPeriod,price);
//--- calculate D
dTmp=0.0;
for(j=0;j<ExtCCIPeriod;j++) dTmp+=MathAbs(price[i-j]-ExtSPBuffer[i]);
ExtDBuffer[i]=dTmp*dMul;
//--- calculate M
ExtMBuffer[i]=price[i]-ExtSPBuffer[i];
//--- calculate CCI
if(ExtDBuffer[i]!=0.0) ExtCCIBuffer[i]=ExtMBuffer[i]/ExtDBuffer[i];
else ExtCCIBuffer[i]=0.0;
//---
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+129
View File
@@ -0,0 +1,129 @@
//+------------------------------------------------------------------+
//| CHO.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Chaikin Oscillator"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//--- input parameters
input int InpFastMA=3; // Fast MA period
input int InpSlowMA=10; // Slow MA period
input ENUM_MA_METHOD InpSmoothMethod=MODE_EMA; // MA method
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//--- indicator buffers
double ExtCHOBuffer[];
double ExtFastEMABuffer[];
double ExtSlowEMABuffer[];
double ExtADBuffer[];
static int weightfast,weightslow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtCHOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtFastEMABuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtSlowEMABuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtADBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowMA);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"CHO("+string(InpSlowMA)+","+string(InpFastMA)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| calculate AD |
//+------------------------------------------------------------------+
double AD(double high,double low,double close,long volume)
{
double res=0;
//---
if(high!=low)
res=(2*close-high-low)/(high-low)*volume;
//---
return(res);
}
//+------------------------------------------------------------------+
//| calculate average on array |
//+------------------------------------------------------------------+
void AverageOnArray(const int mode,const int rates_total,const int prev_calculated,const int begin,
const int period,const double& source[],double& destination[],int &weightsum)
{
switch(mode)
{
case MODE_EMA:
ExponentialMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
break;
case MODE_SMMA:
SmoothedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
break;
case MODE_LWMA:
LinearWeightedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination,weightsum);
break;
default:
SimpleMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
}
}
//+------------------------------------------------------------------+
//| Chaikin Oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for rates total
if(rates_total<InpSlowMA)
return(0); // not enough bars for calculation
//--- preliminary calculations
if(prev_calculated<1)
{
limit=1;
//--- first values
if(InpVolumeType==VOLUME_TICK)
ExtADBuffer[0]=AD(high[0],low[0],close[0],tick_volume[0]);
else
ExtADBuffer[0]=AD(high[0],low[0],close[0],volume[0]);
ExtSlowEMABuffer[0]=ExtADBuffer[0];
ExtFastEMABuffer[0]=ExtADBuffer[0];
}
else limit=prev_calculated-1;
//--- calculate AD buffer
if(InpVolumeType==VOLUME_TICK)
{
for(i=limit;i<rates_total && !IsStopped();i++)
ExtADBuffer[i]=ExtADBuffer[i-1]+AD(high[i],low[i],close[i],tick_volume[i]);
}
else
{
for(i=limit;i<rates_total && !IsStopped();i++)
ExtADBuffer[i]=ExtADBuffer[i-1]+AD(high[i],low[i],close[i],volume[i]);
}
//--- calculate EMA on array ExtADBuffer
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpSlowMA,ExtADBuffer,ExtSlowEMABuffer,weightslow);
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpFastMA,ExtADBuffer,ExtFastEMABuffer,weightfast);
//--- calculate chaikin oscillator
for(i=limit;i<rates_total && !IsStopped();i++)
ExtCHOBuffer[i]=ExtFastEMABuffer[i]-ExtSlowEMABuffer[i];
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+120
View File
@@ -0,0 +1,120 @@
//+------------------------------------------------------------------+
//| CHV.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Chaikin Volatility"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- enum
enum SmoothMethod
{
SMA=0,// Simple MA
EMA=1 // Exponential MA
};
//--- input parameters
input int InpSmoothPeriod=10; // Smoothing period
input int InpCHVPeriod=10; // CHV period
input SmoothMethod InpSmoothType=EMA; // Smoothing method
//---- buffers
double ExtCHVBuffer[];
double ExtHLBuffer[];
double ExtSHLBuffer[];
//--- global variables
int ExtSmoothPeriod,ExtCHVPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input variables
string MAName;
//--- set MA name
if(InpSmoothType==SMA)
MAName="SMA";
else
MAName="EMA";
//--- check inputs
if(InpSmoothPeriod<=0)
{
ExtSmoothPeriod=10;
printf("Incorrect value for input variable InpSmoothPeriod=%d. Indicator will use value=%d for calculations.",InpSmoothPeriod,ExtSmoothPeriod);
}
else ExtSmoothPeriod=InpSmoothPeriod;
if(InpCHVPeriod<=0)
{
ExtCHVPeriod=10;
printf("Incorrect value for input variable InpCHVPeriod=%d. Indicator will use value=%d for calculations.",InpCHVPeriod,ExtCHVPeriod);
}
else ExtCHVPeriod=InpCHVPeriod;
//---- define buffers
SetIndexBuffer(0,ExtCHVBuffer);
SetIndexBuffer(1,ExtHLBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtSHLBuffer,INDICATOR_CALCULATIONS);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtSmoothPeriod+ExtCHVPeriod-1);
//--- set index label
PlotIndexSetString(0,PLOT_LABEL,"CHV("+string(ExtSmoothPeriod)+","+MAName+")");
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"Chaikin Volatility("+string(ExtSmoothPeriod)+","+MAName+")");
//--- round settings
IndicatorSetInteger(INDICATOR_DIGITS,1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//--- variables of indicator
int i,pos,posCHV;
//--- check for rates total
posCHV=ExtCHVPeriod+ExtSmoothPeriod-2;
if(rates_total<posCHV)
return(0);
//--- start working
if(prev_calculated<1)
pos=0;
else pos=prev_calculated-1;
//--- fill H-L(i) buffer
for(i=pos;i<rates_total && !IsStopped();i++) ExtHLBuffer[i]=high[i]-low[i];
//--- calculate smoothed H-L(i) buffer
if(pos<ExtSmoothPeriod-1)
{
pos=ExtSmoothPeriod-1;
for(i=0;i<pos;i++) ExtSHLBuffer[i]=0.0;
}
if(InpSmoothType==SMA)
SimpleMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
else
ExponentialMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
//--- correct calc position
if(pos<posCHV) pos=posCHV;
//--- calculate CHV buffer
for(i=pos;i<rates_total && !IsStopped();i++)
{
if(ExtSHLBuffer[i-ExtCHVPeriod]!=0.0)
ExtCHVBuffer[i]=100.0*(ExtSHLBuffer[i]-ExtSHLBuffer[i-ExtCHVPeriod])/ExtSHLBuffer[i-ExtCHVPeriod];
else
ExtCHVBuffer[i]=0.0;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
+73
View File
@@ -0,0 +1,73 @@
//+------------------------------------------------------------------+
//| FlameChart.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#include <Canvas\FlameCanvas.mqh>
//+------------------------------------------------------------------+
//| Indicator properties |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Input parameters |
//+------------------------------------------------------------------+
input int InpFuturefBars =50;
//+------------------------------------------------------------------+
//| global variables |
//+------------------------------------------------------------------+
CFlameCanvas ExtCanvas;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!ExtCanvas.FlameCreate("FlameChart",TimeCurrent(),InpFuturefBars,0))
return(INIT_FAILED);
//--- succeed
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
datetime xb1=time[rates_total-1];
double yb1=high[rates_total-1];
datetime xe1=xb1+InpFuturefBars*PeriodSeconds();
double ye1=ChartGetDouble(0,CHART_PRICE_MAX);
datetime xb2=xb1;
double yb2=low[rates_total-1];
datetime xe2=xe1;
double ye2=ChartGetDouble(0,CHART_PRICE_MIN);
//--- "nozzle" is defined using two lines: ((xb1,yb1),(xe1,ye1)) and ((xb2,yb2),(xe2,ye2))
ExtCanvas.FlameSet(xb1,yb1,xe1,ye1,xb2,yb2,xe2,ye2);
//--- result
return(rates_total);
}
//+------------------------------------------------------------------+
//| Custom indicator chart's event handler |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
{
ExtCanvas.ChartEventHandler(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
+80
View File
@@ -0,0 +1,80 @@
//+------------------------------------------------------------------+
//| ColorBars.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
//---- plot ColorBars
#property indicator_label1 "ColorBars"
#property indicator_type1 DRAW_COLOR_BARS
#property indicator_color1 Green,Red
#property indicator_label1 "Open;High;Low;Close"
//--- indicator buffers
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicators
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//--- don't show indicator data in DataWindow
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//--- auxiliary variables
int i=0;
bool vol_up=true;
//--- set position for beginning
if(i<prev_calculated) i=prev_calculated-1;
//--- start calculations
while(i<rates_total && !IsStopped())
{
ExtOpenBuffer[i]=open[i];
ExtHighBuffer[i]=high[i];
ExtLowBuffer[i]=low[i];
ExtCloseBuffer[i]=close[i];
//--- define volume change
if(i>0)
{
if(tick_volume[i]>tick_volume[i-1]) vol_up=true;
if(tick_volume[i]<tick_volume[i-1]) vol_up=false;
}
//--- set color
if(vol_up) ExtColorsBuffer[i]=0.0;
else ExtColorsBuffer[i]=1.0;
//---
i++;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+79
View File
@@ -0,0 +1,79 @@
//+------------------------------------------------------------------+
//| ColorCandlesDaily.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
//---- plot ColorCandles
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_label1 "Open;High;Low;Close"
//--- indicator buffers
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorsBuffer[];
//---
color ExtColorOfDay[6]={CLR_NONE,MediumSlateBlue,DarkGoldenrod,ForestGreen,BlueViolet,Red};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//--- set number of colors in color buffer
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,6);
//--- set colors for color buffer
for(int i=1;i<6;i++)
PlotIndexSetInteger(0,PLOT_LINE_COLOR,i,ExtColorOfDay[i]);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
printf("We have %u colors of days",PlotIndexGetInteger(0,PLOT_COLOR_INDEXES));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
int i;
MqlDateTime tstruct;
//----
if(prev_calculated<1) i=0;
else i=prev_calculated-1;
//----
while(i<rates_total && !IsStopped())
{
ExtOpenBuffer[i]=open[i];
ExtHighBuffer[i]=high[i];
ExtLowBuffer[i]=low[i];
ExtCloseBuffer[i]=close[i];
//--- set color for every candle
TimeToStruct(time[i],tstruct);
ExtColorsBuffer[i]=tstruct.day_of_week;
//---
i++;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+130
View File
@@ -0,0 +1,130 @@
//+------------------------------------------------------------------+
//| ColorLine.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
//---- plot ColorLine
#property indicator_label1 "ColorLine"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 Red,Green,Blue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
//--- indicator buffers
double ExtColorLineBuffer[];
double ExtColorsBuffer[];
//---
int ExtMAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtColorLineBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//--- get MA handle
ExtMAHandle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
}
//+------------------------------------------------------------------+
//| get color index |
//+------------------------------------------------------------------+
int getIndexOfColor(int i)
{
int j=i%300;
if(j<100) return(0);// first index
if(j<200) return(1);// second index
return(2); // third index
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
static int ticks=0,modified=0;
int limit;
//--- check data
int calculated=BarsCalculated(ExtMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- first calculation or number of bars was changed
if(prev_calculated==0)
{
//--- copy values of MA into indicator buffer ExtColorLineBuffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer)<=0) return(0);
//--- now set line color for every bar
for(int i=0;i<rates_total && !IsStopped();i++)
ExtColorsBuffer[i]=getIndexOfColor(i);
}
else
{
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- copy values of MA into indicator buffer ExtColorLineBuffer
if(IsStopped()) return(0); //Checking for stop flag
int copied=CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer);
if(copied<=0) return(0);
ticks++;// ticks counting
if(ticks>=5)//it's time to change color scheme
{
ticks=0; // reset counter
modified++; // counter of color changes
if(modified>=3)modified=0;// reset counter
ResetLastError();
switch(modified)
{
case 0:// first color scheme
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Blue);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,Green);
break;
case 1:// second color scheme
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Yellow);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Pink);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,LightSlateGray);
break;
default:// third color scheme
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,LightGoldenrod);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Orchid);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,LimeGreen);
}
}
else
{
//--- set start position
limit=prev_calculated-1;
//--- now we set line color for every bar
for(int i=limit;i<rates_total && !IsStopped();i++)
ExtColorsBuffer[i]=getIndexOfColor(i);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,183 @@
//+------------------------------------------------------------------+
//| Custom Moving Average.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_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
//--- input parameters
input int InpMAPeriod=13; // Period
input int InpMAShift=0; // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Method
//--- indicator buffers
double ExtLineBuffer[];
//+------------------------------------------------------------------+
//| simple moving average |
//+------------------------------------------------------------------+
void CalculateSimpleMA(int rates_total,int prev_calculated,int begin,const double &price[])
{
int i,limit;
//--- first calculation or number of bars was changed
if(prev_calculated==0)// first calculation
{
limit=InpMAPeriod+begin;
//--- set empty value for first limit bars
for(i=0;i<limit-1;i++) ExtLineBuffer[i]=0.0;
//--- calculate first visible value
double firstValue=0;
for(i=begin;i<limit;i++)
firstValue+=price[i];
firstValue/=InpMAPeriod;
ExtLineBuffer[limit-1]=firstValue;
}
else limit=prev_calculated-1;
//--- main loop
for(i=limit;i<rates_total && !IsStopped();i++)
ExtLineBuffer[i]=ExtLineBuffer[i-1]+(price[i]-price[i-InpMAPeriod])/InpMAPeriod;
//---
}
//+------------------------------------------------------------------+
//| exponential moving average |
//+------------------------------------------------------------------+
void CalculateEMA(int rates_total,int prev_calculated,int begin,const double &price[])
{
int i,limit;
double SmoothFactor=2.0/(1.0+InpMAPeriod);
//--- first calculation or number of bars was changed
if(prev_calculated==0)
{
limit=InpMAPeriod+begin;
ExtLineBuffer[begin]=price[begin];
for(i=begin+1;i<limit;i++)
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
}
else limit=prev_calculated-1;
//--- main loop
for(i=limit;i<rates_total && !IsStopped();i++)
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
//---
}
//+------------------------------------------------------------------+
//| linear weighted moving average |
//+------------------------------------------------------------------+
void CalculateLWMA(int rates_total,int prev_calculated,int begin,const double &price[])
{
int i,limit;
static int weightsum;
double sum;
//--- first calculation or number of bars was changed
if(prev_calculated==0)
{
weightsum=0;
limit=InpMAPeriod+begin;
//--- set empty value for first limit bars
for(i=0;i<limit;i++) ExtLineBuffer[i]=0.0;
//--- calculate first visible value
double firstValue=0;
for(i=begin;i<limit;i++)
{
int k=i-begin+1;
weightsum+=k;
firstValue+=k*price[i];
}
firstValue/=(double)weightsum;
ExtLineBuffer[limit-1]=firstValue;
}
else limit=prev_calculated-1;
//--- main loop
for(i=limit;i<rates_total && !IsStopped();i++)
{
sum=0;
for(int j=0;j<InpMAPeriod;j++) sum+=(InpMAPeriod-j)*price[i-j];
ExtLineBuffer[i]=sum/weightsum;
}
//---
}
//+------------------------------------------------------------------+
//| smoothed moving average |
//+------------------------------------------------------------------+
void CalculateSmoothedMA(int rates_total,int prev_calculated,int begin,const double &price[])
{
int i,limit;
//--- first calculation or number of bars was changed
if(prev_calculated==0)
{
limit=InpMAPeriod+begin;
//--- set empty value for first limit bars
for(i=0;i<limit-1;i++) ExtLineBuffer[i]=0.0;
//--- calculate first visible value
double firstValue=0;
for(i=begin;i<limit;i++)
firstValue+=price[i];
firstValue/=InpMAPeriod;
ExtLineBuffer[limit-1]=firstValue;
}
else limit=prev_calculated-1;
//--- main loop
for(i=limit;i<rates_total && !IsStopped();i++)
ExtLineBuffer[i]=(ExtLineBuffer[i-1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;
//---
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
//--- name for DataWindow
string short_name="unknown ma";
switch(InpMAMethod)
{
case MODE_EMA : short_name="EMA"; break;
case MODE_LWMA : short_name="LWMA"; break;
case MODE_SMA : short_name="SMA"; break;
case MODE_SMMA : short_name="SMMA"; break;
}
IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")");
//---- sets drawing line empty value--
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//---- initialization done
}
//+------------------------------------------------------------------+
//| Moving Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for bars count
if(rates_total<InpMAPeriod-1+begin)
return(0);// not enough bars for calculation
//--- first calculation or number of bars was changed
if(prev_calculated==0)
ArrayInitialize(ExtLineBuffer,0);
//--- sets first bar from what index will be draw
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1+begin);
//--- calculation
switch(InpMAMethod)
{
case MODE_EMA: CalculateEMA(rates_total,prev_calculated,begin,price); break;
case MODE_LWMA: CalculateLWMA(rates_total,prev_calculated,begin,price); break;
case MODE_SMMA: CalculateSmoothedMA(rates_total,prev_calculated,begin,price); break;
case MODE_SMA: CalculateSimpleMA(rates_total,prev_calculated,begin,price); break;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+71
View File
@@ -0,0 +1,71 @@
//+------------------------------------------------------------------+
//| DEMA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Double Exponential Moving Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DarkBlue
#property indicator_width1 1
#property indicator_label1 "DEMA"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodEMA=14; // EMA period
input int InpShift=0; // Indicator's shift
//--- indicator buffers
double DemaBuffer[];
double Ema[];
double EmaOfEma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,DemaBuffer,INDICATOR_DATA);
SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodEMA-2);
//--- sets indicator shift
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"DEMA("+string(InpPeriodEMA)+")");
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"DEMA("+string(InpPeriodEMA)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Double Exponential Moving Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for data
if(rates_total<2*InpPeriodEMA-2)
return(0);
//---
int limit;
if(prev_calculated==0)
limit=0;
else limit=prev_calculated-1;
//--- calculate EMA
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema);
//--- calculate EMA on EMA array
ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma);
//--- calculate DEMA
for(int i=limit;i<rates_total && !IsStopped();i++)
DemaBuffer[i]=2*Ema[i]-EmaOfEma[i];
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+69
View File
@@ -0,0 +1,69 @@
//+------------------------------------------------------------------+
//| DPO.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Detrended Price Oscillator"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- input parameters
input int InpDetrendPeriod=12; // Period
//--- indicator buffers
double ExtDPOBuffer[];
double ExtMABuffer[];
//--- global variable
int ExtMAPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- get length of cycle for smoothing
ExtMAPeriod=InpDetrendPeriod/2+1;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtDPOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- set first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMAPeriod-1);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"DPO("+string(InpDetrendPeriod)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Detrended Price Oscillator |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
int limit;
int firstInd=begin+ExtMAPeriod-1;
//--- correct draw begin
if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,firstInd);
//--- preliminary calculations
if(prev_calculated<firstInd)
{
//--- filling
ArrayInitialize(ExtDPOBuffer,0.0);
limit=firstInd;
}
else limit=prev_calculated-1;
//--- calculate simple moving average
SimpleMAOnBuffer(rates_total,prev_calculated,begin,ExtMAPeriod,price,ExtMABuffer);
//--- the main loop of calculations
for(int i=limit;i<rates_total && !IsStopped();i++)
ExtDPOBuffer[i]=price[i]-ExtMABuffer[i];
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
+100
View File
@@ -0,0 +1,100 @@
//+------------------------------------------------------------------+
//| DeMarker.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_level1 0.3
#property indicator_level2 0.7
//--- input parameters
input int InpDeMarkerPeriod=14; // Period
//--- indicator buffers
double ExtDeMarkerBuffer[];
double ExtDeMaxBuffer[];
double ExtDeMinBuffer[];
double ExtAvgDeMaxBuffer[];
double ExtAvgDeMinBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtDeMarkerBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtDeMaxBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtDeMinBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtAvgDeMaxBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtAvgDeMinBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,3);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpDeMarkerPeriod);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"DeM("+string(InpDeMarkerPeriod)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| DeMarker |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
double dNum;
//--- check for bars count
if(rates_total<InpDeMarkerPeriod)
return(0);
//--- preliminary calculations
if(prev_calculated==0)
{
ExtDeMaxBuffer[0]=0.0;
ExtDeMinBuffer[0]=0.0;
//--- filling out the array of True Range values for each period
for(i=1;i<InpDeMarkerPeriod;i++)
{
if(high[i]>high[i-1]) ExtDeMaxBuffer[i]=high[i]-high[i-1];
else ExtDeMaxBuffer[i]=0.0;
if(low[i-1]>low[i]) ExtDeMinBuffer[i]=low[i-1]-low[i];
else ExtDeMinBuffer[i]=0.0;
}
for(i=0;i<InpDeMarkerPeriod;i++) ExtDeMarkerBuffer[i]=0.0;
limit=InpDeMarkerPeriod-1;
}
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
if(high[i]>high[i-1]) ExtDeMaxBuffer[i]=high[i]-high[i-1];
else ExtDeMaxBuffer[i]=0.0;
if(low[i-1]>low[i]) ExtDeMinBuffer[i]=low[i-1]-low[i];
else ExtDeMinBuffer[i]=0.0;
ExtAvgDeMaxBuffer[i]=SimpleMA(i,InpDeMarkerPeriod,ExtDeMaxBuffer);
ExtAvgDeMinBuffer[i]=SimpleMA(i,InpDeMarkerPeriod,ExtDeMinBuffer);
dNum=ExtAvgDeMaxBuffer[i]+ExtAvgDeMinBuffer[i];
if(dNum!=0) ExtDeMarkerBuffer[i]=ExtAvgDeMaxBuffer[i]/dNum;
else ExtDeMarkerBuffer[i]=0.0;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+106
View File
@@ -0,0 +1,106 @@
//+------------------------------------------------------------------+
//| Envelopes.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_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_label1 "Upper band"
#property indicator_label2 "Lower band"
//--- input parameters
input int InpMAPeriod=14; // Period
input int InpMAShift=0; // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
input double InpDeviation=0.1; // Deviation
//--- indicator buffers
double ExtUpBuffer[];
double ExtDownBuffer[];
double ExtMABuffer[];
//--- MA handle
int ExtMAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtUpBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtDownBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtMABuffer,INDICATOR_CALCULATIONS);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1);
//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME,"Env("+string(InpMAPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"Env("+string(InpMAPeriod)+")Upper");
PlotIndexSetString(1,PLOT_LABEL,"Env("+string(InpMAPeriod)+")Lower");
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpMAShift);
//---
ExtMAHandle=iMA(NULL,0,InpMAPeriod,0,InpMAMethod,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Envelopes |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count
if(rates_total<InpMAPeriod)
return(0);
int calculated=BarsCalculated(ExtMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
{
Print("Getting MA data is failed! Error",GetLastError());
return(0);
}
//--- preliminary calculations
limit=prev_calculated-1;
if(limit<InpMAPeriod)
limit=InpMAPeriod;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtUpBuffer[i]=(1+InpDeviation/100.0)*ExtMABuffer[i];
ExtDownBuffer[i]=(1-InpDeviation/100.0)*ExtMABuffer[i];
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
+98
View File
@@ -0,0 +1,98 @@
//+------------------------------------------------------------------+
//| Force_Index.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_LINE
#property indicator_color1 DodgerBlue
//--- input parameters
input int InpForcePeriod=13; // Period
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // MA method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
input ENUM_APPLIED_VOLUME InpAppliedVolume=VOLUME_TICK; // Volumes
//--- indicator buffers
double ExtForceBuffer[];
double ExtMABuffer[];
//--- MA handle
int ExtMAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtForceBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpForcePeriod);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Force("+string(InpForcePeriod)+")");
//--- get MA handle
ExtMAHandle=iMA(NULL,0,InpForcePeriod,0,InpMAMethod,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Force Index |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for rates total
if(rates_total<InpForcePeriod)
return(0);
//---
int calculated=BarsCalculated(ExtMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
{
Print("Getting MA data is failed! Error",GetLastError());
return(0);
}
//--- preliminary calculations
if(prev_calculated<InpForcePeriod)
limit=InpForcePeriod;
else limit=prev_calculated-1;
//--- the main loop of calculations
if(InpAppliedVolume==VOLUME_TICK)
{
for(i=limit;i<rates_total && !IsStopped();i++)
ExtForceBuffer[i]=tick_volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);
}
else
{
for(i=limit;i<rates_total && !IsStopped();i++)
ExtForceBuffer[i]=volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+143
View File
@@ -0,0 +1,143 @@
//+------------------------------------------------------------------+
//| FrAMA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Fractal Adaptive Moving Average"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DarkBlue
#property indicator_width1 1
#property indicator_label1 "FrAMA"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodFrAMA=14; // FrAMA period
input int InpShift=0; // Indicator's shift
//--- indicator buffers
double FrAmaBuffer[];
double High[];
double Low[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,FrAmaBuffer,INDICATOR_DATA);
SetIndexBuffer(1,High,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,Low,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodFrAMA-1);
//--- sets indicator shift
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"FrAMA("+string(InpPeriodFrAMA)+")");
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"FrAMA("+string(InpPeriodFrAMA)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Fractal Adaptive Moving Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for data
if(rates_total<2*InpPeriodFrAMA)
return(0);
//--- preparing calculation
int limit,copied;
double Hi1,Hi2,Hi3,Lo1,Lo2,Lo3;
double N1,N2,N3,D;
double ALFA;
//--- load High
if(IsStopped()) return(0); //Checking for stop flag
copied=CopyHigh(_Symbol,_Period,0,rates_total,High);
if(copied!=rates_total)
{
Print("Can't load High prices.");
return(0);
}
//--- load Low
if(IsStopped()) return(0); //Checking for stop flag
copied=CopyLow(_Symbol,_Period,0,rates_total,Low);
if(copied!=rates_total)
{
Print("Can't load Low prices.");
return(0);
}
//--- start calculations
if(prev_calculated==0)
{
limit=2*InpPeriodFrAMA-1;
//--- fill in indicator array
for(int i=0;i<=limit;i++)
FrAmaBuffer[i]=price[i];
}
else limit=prev_calculated-1;
//--- main cycle
for(int i=limit;i<rates_total && !IsStopped();i++)
{
Hi1=iHighest(i,InpPeriodFrAMA);
Lo1=iLowest(i,InpPeriodFrAMA);
Hi2=iHighest(i-InpPeriodFrAMA,InpPeriodFrAMA);
Lo2=iLowest(i-InpPeriodFrAMA,InpPeriodFrAMA);
Hi3=iHighest(i,2*InpPeriodFrAMA);
Lo3=iLowest(i,2*InpPeriodFrAMA);
N1=(Hi1-Lo1)/InpPeriodFrAMA;
N2=(Hi2-Lo2)/InpPeriodFrAMA;
N3=(Hi3-Lo3)/(2*InpPeriodFrAMA);
D=(log(N1+N2)-log(N3))/log(2.0);
ALFA=exp(-4.6*(D-1.0));
FrAmaBuffer[i]=ALFA*price[i]+(1-ALFA)*FrAmaBuffer[i-1];
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Find the highest value in data range |
//+------------------------------------------------------------------+
double iHighest(int StartPos,
int Depth)
{
double res;
//--- check for parameters StartPos and Depth
if(StartPos<0 || StartPos-Depth+1<0 || Depth<0)
{
Print("Invalid parameter in function",__FUNCTION__,": StartPos =",StartPos,", Depth = ",Depth);
return(0.0);
}
//---
res=High[StartPos];
for(int i=StartPos-Depth+1;i<StartPos;i++)
if(High[i]>res)
res=High[i];
return(res);
}
//+------------------------------------------------------------------+
//| Find the lowest value in data range |
//+------------------------------------------------------------------+
double iLowest(int StartPos,
int Depth)
{
double res;
//--- check for parameters StartPos and Depth
if(StartPos<0 || StartPos-Depth+1<0 || Depth<0)
{
Print("Invalid parameter in function",__FUNCTION__,": StartPos =",StartPos,", Depth = ",Depth);
return(0.0);
}
//---
res=Low[StartPos];
for(int i=StartPos-Depth+1;i<StartPos;i++)
if(Low[i]<res)
res=Low[i];
return(res);
}
//+------------------------------------------------------------------+
+87
View File
@@ -0,0 +1,87 @@
//+------------------------------------------------------------------+
//| Fractals.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_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_type2 DRAW_ARROW
#property indicator_color1 Gray
#property indicator_color2 Gray
#property indicator_label1 "Fractal Up"
#property indicator_label2 "Fractal Down"
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- indicator buffers mapping
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_ARROW,217);
PlotIndexSetInteger(1,PLOT_ARROW,218);
//---- arrow shifts when drawing
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
//---- sets drawing line empty value--
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- initialization done
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//---
if(rates_total<5)
return(0);
//---
if(prev_calculated<7)
{
limit=2;
//--- clean up arrays
ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
}
else limit=rates_total-5;
for(i=limit;i<rates_total-3 && !IsStopped();i++)
{
//---- Upper Fractal
if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>=high[i-1] && high[i]>=high[i-2])
ExtUpperBuffer[i]=high[i];
else ExtUpperBuffer[i]=EMPTY_VALUE;
//---- Lower Fractal
if(low[i]<low[i+1] && low[i]<low[i+2] && low[i]<=low[i-1] && low[i]<=low[i-2])
ExtLowerBuffer[i]=low[i];
else ExtLowerBuffer[i]=EMPTY_VALUE;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+260
View File
@@ -0,0 +1,260 @@
//+------------------------------------------------------------------+
//| Gator.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Gator Oscillator"
#property description "based on 3 non-shifted moving averages"
//********************************************************************
// Attention! Following correlations must be obeyed:
// 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod;
// 2.InpJawsShift>InpTeethShift>InpLipsShift;
// 3.InpJawsPeriod>InpJawsShift;
// 4.InpTeethPeriod>InpTeethShift;
// 5.InpLipsPeriod>InpLipsShift.
//********************************************************************
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots 2
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_type2 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_color2 Green,Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_label1 "Gator Upper"
#property indicator_label2 "Gator Lower"
//--- input parameters
input int InpJawsPeriod=13; // Jaws period
input int InpJawsShift=8; // Jaws shift
input int InpTeethPeriod=8; // Teeth period
input int InpTeethShift=5; // Teeth shift
input int InpLipsPeriod=5; // Lips period
input int InpLipsShift=3; // Lips shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
//--- indicator buffers
double ExtUpperBuffer[];
double ExtUpColorsBuffer[];
double ExtLowerBuffer[];
double ExtLoColorsBuffer[];
double ExtJawsBuffer[];
double ExtTeethBuffer[];
double ExtLipsBuffer[];
//--- handles
int ExtJawsHandle;
int ExtTeethHandle;
int ExtLipsHandle;
//--- global variables
int ExtUpperShift;
int ExtLowerShift;
bool ExtFlag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtUpColorsBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,ExtLowerBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtLoColorsBuffer,INDICATOR_COLOR_INDEX);
//--- MAs
SetIndexBuffer(4,ExtJawsBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,ExtTeethBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,ExtLipsBuffer,INDICATOR_CALCULATIONS);
//--- get handles
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTeethShift+InpTeethPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpLipsShift+InpLipsPeriod);
//--- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpTeethShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpLipsShift);
//--- name for indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Gator("+
string(InpJawsPeriod)+","+
string(InpTeethPeriod)+","+
string(InpLipsPeriod)+")");
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//--- calculate global variables values
ExtUpperShift=InpJawsShift-InpTeethShift;
ExtLowerShift=InpTeethShift-InpLipsShift;
//--- check for input parameters
ExtFlag=CheckForInput();
if(!ExtFlag) Print("Wrong input parameters. Indicator won't work.");
//--- initialization done. 0 returned if ExtFlag is true
return(!ExtFlag);
}
//+------------------------------------------------------------------+
//| Gator Oscillator |
//+------------------------------------------------------------------+
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[])
{
int pos,shift;
double dCurr,dPrev;
//--- check for rules and bars count
if(ExtUpperShift>ExtLowerShift)
shift=ExtUpperShift;
else shift=ExtLowerShift;
if(!ExtFlag || shift>rates_total)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtJawsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtJawsHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtTeethHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtTeethHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtLipsHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtLipsHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJawsBuffer)<=0)
{
Print("getting ExtJawsHandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeethBuffer)<=0)
{
Print("getting ExtTeethHandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLipsBuffer)<=0)
{
Print("getting ExtLipsHandle is failed! Error",GetLastError());
return(0);
}
//--- last 2 counted bars will be recounted
pos=prev_calculated-2;
if(pos<shift)
{
for(int i=0; i<shift; i++)
{
ExtUpperBuffer[i]=0.0;
ExtUpColorsBuffer[i]=0.0;
ExtLowerBuffer[i]=0.0;
ExtLoColorsBuffer[i]=0.0;
}
pos=shift;
}
//--- main cycle
int lower_limit=ExtLowerShift+InpLipsShift+InpLipsPeriod;
int upper_limit=ExtUpperShift+InpTeethShift+InpTeethPeriod;
for(int i=pos;i<rates_total && !IsStopped();i++)
{
if(i>=lower_limit)
{
//--- calculate down buffer value
dCurr=-fabs(ExtTeethBuffer[i-ExtLowerShift]-ExtLipsBuffer[i]);
dPrev=ExtLowerBuffer[i-1];
ExtLowerBuffer[i]=dCurr;
//--- set down buffer color
if(dPrev==dCurr)
ExtLoColorsBuffer[i]=ExtLoColorsBuffer[i-1];
else
{
if(dPrev<dCurr)
ExtLoColorsBuffer[i]=1.0;
else
ExtLoColorsBuffer[i]=0.0;
}
}
else
{
ExtLowerBuffer[i]=0.0;
ExtLoColorsBuffer[i]=0.0;
}
if(i>=upper_limit)
{
//--- calculate up buffer value
dCurr=fabs(ExtJawsBuffer[i-ExtUpperShift]-ExtTeethBuffer[i]);
ExtUpperBuffer[i]=dCurr;
dPrev=ExtUpperBuffer[i-1];
//--- set up buffer color
if(dPrev==dCurr)
ExtUpColorsBuffer[i]=ExtUpColorsBuffer[i-1];
else
{
if(dPrev<dCurr)
ExtUpColorsBuffer[i]=0.0;
else
ExtUpColorsBuffer[i]=1.0;
}
}
else
{
ExtUpperBuffer[i]=0.0;
ExtUpColorsBuffer[i]=0.0;
}
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
//| Check for rules |
//| 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod; |
//| 2.InpJawsShift>InpTeethShift>InpLipsShift; |
//| 3.InpJawsPeriod>InpJawsShift; |
//| 4.InpTeethPeriod>InpTeethShift; |
//| 5.InpLipsPeriod>InpLipsShift. |
//+------------------------------------------------------------------+
bool CheckForInput()
{
//--- 1
if(InpJawsPeriod<=InpTeethPeriod || InpTeethPeriod<=InpLipsPeriod)
return(false);
//--- 2
if(InpJawsShift<=InpTeethShift || InpTeethShift<=InpLipsShift)
return(false);
//--- 3
if(InpJawsPeriod<=InpJawsShift)
return(false);
//--- 4
if(InpTeethPeriod<=InpTeethShift)
return(false);
//--- 5
if(InpLipsPeriod<=InpLipsShift)
return(false);
//--- all right
return(true);
}
//+------------------------------------------------------------------+
+248
View File
@@ -0,0 +1,248 @@
//+------------------------------------------------------------------+
//| Gator.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Gator Oscillator"
#property description "based on shifted Alligator buffers"
//********************************************************************
// Attention! Following correlations must be obeyed:
// 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod;
// 2.InpJawsShift>InpTeethShift>InpLipsShift;
// 3.InpJawsPeriod>InpJawsShift;
// 4.InpTeethPeriod>InpTeethShift;
// 5.InpLipsPeriod>InpLipsShift.
//********************************************************************
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots 2
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_type2 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green,Red
#property indicator_color2 Green,Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_label1 "Gator Upper"
#property indicator_label2 "Gator Lower"
//--- input parameters
input int InpJawsPeriod=13; // Jaws period
input int InpJawsShift=8; // Jaws shift
input int InpTeethPeriod=8; // Teeth period
input int InpTeethShift=5; // Teeth shift
input int InpLipsPeriod=5; // Lips period
input int InpLipsShift=3; // Lips shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
//--- indicator buffers
double ExtUpperBuffer[];
double ExtUpColorsBuffer[];
double ExtLowerBuffer[];
double ExtLoColorsBuffer[];
double ExtJawsBuffer[];
double ExtTeethBuffer[];
double ExtLipsBuffer[];
//--- handle
int ExtAlligatorHandle;
//--- global variables
int ExtUpperShift;
int ExtLowerShift;
bool ExtFlag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtUpColorsBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,ExtLowerBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtLoColorsBuffer,INDICATOR_COLOR_INDEX);
//--- MAs
SetIndexBuffer(4,ExtJawsBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,ExtTeethBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,ExtLipsBuffer,INDICATOR_CALCULATIONS);
//--- get handles
ExtAlligatorHandle=iAlligator(NULL,0,
InpJawsPeriod,0,
InpTeethPeriod,0,
InpLipsPeriod,0,
InpMAMethod,InpAppliedPrice);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTeethShift+InpTeethPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpLipsShift+InpLipsPeriod);
//--- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpTeethShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpLipsShift);
//--- name for indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Gator("+
string(InpJawsPeriod)+","+
string(InpTeethPeriod)+","+
string(InpLipsPeriod)+")");
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//--- calculate global variables values
ExtUpperShift=InpJawsShift-InpTeethShift;
ExtLowerShift=InpTeethShift-InpLipsShift;
//--- check for input parameters
ExtFlag=CheckForInput();
if(!ExtFlag) Print("Wrong input parameters. Indicator won't work.");
//--- initialization done. 0 returned if ExtFlag is true
return(ExtFlag?0:1);
}
//+------------------------------------------------------------------+
//| Gator Oscillator |
//+------------------------------------------------------------------+
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[])
{
int pos,shift;
double dCurr,dPrev;
//--- check for rules and bars count
if(ExtUpperShift>ExtLowerShift)
shift=ExtUpperShift;
else shift=ExtLowerShift;
if(!ExtFlag || shift>rates_total)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtAlligatorHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtAlligatorHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtAlligatorHandle,0,0,to_copy,ExtJawsBuffer)<=0)
{
Print("getting ExtAlligatorHandle buffer 0 is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtAlligatorHandle,1,0,to_copy,ExtTeethBuffer)<=0)
{
Print("getting ExtAlligatorHandle buffer 1 is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtAlligatorHandle,2,0,to_copy,ExtLipsBuffer)<=0)
{
Print("getting ExtAlligatorHandle buffer 2 is failed! Error",GetLastError());
return(0);
}
//--- last counted bar will be recounted
pos=prev_calculated-1;
if(pos<shift)
{
for(int i=0;i<shift;i++)
{
ExtUpperBuffer[i]=0.0;
ExtUpColorsBuffer[i]=0.0;
ExtLowerBuffer[i]=0.0;
ExtLoColorsBuffer[i]=0.0;
}
pos=shift;
}
//--- main cycle
int lower_limit=ExtLowerShift+InpLipsShift+InpLipsPeriod;
int upper_limit=ExtUpperShift+InpTeethShift+InpTeethPeriod;
for(int i=pos;i<rates_total && !IsStopped();i++)
{
if(i>=lower_limit)
{
//--- calculate down buffer value
dCurr=-fabs(ExtTeethBuffer[i-ExtLowerShift]-ExtLipsBuffer[i]);
dPrev=ExtLowerBuffer[i-1];
ExtLowerBuffer[i]=dCurr;
//--- set down buffer color
if(dPrev==dCurr)
ExtLoColorsBuffer[i]=ExtLoColorsBuffer[i-1];
else
{
if(dPrev<dCurr)
ExtLoColorsBuffer[i]=1.0;
else
ExtLoColorsBuffer[i]=0.0;
}
}
else
{
ExtLowerBuffer[i]=0.0;
ExtLoColorsBuffer[i]=0.0;
}
if(i>=upper_limit)
{
//--- calculate up buffer value
dCurr=fabs(ExtJawsBuffer[i-ExtUpperShift]-ExtTeethBuffer[i]);
ExtUpperBuffer[i]=dCurr;
dPrev=ExtUpperBuffer[i-1];
//--- set up buffer color
if(dPrev==dCurr)
ExtUpColorsBuffer[i]=ExtUpColorsBuffer[i-1];
else
{
if(dPrev<dCurr)
ExtUpColorsBuffer[i]=0.0;
else
ExtUpColorsBuffer[i]=1.0;
}
}
else
{
ExtUpperBuffer[i]=0.0;
ExtUpColorsBuffer[i]=0.0;
}
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
//| Check for rules |
//| 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod; |
//| 2.InpJawsShift>InpTeethShift>InpLipsShift; |
//| 3.InpJawsPeriod>InpJawsShift; |
//| 4.InpTeethPeriod>InpTeethShift; |
//| 5.InpLipsPeriod>InpLipsShift. |
//+------------------------------------------------------------------+
bool CheckForInput()
{
//--- 1
if(InpJawsPeriod<=InpTeethPeriod || InpTeethPeriod<=InpLipsPeriod)
return(false);
//--- 2
if(InpJawsShift<=InpTeethShift || InpTeethShift<=InpLipsShift)
return(false);
//--- 3
if(InpJawsPeriod<=InpJawsShift)
return(false);
//--- 4
if(InpTeethPeriod<=InpTeethShift)
return(false);
//--- 5
if(InpLipsPeriod<=InpLipsShift)
return(false);
//--- all right
return(true);
}
//+------------------------------------------------------------------+
+88
View File
@@ -0,0 +1,88 @@
//+------------------------------------------------------------------+
//| Heiken_Ashi.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_chart_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 DodgerBlue, Red
#property indicator_label1 "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
IndicatorSetString(INDICATOR_SHORTNAME,"Heiken Ashi");
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Heiken Ashi |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- preliminary calculations
if(prev_calculated==0)
{
//--- set first candle
ExtLBuffer[0]=low[0];
ExtHBuffer[0]=high[0];
ExtOBuffer[0]=open[0];
ExtCBuffer[0]=close[0];
limit=1;
}
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
double haOpen=(ExtOBuffer[i-1]+ExtCBuffer[i-1])/2;
double haClose=(open[i]+high[i]+low[i]+close[i])/4;
double haHigh=MathMax(high[i],MathMax(haOpen,haClose));
double haLow=MathMin(low[i],MathMin(haOpen,haClose));
ExtLBuffer[i]=haLow;
ExtHBuffer[i]=haHigh;
ExtOBuffer[i]=haOpen;
ExtCBuffer[i]=haClose;
//--- set candle color
if(haOpen<haClose) ExtColorBuffer[i]=0.0; // set color DodgerBlue
else ExtColorBuffer[i]=1.0; // set color Red
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
+131
View File
@@ -0,0 +1,131 @@
//+------------------------------------------------------------------+
//| Ichimoku.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 4
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_FILLING
#property indicator_type4 DRAW_LINE
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown,Thistle
#property indicator_color4 Lime
#property indicator_label1 "Tenkan-sen"
#property indicator_label2 "Kijun-sen"
#property indicator_label3 "Senkou Span A;Senkou Span B"
#property indicator_label4 "Chikou Span"
//--- input parameters
input int InpTenkan=9; // Tenkan-sen
input int InpKijun=26; // Kijun-sen
input int InpSenkou=52; // Senkou Span B
//--- indicator buffers
double ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtSpanABuffer[];
double ExtSpanBBuffer[];
double ExtChikouBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtSpanABuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtSpanBBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtChikouBuffer,INDICATOR_DATA);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTenkan);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKijun);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSenkou-1);
//--- lines shifts when drawing
PlotIndexSetInteger(2,PLOT_SHIFT,InpKijun);
PlotIndexSetInteger(3,PLOT_SHIFT,-InpKijun);
//--- change labels for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
PlotIndexSetString(1,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");
PlotIndexSetString(2,PLOT_LABEL,"Senkou Span A;Senkou Span B("+string(InpSenkou)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| get highest value for range |
//+------------------------------------------------------------------+
double Highest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res<array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| get lowest value for range |
//+------------------------------------------------------------------+
double Lowest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res>array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
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[])
{
int limit;
//---
if(prev_calculated==0) limit=0;
else limit=prev_calculated-1;
//---
for(int i=limit;i<rates_total && !IsStopped();i++)
{
ExtChikouBuffer[i]=close[i];
//--- tenkan sen
double _high=Highest(high,InpTenkan,i);
double _low=Lowest(low,InpTenkan,i);
ExtTenkanBuffer[i]=(_high+_low)/2.0;
//--- kijun sen
_high=Highest(high,InpKijun,i);
_low=Lowest(low,InpKijun,i);
ExtKijunBuffer[i]=(_high+_low)/2.0;
//--- senkou span a
ExtSpanABuffer[i]=(ExtTenkanBuffer[i]+ExtKijunBuffer[i])/2.0;
//--- senkou span b
_high=Highest(high,InpSenkou,i);
_low=Lowest(low,InpSenkou,i);
ExtSpanBBuffer[i]=(_high+_low)/2.0;
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
+119
View File
@@ -0,0 +1,119 @@
//+------------------------------------------------------------------+
//| MACD.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Moving Average Convergence/Divergence"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 2
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_type2 DRAW_LINE
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1
#property indicator_label1 "MACD"
#property indicator_label2 "Signal"
//--- input parameters
input int InpFastEMA=12; // Fast EMA period
input int InpSlowEMA=26; // Slow EMA period
input int InpSignalSMA=9; // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
//--- MA handles
int ExtFastMaHandle;
int ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpFastEMA)+","+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
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 data
if(rates_total<InpSignalSMA)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get Fast EMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
{
Print("Getting slow SMA is failed! Error",GetLastError());
return(0);
}
//---
int limit;
if(prev_calculated==0)
limit=0;
else limit=prev_calculated-1;
//--- calculate MACD
for(int i=limit;i<rates_total && !IsStopped();i++)
ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate Signal
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+117
View File
@@ -0,0 +1,117 @@
//+------------------------------------------------------------------+
//| MFI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Money Flow Index"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_maximum 100.0
#property indicator_minimum 0.0
#property indicator_level1 20.0
#property indicator_level2 80.0
#property indicator_levelcolor Silver
#property indicator_levelstyle 2
#property indicator_levelwidth 1
//---- input parameters
input int InpMFIPeriod=14; // Period
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- buffers
double ExtMFIBuffer[];
//--- global variable
int ExtMFIPeriod;
//+------------------------------------------------------------------+
//| Money Flow Index initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(InpMFIPeriod<=0)
{
ExtMFIPeriod=14;
Print("Parameter InpMFIPeriod has wrong value. Indicator will use value ",ExtMFIPeriod);
}
else ExtMFIPeriod=InpMFIPeriod;
//---- indicator buffer
SetIndexBuffer(0,ExtMFIBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"MFI"+"("+string(ExtMFIPeriod)+")");
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMFIPeriod);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- end of initialization function
}
//+------------------------------------------------------------------+
//| Money Flow Index |
//+------------------------------------------------------------------+
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[])
{
//--- variables of indicator
int CalcPosition;
//---- insufficient data
if(rates_total<ExtMFIPeriod)
return(0);
//--- start working
if(prev_calculated<ExtMFIPeriod)
CalcPosition=ExtMFIPeriod;
else
CalcPosition=prev_calculated-1;
//--- calculate MFI by volume
if(InpVolumeType==VOLUME_TICK)
CalculateMFI(CalcPosition,rates_total,high,low,close,tick_volume);
else
CalculateMFI(CalcPosition,rates_total,high,low,close,volume);
//--- OnCalculate done. Return new prev_calculated
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate MFI by volume from argument |
//+------------------------------------------------------------------+
void CalculateMFI(const int nPosition,
const int nRatesCount,
const double &HiBuffer[],
const double &LoBuffer[],
const double &ClBuffer[],
const long &VolBuffer[])
{
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
double dPositiveMF=0.0;
double dNegativeMF=0.0;
double dCurrentTP=TypicalPrice(HiBuffer[i],LoBuffer[i],ClBuffer[i]);
for(int j=1;j<=ExtMFIPeriod;j++)
{
int index=i-j;
double dPreviousTP=TypicalPrice(HiBuffer[index],LoBuffer[index],ClBuffer[index]);
if(dCurrentTP>dPreviousTP) dPositiveMF+=VolBuffer[index+1]*dCurrentTP;
if(dCurrentTP<dPreviousTP) dNegativeMF+=VolBuffer[index+1]*dCurrentTP;
dCurrentTP=dPreviousTP;
}
if(dNegativeMF!=0.0) ExtMFIBuffer[i]=100.0-100.0/(1+dPositiveMF/dNegativeMF);
else ExtMFIBuffer[i]=100.0;
}
}
//+------------------------------------------------------------------+
//| Calculate typical price |
//+------------------------------------------------------------------+
double TypicalPrice(const double dHi,const double dLo,const double dCl)
{
return (dHi+dLo+dCl)/3;
}
//+------------------------------------------------------------------+
+118
View File
@@ -0,0 +1,118 @@
//+------------------------------------------------------------------+
//| MI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Mass Index"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_level1 27
#property indicator_level2 26.5
#property indicator_levelcolor DarkGray
//--- input parametrs
input int InpPeriodEMA=9; // First EMA period
input int InpSecondPeriodEMA=9; // Second EMA period
input int InpSumPeriod=25; // Mass period
//--- global variables
int ExtPeriodEMA;
int ExtSecondPeriodEMA;
int ExtSumPeriod;
//---- indicator buffers
double ExtHLBuffer[];
double ExtEHLBuffer[];
double ExtEEHLBuffer[];
double ExtMIBuffer[];
//+------------------------------------------------------------------+
//| MI initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check input variables
if(InpPeriodEMA<=0)
{
ExtPeriodEMA=9;
printf("Incorrect value for input variable InpPeriodEMA=%d. Indicator will use value=%d for calculations.",
InpPeriodEMA,ExtPeriodEMA);
}
else ExtPeriodEMA=InpPeriodEMA;
if(InpSecondPeriodEMA<=0)
{
ExtSecondPeriodEMA=9;
printf("Incorrect value for input variable InpSecondPeriodEMA=%d. Indicator will use value=%d for calculations.",
InpSecondPeriodEMA,ExtSecondPeriodEMA);
}
else ExtSecondPeriodEMA=InpSecondPeriodEMA;
if(InpSumPeriod<=0)
{
ExtSumPeriod=25;
printf("Incorrect value for input variable PeriodSum=%d. Indicator will use value=%d for calculations.",
InpSumPeriod,ExtSumPeriod);
}
else ExtSumPeriod=InpSumPeriod;
//--- define buffers
SetIndexBuffer(0,ExtMIBuffer);
SetIndexBuffer(1,ExtEHLBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtEEHLBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtHLBuffer,INDICATOR_CALCULATIONS);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Mass Index("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"MI("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")");
//--- indexes draw begin settings
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodEMA+ExtSecondPeriodEMA+ExtSumPeriod-3);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Mass Index |
//+------------------------------------------------------------------+
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 bars count
int posMI=ExtSumPeriod+ExtPeriodEMA+ExtSecondPeriodEMA-3;
if(rates_total<posMI)
return(0);
//--- start working
int pos=prev_calculated-1;
//--- correct position
if(pos<1)
{
ExtHLBuffer[0]=high[0]-low[0];
pos=1;
}
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- fill main data buffer
ExtHLBuffer[i]=high[i]-low[i];
//--- calculate EMA values
ExtEHLBuffer[i]=ExponentialMA(i,ExtPeriodEMA,ExtEHLBuffer[i-1],ExtHLBuffer);
//--- calculate EMA on EMA values
ExtEEHLBuffer[i]=ExponentialMA(i,ExtSecondPeriodEMA,ExtEEHLBuffer[i-1],ExtEHLBuffer);
//--- calculate MI values
double dTmp=0.0;
for(int j=0;j<ExtSumPeriod && i>=posMI;j++)
if(ExtEEHLBuffer[i-j]!=0.0)
dTmp+=ExtEHLBuffer[i-j]/ExtEEHLBuffer[i-j];
ExtMIBuffer[i]=dTmp;
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,125 @@
//+------------------------------------------------------------------+
//| MarketFacilitationIndex.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 Lime,SaddleBrown,Blue,Pink
#property indicator_width1 2
//--- input parameter
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- buffers
double ExtMFIBuffer[];
double ExtColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- indicators
SetIndexBuffer(0,ExtMFIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME,"BWMFI");
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//----
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CalculateMFI(const int start,const int rates_total,
const double &high[],
const double &low[],
const long &volume[])
{
int i=start;
bool mfi_up=true,vol_up=true;
//--- calculate first values of mfi_up and vol_up
if(i>0)
{
int n=i;
while(n>0)
{
if(ExtMFIBuffer[n]>ExtMFIBuffer[n-1]) { mfi_up=true; break; }
if(ExtMFIBuffer[n]<ExtMFIBuffer[n-1]) { mfi_up=false; break; }
//--- if mfi values are equal continue
n--;
}
n=i;
while(n>0)
{
if(volume[n]>volume[n-1]) { vol_up=true; break; }
if(volume[n]<volume[n-1]) { vol_up=false; break; }
//--- if real volumes are equal continue
n--;
}
}
//---
while(i<rates_total && !IsStopped())
{
if(volume[i]==0)
{
if(i>0) ExtMFIBuffer[i]=ExtMFIBuffer[i-1];
else ExtMFIBuffer[i]=0;
}
else ExtMFIBuffer[i]=(high[i]-low[i])/_Point/volume[i];
//--- calculate changes
if(i>0)
{
if(ExtMFIBuffer[i]>ExtMFIBuffer[i-1]) mfi_up=true;
if(ExtMFIBuffer[i]<ExtMFIBuffer[i-1]) mfi_up=false;
if(volume[i]>volume[i-1]) vol_up=true;
if(volume[i]<volume[i-1]) vol_up=false;
}
//--- set colors
if(mfi_up && vol_up) ExtColorBuffer[i]=0.0;
if(!mfi_up && !vol_up) ExtColorBuffer[i]=1.0;
if(mfi_up && !vol_up) ExtColorBuffer[i]=2.0;
if(!mfi_up && vol_up) ExtColorBuffer[i]=3.0;
i++;
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
int start=0;
//---
if(start<prev_calculated) start=prev_calculated-1;
//--- calculate with tick or real volumes
if(InpVolumeType==VOLUME_TICK)
CalculateMFI(start,rates_total,high,low,tick_volume);
else
CalculateMFI(start,rates_total,high,low,volume);
//--- normalize last mfi value
if(rates_total>1)
{
datetime ctm=TimeTradeServer(),lasttm=time[rates_total-1],nexttm=lasttm+datetime(PeriodSeconds());
if(ctm<nexttm && ctm>=lasttm && nexttm!=lasttm)
{
double correction_koef=double(1+ctm-lasttm)/double(nexttm-lasttm);
ExtMFIBuffer[rates_total-1]*=correction_koef;
}
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
+70
View File
@@ -0,0 +1,70 @@
//+------------------------------------------------------------------+
//| Momentum.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 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//---- input parameters
input int InpMomentumPeriod=14; // Period
//---- indicator buffers
double ExtMomentumBuffer[];
//--- global variable
int ExtMomentumPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(InpMomentumPeriod<0)
{
ExtMomentumPeriod=14;
Print("Input parameter InpMomentumPeriod has wrong value. Indicator will use value ",ExtMomentumPeriod);
}
else ExtMomentumPeriod=InpMomentumPeriod;
//---- buffers
SetIndexBuffer(0,ExtMomentumBuffer,INDICATOR_DATA);
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Momentum"+"("+string(ExtMomentumPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMomentumPeriod-1);
//--- sets drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- digits
IndicatorSetInteger(INDICATOR_DIGITS,2);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- start calculation
int StartCalcPosition=(ExtMomentumPeriod-1)+begin;
//---- insufficient data
if(rates_total<StartCalcPosition)
return(0);
//--- correct draw begin
if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartCalcPosition+(ExtMomentumPeriod-1));
//--- start working, detect position
int pos=prev_calculated-1;
if(pos<StartCalcPosition)
pos=begin+ExtMomentumPeriod;
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
ExtMomentumBuffer[i]=price[i]*100/price[i-ExtMomentumPeriod];
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+91
View File
@@ -0,0 +1,91 @@
//+------------------------------------------------------------------+
//| OBV.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "On Balance Volume"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_label1 "OBV"
//--- input parametrs
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffer
double ExtOBVBuffer[];
//+------------------------------------------------------------------+
//| On Balance Volume initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- define indicator buffer
SetIndexBuffer(0,ExtOBVBuffer);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| On Balance Volume |
//+------------------------------------------------------------------+
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[])
{
//--- variables
int pos;
//--- check for bars count
if(rates_total<2)
return(0);
//--- starting calculation
pos=prev_calculated-1;
//--- correct position, when it's first iteration
if(pos<1)
{
pos=1;
if(InpVolumeType==VOLUME_TICK)
ExtOBVBuffer[0]=(double)tick_volume[0];
else ExtOBVBuffer[0]=(double)volume[0];
}
//--- main cycle
if(InpVolumeType==VOLUME_TICK)
CalculateOBV(pos,rates_total,close,tick_volume);
else
CalculateOBV(pos,rates_total,close,volume);
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate OBV by volume argument |
//+------------------------------------------------------------------+
void CalculateOBV(int StartPosition,
int RatesCount,
const double &ClBuffer[],
const long &VolBuffer[])
{
for(int i=StartPosition;i<RatesCount && !IsStopped();i++)
{
//--- get some data
double Volume=(double)VolBuffer[i];
double PrevClose=ClBuffer[i-1];
double CurrClose=ClBuffer[i];
//--- fill ExtOBVBuffer
if(CurrClose<PrevClose) ExtOBVBuffer[i]=ExtOBVBuffer[i-1]-Volume;
else
{
if(CurrClose>PrevClose) ExtOBVBuffer[i]=ExtOBVBuffer[i-1]+Volume;
else ExtOBVBuffer[i]=ExtOBVBuffer[i-1];
}
}
}
//+------------------------------------------------------------------+
+126
View File
@@ -0,0 +1,126 @@
//+------------------------------------------------------------------+
//| OsMA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Moving Average of Oscillator"
#property description "aka MACD histogram"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 Silver
#property indicator_width1 2
//--- input parameters
input int InpFastEMAPeriod=12; // Fast EMA period
input int InpSlowEMAPeriod=26; // Slow EMA period
input int InpSignalSMAPeriod=9; // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtOsMABuffer[];
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
//--- MA handles
int ExtFastMaHandle;
int ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtOsMABuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMacdBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtSignalBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowEMAPeriod+InpSignalSMAPeriod-2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"OsMA("+string(InpFastEMAPeriod)+","+string(InpSlowEMAPeriod)+","+string(InpSignalSMAPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"OsMA");
//--- get MAs handles
ExtFastMaHandle=iMA(NULL,0,InpFastEMAPeriod,0,MODE_EMA,InpAppliedPrice);
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMAPeriod,0,MODE_EMA,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
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[])
{
if(rates_total<InpSignalSMAPeriod)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get Fast EMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
{
Print("Getting slow SMA is failed! Error",GetLastError());
return(0);
}
//---
int i,limit;
if(prev_calculated==0)
limit=0;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total;i++)
{
//--- calculate MACD
ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
}
//--- calculate Signal
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMAPeriod,ExtMacdBuffer,ExtSignalBuffer);
//--- calculate OsMA
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtOsMABuffer[i]=ExtMacdBuffer[i]-ExtSignalBuffer[i];
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+92
View File
@@ -0,0 +1,92 @@
//+------------------------------------------------------------------+
//| PVT.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Price and Volume Trend"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- input parametrs
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffer
double ExtPVTBuffer[];
//+------------------------------------------------------------------+
//| PVT initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- define indicator buffer
SetIndexBuffer(0,ExtPVTBuffer);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- name for DataWindow and indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"PVT");
//--- set index empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- set index draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| PVT iteration function |
//+------------------------------------------------------------------+
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[])
{
//--- variables
int pos;
//--- check for bars count
if(rates_total<2)
return(0);
//--- start calculation
pos=prev_calculated-1;
//--- correct position, when it's first iteration
if(pos<0)
{
pos=1;
ExtPVTBuffer[0]=0.0;
}
//--- main cycle
if(InpVolumeType==VOLUME_TICK)
CalculatePVT(pos,rates_total,close,tick_volume);
else
CalculatePVT(pos,rates_total,close,volume);
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate PVT by volume argument |
//+------------------------------------------------------------------+
void CalculatePVT(int nPosition,
int nRatesCount,
const double &ClBuffer[],
const long &VolBuffer[])
{
if(nPosition<=0) nPosition=1;
//---
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
//--- get some data
double PrevClose=ClBuffer[i-1];
//--- calculate PVT value
if(PrevClose!=0)
ExtPVTBuffer[i]=((ClBuffer[i]-PrevClose)/PrevClose)*VolBuffer[i]+ExtPVTBuffer[i-1];
else ExtPVTBuffer[i]=ExtPVTBuffer[i-1];
}
//---
}
//+------------------------------------------------------------------+
@@ -0,0 +1,64 @@
//+------------------------------------------------------------------+
//| PanelChart.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_plots 0
#property indicator_buffers 0
#property indicator_minimum 0.0
#property indicator_maximum 0.0
#include "PanelDialog.mqh"
//+------------------------------------------------------------------+
//| Global Variables |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- create application dialog
if(!ExtDialog.Create(0,"Chart Panel ",0,50,50,390,300))
return(INIT_FAILED);
//--- run application
if(!ExtDialog.Run())
return(INIT_FAILED);
//--- succeed
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy application dialog
ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,375 @@
//+------------------------------------------------------------------+
//| PanelDialog.mqh |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\ComboBox.mqh>
#include <Controls\CheckBox.mqh>
#include <Controls\Label.mqh>
#include <Controls\SpinEdit.mqh>
#include <ChartObjects\ChartObjectSubChart.mqh>
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
//--- indents and gaps
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
#define INDENT_TOP (11) // indent from top (with allowance for border width)
#define INDENT_RIGHT (11) // indent from right (with allowance for border width)
#define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width)
#define CONTROLS_GAP_X (10) // gap by X coordinate
#define CONTROLS_GAP_Y (10) // gap by Y coordinate
//--- for combo boxes
#define COMBOBOX_WIDTH (100) // size by X coordinate
#define COMBOBOX_HEIGHT (20) // size by Y coordinate
//--- for spin edit
#define SPINEDIT_WIDTH (50) // size by X coordinate
//+------------------------------------------------------------------+
//| Class CPanelDialog |
//| Usage: main dialog of the Controls application |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
{
private:
CChartObjectSubChart m_subchart; // the sub-chart object
CComboBox m_symbols; // the symbols combo box object
CComboBox m_periods; // the timeframes combo box object
CCheckBox m_time; // the time scale management object
CCheckBox m_price; // the price scale management object
CLabel m_label; // the label object
CSpinEdit m_scale; // the scale management object
public:
CPanelDialog(void);
~CPanelDialog(void);
//--- create
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
//--- chart event handler
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
protected:
//--- create dependent controls
bool CreateSubchart(void);
bool CreateSymbols(void);
bool CreatePeriods(void);
bool CreateTime(void);
bool CreatePrice(void);
bool CreateLabel(void);
bool CreateScale(void);
//--- fill dependent controls
bool FillSymbols(void);
bool FillPeriods(void);
//--- internal event handlers
virtual bool OnResize(void);
//--- handlers of the dependent controls events
void OnChangeSymbols(void);
void OnChangePeriods(void);
void OnChangeTime(void);
void OnChangePrice(void);
void OnChangeScale(void);
//--- change dialog title
void SetCaption(void);
};
//+------------------------------------------------------------------+
//| Event Handling |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
ON_EVENT(ON_CHANGE,m_symbols,OnChangeSymbols)
ON_EVENT(ON_CHANGE,m_periods,OnChangePeriods)
ON_EVENT(ON_CHANGE,m_time,OnChangeTime)
ON_EVENT(ON_CHANGE,m_price,OnChangePrice)
ON_EVENT(ON_CHANGE,m_scale,OnChangeScale)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
{
}
//+------------------------------------------------------------------+
//| Create |
//+------------------------------------------------------------------+
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
return(false);
//--- create dependent controls
if(!CreateSubchart())
return(false);
if(!CreateTime())
return(false);
if(!CreatePrice())
return(false);
if(!CreateLabel())
return(false);
if(!CreateScale())
return(false);
if(!CreatePeriods())
return(false);
if(!CreateSymbols())
return(false);
//--- change dialog title
SetCaption();
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Chart of Chart" object |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateSubchart(void)
{
//--- coordinates
int x=ClientAreaLeft()+INDENT_LEFT;
int y=ClientAreaTop()+INDENT_TOP;
int w=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH+CONTROLS_GAP_X+INDENT_LEFT);
int h=ClientAreaHeight()-(INDENT_BOTTOM+INDENT_TOP);
//--- create
if(!m_subchart.Create(m_chart_id,m_name,m_subwin,x,y,w,h))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Symbols" combo box |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateSymbols(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
int y1=INDENT_TOP;
int x2=x1+COMBOBOX_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_symbols.Create(m_chart_id,m_name+"Symbols",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_symbols))
return(false);
m_symbols.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- fill
if(!FillSymbols())
return(false);
//--- select
m_symbols.SelectByText(Symbol());
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Timeframes" combo box |
//+------------------------------------------------------------------+
bool CPanelDialog::CreatePeriods(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
int y1=INDENT_TOP+COMBOBOX_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+COMBOBOX_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_periods.Create(m_chart_id,m_name+"Periods",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_periods))
return(false);
m_periods.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- fill
if(!FillPeriods())
return(false);
//--- select
m_periods.SelectByValue(Period());
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Time scale" check box |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateTime(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
int y1=INDENT_TOP+2*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+COMBOBOX_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_time.Create(m_chart_id,m_name+"Time",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_time.Text(" dates scale"))
return(false);
if(!Add(m_time))
return(false);
m_time.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- state
m_time.Checked(m_subchart.DateScale());
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Price scale" check box |
//+------------------------------------------------------------------+
bool CPanelDialog::CreatePrice(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
int y1=INDENT_TOP+3*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+COMBOBOX_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_price.Create(m_chart_id,m_name+"Price",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_price.Text(" prices scale"))
return(false);
if(!Add(m_price))
return(false);
m_price.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- state
m_price.Checked(m_subchart.PriceScale());
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create label for the "Scale" spin edit |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateLabel(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
int y1=INDENT_TOP+4*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+COMBOBOX_WIDTH-SPINEDIT_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_label.Create(m_chart_id,m_name+"Label",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_label.Text("Scale"))
return(false);
if(!Add(m_label))
return(false);
m_label.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT+SPINEDIT_WIDTH,0);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Scale" spin edit |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateScale(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+SPINEDIT_WIDTH);
int y1=INDENT_TOP+4*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+SPINEDIT_WIDTH;
int y2=y1+COMBOBOX_HEIGHT;
//--- create
if(!m_scale.Create(m_chart_id,m_name+"Scale",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_scale))
return(false);
m_scale.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- set up
m_scale.MinValue(0);
m_scale.MaxValue(5);
m_scale.Value(m_subchart.Scale());
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Fill the "Symbols" combo box |
//+------------------------------------------------------------------+
bool CPanelDialog::FillSymbols(void)
{
int total=SymbolsTotal(true);
for(int i=0;i<total;i++)
if(!m_symbols.ItemAdd(SymbolName(i,true)))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Fill the "Timeframes" combo box |
//+------------------------------------------------------------------+
bool CPanelDialog::FillPeriods(void)
{
static string name[]=
{
"M1","M2","M3","M4","M5","M6","M10","M12","M15","M20","M30",
"H1","H2","H3","H4","H6","H8","H12","Day","Week","Month"
};
static long value[]=
{
PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,
PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,
PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,
PERIOD_D1,PERIOD_W1,PERIOD_MN1
};
//---
int total=ArraySize(name);
if(total>ArraySize(value))
total=ArraySize(value);
//---
for(int i=0;i<total;i++)
if(!m_periods.ItemAdd(name[i],value[i]))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Handler of resizing |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
{
//--- call method of parent class
if(!CAppDialog::OnResize())
return(false);
//--- change width of sub-chart
m_subchart.X_Size(ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH+CONTROLS_GAP_X+INDENT_LEFT));
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Change dialog title |
//+------------------------------------------------------------------+
void CPanelDialog::SetCaption(void)
{
Caption(ProgramName()+"("+m_symbols.Select()+","+m_periods.Select()+")");
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeSymbols(void)
{
m_subchart.Symbol(m_symbols.Select());
//--- change dialog title
SetCaption();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangePeriods(void)
{
m_subchart.Period((int)m_periods.Value());
//--- change dialog title
SetCaption();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeTime(void)
{
m_subchart.DateScale(m_time.Checked());
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangePrice(void)
{
m_subchart.PriceScale(m_price.Checked());
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeScale(void)
{
m_subchart.Scale(m_scale.Value());
}
//+------------------------------------------------------------------+
@@ -0,0 +1,346 @@
//+------------------------------------------------------------------+
//| PanelDialog.mqh |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
#include <Controls\Edit.mqh>
#include <Controls\ListView.mqh>
#include <Controls\ComboBox.mqh>
#include <Controls\SpinEdit.mqh>
#include <Controls\RadioGroup.mqh>
#include <Controls\CheckGroup.mqh>
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
//--- indents and gaps
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
#define INDENT_TOP (11) // indent from top (with allowance for border width)
#define INDENT_RIGHT (11) // indent from right (with allowance for border width)
#define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width)
#define CONTROLS_GAP_X (10) // gap by X coordinate
#define CONTROLS_GAP_Y (10) // gap by Y coordinate
//--- for buttons
#define BUTTON_WIDTH (100) // size by X coordinate
#define BUTTON_HEIGHT (20) // size by Y coordinate
//--- for the indication area
#define EDIT_HEIGHT (20) // size by Y coordinate
//+------------------------------------------------------------------+
//| Class CPanelDialog |
//| Usage: main dialog of the SimplePanel application |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
{
private:
CEdit m_edit; // the display field object
CButton m_button1; // the button object
CButton m_button2; // the button object
CButton m_button3; // the fixed button object
CListView m_list_view; // the list object
CRadioGroup m_radio_group; // the radio buttons group object
CCheckGroup m_check_group; // the check box group object
public:
CPanelDialog(void);
~CPanelDialog(void);
//--- create
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
//--- chart event handler
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
protected:
//--- create dependent controls
bool CreateEdit(void);
bool CreateButton1(void);
bool CreateButton2(void);
bool CreateButton3(void);
bool CreateRadioGroup(void);
bool CreateCheckGroup(void);
bool CreateListView(void);
//--- internal event handlers
virtual bool OnResize(void);
//--- handlers of the dependent controls events
void OnClickButton1(void);
void OnClickButton2(void);
void OnClickButton3(void);
void OnChangeRadioGroup(void);
void OnChangeCheckGroup(void);
void OnChangeListView(void);
};
//+------------------------------------------------------------------+
//| Event Handling |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
ON_EVENT(ON_CLICK,m_button3,OnClickButton3)
ON_EVENT(ON_CHANGE,m_radio_group,OnChangeRadioGroup)
ON_EVENT(ON_CHANGE,m_check_group,OnChangeCheckGroup)
ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
{
}
//+------------------------------------------------------------------+
//| Create |
//+------------------------------------------------------------------+
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
return(false);
//--- create dependent controls
if(!CreateEdit())
return(false);
if(!CreateButton1())
return(false);
if(!CreateButton2())
return(false);
if(!CreateButton3())
return(false);
if(!CreateRadioGroup())
return(false);
if(!CreateCheckGroup())
return(false);
if(!CreateListView())
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the display field |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateEdit(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP;
int x2=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
int y2=y1+EDIT_HEIGHT;
//--- create
if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_edit.ReadOnly(true))
return(false);
if(!Add(m_edit))
return(false);
m_edit.Alignment(WND_ALIGN_WIDTH,INDENT_LEFT,0,INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X,0);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Button1" button |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateButton1(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
int y1=INDENT_TOP;
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button1.Text("Button1"))
return(false);
if(!Add(m_button1))
return(false);
m_button1.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Button2" button |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateButton2(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
int y1=INDENT_TOP+BUTTON_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button2.Text("Button2"))
return(false);
if(!Add(m_button2))
return(false);
m_button2.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Button3" fixed button |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateButton3(void)
{
//--- coordinates
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
int y1=ClientAreaHeight()-(INDENT_BOTTOM+BUTTON_HEIGHT);
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button3.Text("Locked"))
return(false);
if(!Add(m_button3))
return(false);
m_button3.Locking(true);
m_button3.Alignment(WND_ALIGN_RIGHT|WND_ALIGN_BOTTOM,0,0,INDENT_RIGHT,INDENT_BOTTOM);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "RadioGroup" element |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateRadioGroup(void)
{
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+sx;
int y2=ClientAreaHeight()-INDENT_BOTTOM;
//--- create
if(!m_radio_group.Create(m_chart_id,m_name+"RadioGroup",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_radio_group))
return(false);
m_radio_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
//--- fill out with strings
for(int i=0;i<4;i++)
if(!m_radio_group.AddItem("Item "+IntegerToString(i),1<<i))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "CheckGroup" element |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateCheckGroup(void)
{
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
//--- coordinates
int x1=INDENT_LEFT+sx+CONTROLS_GAP_X;
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+sx;
int y2=ClientAreaHeight()-INDENT_BOTTOM;
//--- create
if(!m_check_group.Create(m_chart_id,m_name+"CheckGroup",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_check_group))
return(false);
m_check_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
//--- fill out with strings
for(int i=0;i<4;i++)
if(!m_check_group.AddItem("Item "+IntegerToString(i),1<<i))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "ListView" element |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateListView(void)
{
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
//--- coordinates
int x1=ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
int x2=x1+sx;
int y2=ClientAreaHeight()-INDENT_BOTTOM;
//--- create
if(!m_list_view.Create(m_chart_id,m_name+"ListView",m_subwin,x1,y1,x2,y2))
return(false);
if(!Add(m_list_view))
return(false);
m_list_view.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
//--- fill out with strings
for(int i=0;i<16;i++)
if(!m_list_view.ItemAdd("Item "+IntegerToString(i)))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Handler of resizing |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
{
//--- call method of parent class
if(!CAppDialog::OnResize()) return(false);
//--- coordinates
int x=ClientAreaLeft()+INDENT_LEFT;
int y=m_radio_group.Top();
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
//--- move and resize the "RadioGroup" element
m_radio_group.Move(x,y);
m_radio_group.Width(sx);
//--- move and resize the "CheckGroup" element
x=ClientAreaLeft()+INDENT_LEFT+sx+CONTROLS_GAP_X;
m_check_group.Move(x,y);
m_check_group.Width(sx);
//--- move and resize the "ListView" element
x=ClientAreaLeft()+ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
m_list_view.Move(x,y);
m_list_view.Width(sx);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnClickButton1(void)
{
m_edit.Text(__FUNCTION__);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnClickButton2(void)
{
m_edit.Text(__FUNCTION__);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnClickButton3(void)
{
if(m_button3.Pressed())
m_edit.Text(__FUNCTION__+"On");
else
m_edit.Text(__FUNCTION__+"Off");
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeListView(void)
{
m_edit.Text(__FUNCTION__+" \""+m_list_view.Select()+"\"");
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeRadioGroup(void)
{
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeCheckGroup(void)
{
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_check_group.Value()));
}
//+------------------------------------------------------------------+
@@ -0,0 +1,64 @@
//+------------------------------------------------------------------+
//| SimplePanel.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_plots 0
#property indicator_buffers 0
#property indicator_minimum 0.0
#property indicator_maximum 0.0
#include "PanelDialog.mqh"
//+------------------------------------------------------------------+
//| Global Variables |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- create application dialog
if(!ExtDialog.Create(0,"Simple Panel",0,50,50,390,200))
return(INIT_FAILED);
//--- run application
if(!ExtDialog.Run())
return(INIT_FAILED);
//--- succeed
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy application dialog
ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
+199
View File
@@ -0,0 +1,199 @@
//+------------------------------------------------------------------+
//| ParabolicSAR.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_chart_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_ARROW
#property indicator_color1 DodgerBlue
//--- External parametrs
input double InpSARStep=0.02; // Step
input double InpSARMaximum=0.2; // Maximum
//---- buffers
double ExtSARBuffer[];
double ExtEPBuffer[];
double ExtAFBuffer[];
//--- global variables
int ExtLastRevPos;
bool ExtDirectionLong;
double ExtSarStep;
double ExtSarMaximum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- checking input data
if(InpSARStep<0.0)
{
ExtSarStep=0.02;
Print("Input parametr InpSARStep has incorrect value. Indicator will use value",
ExtSarStep,"for calculations.");
}
else ExtSarStep=InpSARStep;
if(InpSARMaximum<0.0)
{
ExtSarMaximum=0.2;
Print("Input parametr InpSARMaximum has incorrect value. Indicator will use value",
ExtSarMaximum,"for calculations.");
}
else ExtSarMaximum=InpSARMaximum;
//---- indicator buffers
SetIndexBuffer(0,ExtSARBuffer);
SetIndexBuffer(1,ExtEPBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtAFBuffer,INDICATOR_CALCULATIONS);
//--- set arrow symbol
PlotIndexSetInteger(0,PLOT_ARROW,159);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set label name
PlotIndexSetString(0,PLOT_LABEL,"SAR("+
DoubleToString(ExtSarStep,2)+","+
DoubleToString(ExtSarMaximum,2)+")");
//--- set global variables
ExtLastRevPos=0;
ExtDirectionLong=false;
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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 minimum rates count
if(rates_total<3)
return(0);
//--- detect current position
int pos=prev_calculated-1;
//--- correct position
if(pos<1)
{
//--- first pass, set as SHORT
pos=1;
ExtAFBuffer[0]=ExtSarStep;
ExtAFBuffer[1]=ExtSarStep;
ExtSARBuffer[0]=high[0];
ExtLastRevPos=0;
ExtDirectionLong=false;
ExtSARBuffer[1]=GetHigh(pos,ExtLastRevPos,high);
ExtEPBuffer[0]=low[pos];
ExtEPBuffer[1]=low[pos];
}
//---main cycle
for(int i=pos;i<rates_total-1 && !IsStopped();i++)
{
//--- check for reverse
if(ExtDirectionLong)
{
if(ExtSARBuffer[i]>low[i])
{
//--- switch to SHORT
ExtDirectionLong=false;
ExtSARBuffer[i]=GetHigh(i,ExtLastRevPos,high);
ExtEPBuffer[i]=low[i];
ExtLastRevPos=i;
ExtAFBuffer[i]=ExtSarStep;
}
}
else
{
if(ExtSARBuffer[i]<high[i])
{
//--- switch to LONG
ExtDirectionLong=true;
ExtSARBuffer[i]=GetLow(i,ExtLastRevPos,low);
ExtEPBuffer[i]=high[i];
ExtLastRevPos=i;
ExtAFBuffer[i]=ExtSarStep;
}
}
//--- continue calculations
if(ExtDirectionLong)
{
//--- check for new High
if(high[i]>ExtEPBuffer[i-1] && i!=ExtLastRevPos)
{
ExtEPBuffer[i]=high[i];
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
if(ExtAFBuffer[i]>ExtSarMaximum)
ExtAFBuffer[i]=ExtSarMaximum;
}
else
{
//--- when we haven't reversed
if(i!=ExtLastRevPos)
{
ExtAFBuffer[i]=ExtAFBuffer[i-1];
ExtEPBuffer[i]=ExtEPBuffer[i-1];
}
}
//--- calculate SAR for tomorrow
ExtSARBuffer[i+1]=ExtSARBuffer[i]+ExtAFBuffer[i]*(ExtEPBuffer[i]-ExtSARBuffer[i]);
//--- check for SAR
if(ExtSARBuffer[i+1]>low[i] || ExtSARBuffer[i+1]>low[i-1])
ExtSARBuffer[i+1]=MathMin(low[i],low[i-1]);
}
else
{
//--- check for new Low
if(low[i]<ExtEPBuffer[i-1] && i!=ExtLastRevPos)
{
ExtEPBuffer[i]=low[i];
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
if(ExtAFBuffer[i]>ExtSarMaximum)
ExtAFBuffer[i]=ExtSarMaximum;
}
else
{
//--- when we haven't reversed
if(i!=ExtLastRevPos)
{
ExtAFBuffer[i]=ExtAFBuffer[i-1];
ExtEPBuffer[i]=ExtEPBuffer[i-1];
}
}
//--- calculate SAR for tomorrow
ExtSARBuffer[i+1]=ExtSARBuffer[i]+ExtAFBuffer[i]*(ExtEPBuffer[i]-ExtSARBuffer[i]);
//--- check for SAR
if(ExtSARBuffer[i+1]<high[i] || ExtSARBuffer[i+1]<high[i-1])
ExtSARBuffer[i+1]=MathMax(high[i],high[i-1]);
}
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Find highest price from start to current position |
//+------------------------------------------------------------------+
double GetHigh(int nPosition,int nStartPeriod,const double &HiData[])
{
//--- calculate
double result=HiData[nStartPeriod];
for(int i=nStartPeriod;i<=nPosition;i++) if(result<HiData[i]) result=HiData[i];
return(result);
}
//+------------------------------------------------------------------+
//| Find lowest price from start to current position |
//+------------------------------------------------------------------+
double GetLow(int nPosition,int nStartPeriod,const double &LoData[])
{
//--- calculate
double result=LoData[nStartPeriod];
for(int i=nStartPeriod;i<=nPosition;i++) if(result>LoData[i]) result=LoData[i];
return(result);
}
//+------------------------------------------------------------------+
+113
View File
@@ -0,0 +1,113 @@
//+------------------------------------------------------------------+
//| Price_Channell.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_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_type1 DRAW_FILLING
#property indicator_type2 DRAW_LINE
#property indicator_color1 DodgerBlue,Gray
#property indicator_color2 Blue
#property indicator_label1 "Channel upper;Channel lower"
#property indicator_label2 "Channel median"
//--- input parameters
input int InpChannelPeriod=22; // Period
//--- indicator buffers
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtMiddBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtHighBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtLowBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtMiddBuffer,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,1);
PlotIndexSetInteger(1,PLOT_SHIFT,1);
//--- name for DataWindow and indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"Price Channel("+string(InpChannelPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"Channel("+string(InpChannelPeriod)+") upper;Channel("+string(InpChannelPeriod)+") lower");
PlotIndexSetString(1,PLOT_LABEL,"Median("+string(InpChannelPeriod)+")");
//--- set drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//--- initialization done
}
//+------------------------------------------------------------------+
//| get highest value for range |
//+------------------------------------------------------------------+
double Highest(const double &array[],int range,int fromIndex)
{
double res;
int i;
//---
res=array[fromIndex];
for(i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res<array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| get lowest value for range |
//+------------------------------------------------------------------+
double Lowest(const double &array[],int range,int fromIndex)
{
double res;
int i;
//---
res=array[fromIndex];
for(i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res>array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Price Channell |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for rates
if(rates_total<InpChannelPeriod)
return(0);
//--- preliminary calculations
if(prev_calculated==0)
limit=InpChannelPeriod;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtHighBuffer[i]=Highest(high,InpChannelPeriod,i);
ExtLowBuffer[i]=Lowest(low,InpChannelPeriod,i);
ExtMiddBuffer[i]=(ExtHighBuffer[i]+ExtLowBuffer[i])/2.0;;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+67
View File
@@ -0,0 +1,67 @@
//+------------------------------------------------------------------+
//| ROC.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//--- input parameters
input int InpRocPeriod=12; // Period
//--- indicator buffers
double ExtRocBuffer[];
//--- global variable
int ExtRocPeriod;
//+------------------------------------------------------------------+
//| Rate of Change initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpRocPeriod<1)
{
ExtRocPeriod=12;
Print("Incorrect value for input variable InpRocPeriod =",InpRocPeriod,
"Indicator will use value =",ExtRocPeriod,"for calculations.");
}
else ExtRocPeriod=InpRocPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Rate of Change |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- check for rates count
if(rates_total<ExtRocPeriod)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1; // set calc position
if(pos<ExtRocPeriod)
pos=ExtRocPeriod;
//--- the main loop of calculations
for(int i=pos;i<rates_total && !IsStopped();i++)
{
if(price[i]==0.0)
ExtRocBuffer[i]=0.0;
else
ExtRocBuffer[i]=(price[i]-price[i-ExtRocPeriod])/price[i]*100;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+118
View File
@@ -0,0 +1,118 @@
//+------------------------------------------------------------------+
//| RSI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Relative Strength Index"
//--- indicator settings
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- input parameters
input int InpPeriodRSI=14; // Period
//--- indicator buffers
double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
//--- global variable
int ExtPeriodRSI;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpPeriodRSI<1)
{
ExtPeriodRSI=12;
Print("Incorrect value for input variable InpPeriodRSI =",InpPeriodRSI,
"Indicator will use value =",ExtPeriodRSI,"for calculations.");
}
else ExtPeriodRSI=InpPeriodRSI;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRSIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtPosBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtNegBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodRSI);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"RSI("+string(ExtPeriodRSI)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
int i;
double diff;
//--- check for rates count
if(rates_total<=ExtPeriodRSI)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1;
if(pos<=ExtPeriodRSI)
{
//--- first RSIPeriod values of the indicator are not calculated
ExtRSIBuffer[0]=0.0;
ExtPosBuffer[0]=0.0;
ExtNegBuffer[0]=0.0;
double SumP=0.0;
double SumN=0.0;
for(i=1;i<=ExtPeriodRSI;i++)
{
ExtRSIBuffer[i]=0.0;
ExtPosBuffer[i]=0.0;
ExtNegBuffer[i]=0.0;
diff=price[i]-price[i-1];
SumP+=(diff>0?diff:0);
SumN+=(diff<0?-diff:0);
}
//--- calculate first visible value
ExtPosBuffer[ExtPeriodRSI]=SumP/ExtPeriodRSI;
ExtNegBuffer[ExtPeriodRSI]=SumN/ExtPeriodRSI;
if(ExtNegBuffer[ExtPeriodRSI]!=0.0)
ExtRSIBuffer[ExtPeriodRSI]=100.0-(100.0/(1.0+ExtPosBuffer[ExtPeriodRSI]/ExtNegBuffer[ExtPeriodRSI]));
else
{
if(ExtPosBuffer[ExtPeriodRSI]!=0.0)
ExtRSIBuffer[ExtPeriodRSI]=100.0;
else
ExtRSIBuffer[ExtPeriodRSI]=50.0;
}
//--- prepare the position value for main calculation
pos=ExtPeriodRSI+1;
}
//--- the main loop of calculations
for(i=pos;i<rates_total && !IsStopped();i++)
{
diff=price[i]-price[i-1];
ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(ExtPeriodRSI-1)+(diff>0.0?diff:0.0))/ExtPeriodRSI;
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(ExtPeriodRSI-1)+(diff<0.0?-diff:0.0))/ExtPeriodRSI;
if(ExtNegBuffer[i]!=0.0)
ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
else
{
if(ExtPosBuffer[i]!=0.0)
ExtRSIBuffer[i]=100.0;
else
ExtRSIBuffer[i]=50.0;
}
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+101
View File
@@ -0,0 +1,101 @@
//+------------------------------------------------------------------+
//| RVI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Relative Vigor Index"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_label1 "RVI"
#property indicator_label2 "Signal"
//--- input parameters
input int InpRVIPeriod=10; // Period
//--- indicator buffers
double ExtRVIBuffer[];
double ExtSignalBuffer[];
//---
#define TRIANGLE_PERIOD 3
#define AVERAGE_PERIOD (TRIANGLE_PERIOD*2)
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRVIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
IndicatorSetInteger(INDICATOR_DIGITS,3);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+TRIANGLE_PERIOD);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+AVERAGE_PERIOD);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"RVI("+string(InpRVIPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"RVI("+string(InpRVIPeriod)+")");
PlotIndexSetString(1,PLOT_LABEL,"Signal("+string(InpRVIPeriod)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Relative Vigor Index |
//+------------------------------------------------------------------+
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[])
{
int i,j,nLimit;
double dValueUp,dValueDown,dNum,dDeNum;
//--- check for bars count
if(rates_total<=InpRVIPeriod+AVERAGE_PERIOD+2) return(0); // exit with zero result
//--- check for possible errors
if(prev_calculated<0) return(0); // exit with zero result
//--- last counted bar will be recounted
nLimit=InpRVIPeriod+2;
if(prev_calculated>InpRVIPeriod+TRIANGLE_PERIOD+2)
nLimit=prev_calculated-1;
//--- set empty value for uncalculated bars
if(prev_calculated==0)
{
for(i=0;i<InpRVIPeriod+TRIANGLE_PERIOD;i++) ExtRVIBuffer[i]=0.0;
for(i=0;i<InpRVIPeriod+AVERAGE_PERIOD;i++) ExtSignalBuffer[i]=0.0;
}
//--- RVI counted in the 1-st buffer
for(i=nLimit;i<rates_total && !IsStopped();i++)
{
dNum=0.0;
dDeNum=0.0;
for(j=i;j>i-InpRVIPeriod;j--)
{
dValueUp=close[j]-open[j]+2*(close[j-1]-open[j-1])+2*(close[j-2]-open[j-2])+close[j-3]-open[j-3];
dValueDown=high[j]-low[j]+2*(high[j-1]-low[j-1])+2*(high[j-2]-low[j-2])+high[j-3]-low[j-3];
dNum+=dValueUp;
dDeNum+=dValueDown;
}
if(dDeNum!=0.0)
ExtRVIBuffer[i]=dNum/dDeNum;
else
ExtRVIBuffer[i]=dNum;
}
//--- signal line counted in the 2-nd buffer
nLimit=InpRVIPeriod+TRIANGLE_PERIOD+2;
if(prev_calculated>InpRVIPeriod+AVERAGE_PERIOD+2)
nLimit=prev_calculated-1;
for(i=nLimit;i<rates_total && !IsStopped();i++) ExtSignalBuffer[i]=(ExtRVIBuffer[i]+2*ExtRVIBuffer[i-1]+2*ExtRVIBuffer[i-2]+ExtRVIBuffer[i-3])/AVERAGE_PERIOD;
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+129
View File
@@ -0,0 +1,129 @@
//+------------------------------------------------------------------+
//| StdDev.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Standard Deviation"
#include <MovingAverages.mqh>
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 MediumSeaGreen
#property indicator_style1 STYLE_SOLID
//--- input parametrs
input int InpStdDevPeriod=20; // Period
input int InpStdDevShift=0; // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method
//---- buffers
double ExtStdDevBuffer[];
double ExtMABuffer[];
//--- global variables
int ExtStdDevPeriod,ExtStdDevShift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input values
if(InpStdDevPeriod<=1)
{
ExtStdDevPeriod=20;
printf("Incorrect value for input variable InpStdDevPeriod=%d. Indicator will use value=%d for calculations.",InpStdDevPeriod,ExtStdDevPeriod);
}
else ExtStdDevPeriod=InpStdDevPeriod;
if(InpStdDevShift<0)
{
ExtStdDevShift=0;
printf("Incorrect value for input variable InpStdDevShift=%d. Indicator will use value=%d for calculations.",InpStdDevShift,ExtStdDevShift);
}
else ExtStdDevShift=InpStdDevShift;
//--- set indicator short name
IndicatorSetString(INDICATOR_SHORTNAME,"StdDev("+string(ExtStdDevPeriod)+")");
//---- define indicator buffers as indexes
SetIndexBuffer(0,ExtStdDevBuffer);
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//--- set index label
PlotIndexSetString(0,PLOT_LABEL,"StdDev("+string(ExtStdDevPeriod)+")");
//--- set index shift
PlotIndexSetInteger(0,PLOT_SHIFT,ExtStdDevShift);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- variables of indicator
int pos;
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtStdDevPeriod-1+begin);
//--- check for rates count
if(rates_total<ExtStdDevPeriod)
return(0);
//--- starting work
pos=prev_calculated-1;
//--- correct position for first iteration
if(pos<ExtStdDevPeriod)
{
pos=ExtStdDevPeriod-1;
ArrayInitialize(ExtStdDevBuffer,0.0);
ArrayInitialize(ExtMABuffer,0.0);
}
//--- main cycle
switch(InpMAMethod)
{
case MODE_EMA :
for(int i=pos;i<rates_total && !IsStopped();i++)
{
if(i==InpStdDevPeriod-1)
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
else
ExtMABuffer[i]=ExponentialMA(i,InpStdDevPeriod,ExtMABuffer[i-1],price);
//--- Calculate StdDev
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
}
break;
case MODE_SMMA :
for(int i=pos;i<rates_total && !IsStopped();i++)
{
if(i==InpStdDevPeriod-1)
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
else
ExtMABuffer[i]=SmoothedMA(i,InpStdDevPeriod,ExtMABuffer[i-1],price);
//--- Calculate StdDev
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
}
break;
case MODE_LWMA :
for(int i=pos;i<rates_total && !IsStopped();i++)
{
ExtMABuffer[i]=LinearWeightedMA(i,InpStdDevPeriod,price);
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
}
break;
default :
for(int i=pos;i<rates_total && !IsStopped();i++)
{
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
//--- Calculate StdDev
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
}
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate Standard Deviation |
//+------------------------------------------------------------------+
double StdDevFunc(const double &price[],const double &MAprice[],int position)
{
double dTmp=0.0;
for(int i=0;i<ExtStdDevPeriod;i++) dTmp+=MathPow(price[position-i]-MAprice[position],2);
dTmp=MathSqrt(dTmp/ExtStdDevPeriod);
return(dTmp);
}
//+------------------------------------------------------------------+
+132
View File
@@ -0,0 +1,132 @@
//+------------------------------------------------------------------+
//| Stochastic.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 4
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_style2 STYLE_DOT
//--- input parameters
input int InpKPeriod=5; // K period
input int InpDPeriod=3; // D period
input int InpSlowing=3; // Slowing
//--- indicator buffers
double ExtMainBuffer[];
double ExtSignalBuffer[];
double ExtHighesBuffer[];
double ExtLowesBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtMainBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtHighesBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtLowesBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set levels
IndicatorSetInteger(INDICATOR_LEVELS,2);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,80);
//--- set maximum and minimum for subwindow
IndicatorSetDouble(INDICATOR_MINIMUM,0);
IndicatorSetDouble(INDICATOR_MAXIMUM,100);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Stoch("+(string)InpKPeriod+","+(string)InpDPeriod+","+(string)InpSlowing+")");
PlotIndexSetString(0,PLOT_LABEL,"Main");
PlotIndexSetString(1,PLOT_LABEL,"Signal");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Stochastic Oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,k,start;
//--- check for bars count
if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
return(0);
//---
start=InpKPeriod-1;
if(start+1<prev_calculated) start=prev_calculated-2;
else
{
for(i=0;i<start;i++)
{
ExtLowesBuffer[i]=0.0;
ExtHighesBuffer[i]=0.0;
}
}
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
for(i=start;i<rates_total && !IsStopped();i++)
{
double dmin=1000000.0;
double dmax=-1000000.0;
for(k=i-InpKPeriod+1;k<=i;k++)
{
if(dmin>low[k]) dmin=low[k];
if(dmax<high[k]) dmax=high[k];
}
ExtLowesBuffer[i]=dmin;
ExtHighesBuffer[i]=dmax;
}
//--- %K
start=InpKPeriod-1+InpSlowing-1;
if(start+1<prev_calculated) start=prev_calculated-2;
else
{
for(i=0;i<start;i++) ExtMainBuffer[i]=0.0;
}
//--- main cycle
for(i=start;i<rates_total && !IsStopped();i++)
{
double sumlow=0.0;
double sumhigh=0.0;
for(k=(i-InpSlowing+1);k<=i;k++)
{
sumlow +=(close[k]-ExtLowesBuffer[k]);
sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
}
if(sumhigh==0.0) ExtMainBuffer[i]=100.0;
else ExtMainBuffer[i]=sumlow/sumhigh*100;
}
//--- signal
start=InpDPeriod-1;
if(start+1<prev_calculated) start=prev_calculated-2;
else
{
for(i=0;i<start;i++) ExtSignalBuffer[i]=0.0;
}
for(i=start;i<rates_total && !IsStopped();i++)
{
double sum=0.0;
for(k=0;k<InpDPeriod;k++) sum+=ExtMainBuffer[i-k];
ExtSignalBuffer[i]=sum/InpDPeriod;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+75
View File
@@ -0,0 +1,75 @@
//+------------------------------------------------------------------+
//| TEMA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Triple Exponential Moving Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DarkBlue
#property indicator_width1 1
#property indicator_label1 "TEMA"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodEMA=14; // EMA period
input int InpShift=0; // Indicator's shift
//--- indicator buffers
double TemaBuffer[];
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,TemaBuffer,INDICATOR_DATA);
SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,EmaOfEmaOfEma,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3);
//--- sets indicator shift
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"TEMA("+string(InpPeriodEMA)+")");
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"TEMA("+string(InpPeriodEMA)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Triple Exponential Moving Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for data
if(rates_total<3*InpPeriodEMA-3)
return(0);
//---
int limit;
if(prev_calculated==0)
limit=0;
else limit=prev_calculated-1;
//--- calculate EMA
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema);
//--- calculate EMA on EMA array
ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma);
//--- calculate EMA on EMA array on EMA array
ExponentialMAOnBuffer(rates_total,prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,EmaOfEma,EmaOfEmaOfEma);
//--- calculate TEMA
for(int i=limit;i<rates_total && !IsStopped();i++)
TemaBuffer[i]=3*Ema[i]-3*EmaOfEma[i]+EmaOfEmaOfEma[i];
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+83
View File
@@ -0,0 +1,83 @@
//+------------------------------------------------------------------+
//| TRIX.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Triple Exponential Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
#property indicator_width1 1
#property indicator_label1 "TRIX"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodEMA=14; // EMA period
//--- indicator buffers
double TRIX_Buffer[];
double EMA[];
double SecondEMA[];
double ThirdEMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,TRIX_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,EMA,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,SecondEMA,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ThirdEMA,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3);
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"TRIX("+string(InpPeriodEMA)+")");
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"TRIX("+string(InpPeriodEMA)+")");
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,5);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Triple Exponential Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for data
if(rates_total<3*InpPeriodEMA-3)
return(0);
//---
int limit;
if(prev_calculated==0)
{
limit=3*(InpPeriodEMA-1);
for(int i=0;i<limit;i++)
TRIX_Buffer[i]=EMPTY_VALUE;
}
else limit=prev_calculated-1;
//--- calculate EMA
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,EMA);
//--- calculate EMA on EMA array
ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,EMA,SecondEMA);
//--- calculate EMA on EMA array on EMA array
ExponentialMAOnBuffer(rates_total,prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,SecondEMA,ThirdEMA);
//--- calculate TRIX
for(int i=limit;i<rates_total && !IsStopped();i++)
{
if(ThirdEMA[i-1]!=0.0)
TRIX_Buffer[i]=(ThirdEMA[i]-ThirdEMA[i-1])/ThirdEMA[i-1];
else
TRIX_Buffer[i]=0.0;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+179
View File
@@ -0,0 +1,179 @@
//+------------------------------------------------------------------+
//| Ultimate_Oscillator.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- input parameters
input int InpFastPeriod=7; // Fast ATR period
input int InpMiddlePeriod=14; // Middle ATR period
input int InpSlowPeriod=28; // Slow ATR period
input int InpFastK=4; // Fast K
input int InpMiddleK=2; // Middle K
input int InpSlowK=1; // Slow K
//--- indicator buffers
double ExtUOBuffer[];
double ExtBPBuffer[];
double ExtFastATRBuffer[];
double ExtMiddleATRBuffer[];
double ExtSlowATRBuffer[];
//--- indicator handles
int ExtFastATRhandle;
int ExtMiddleATRhandle;
int ExtSlowATRhandle;
//--- global variable
double ExtDivider;
int ExtMaxPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtUOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtBPBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtFastATRBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtMiddleATRBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,ExtSlowATRBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set levels
IndicatorSetInteger(INDICATOR_LEVELS,2);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,30);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,70);
//--- set maximum and minimum for subwindow
IndicatorSetDouble(INDICATOR_MINIMUM,0);
IndicatorSetDouble(INDICATOR_MAXIMUM,100);
//--- set first bar from which index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowPeriod-1);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"UOS("+string(InpFastPeriod)+", "+string(InpMiddlePeriod)+", "+string(InpSlowPeriod)+")");
//--- get handles
ExtFastATRhandle=iATR(Symbol(),0,InpFastPeriod);
ExtMiddleATRhandle=iATR(Symbol(),0,InpMiddlePeriod);
ExtSlowATRhandle=iATR(Symbol(),0,InpSlowPeriod);
//---
ExtDivider=InpFastK+InpMiddleK+InpSlowK;
ExtMaxPeriod=InpSlowPeriod;
if(ExtMaxPeriod<InpMiddlePeriod) ExtMaxPeriod=InpMiddlePeriod;
if(ExtMaxPeriod<InpFastPeriod) ExtMaxPeriod=InpFastPeriod;
//--- initialization done
}
//+------------------------------------------------------------------+
//| Ultimate Oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
double TL,RawUO;
//--- check for rates count
if(rates_total<ExtMaxPeriod)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastATRhandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastATRhandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtMiddleATRhandle);
if(calculated<rates_total)
{
Print("Not all data of ExtMiddleATRhandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowATRhandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowATRhandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ATR buffers
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtFastATRhandle,0,0,to_copy,ExtFastATRBuffer)<=0)
{
Print("getting ExtFastATRhandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtMiddleATRhandle,0,0,to_copy,ExtMiddleATRBuffer)<=0)
{
Print("getting ExtMiddleATRhandle is failed! Error",GetLastError());
return(0);
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowATRhandle,0,0,to_copy,ExtSlowATRBuffer)<=0)
{
Print("getting ExtSlowATRhandle is failed! Error",GetLastError());
return(0);
}
//--- preliminary calculations
if(prev_calculated==0)
{
//--- set empty value for first bar
ExtBPBuffer[0]=0.0;
ExtUOBuffer[0]=0.0;
//--- set value for first InpSlowPeriod bars
for(i=1;i<=InpSlowPeriod;i++)
{
ExtUOBuffer[i]=0.0;
TL=MathMin(low[i],close[i-1]);
ExtBPBuffer[i]=close[i]-TL;
}
//--- now we are going to calculate from limit index in main loop
limit=InpSlowPeriod+1;
}
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
//--- TL is True Low
TL=MathMin(low[i],close[i-1]);
//--- buying pressure
ExtBPBuffer[i]=close[i]-TL;
//--- first we calculate "raw" value
if(ExtFastATRBuffer[i]!=0.0 &&
ExtMiddleATRBuffer[i]!=0.0 &&
ExtSlowATRBuffer[i]!=0.0)
{
RawUO=InpFastK*SimpleMA(i,InpFastPeriod,ExtBPBuffer)/ExtFastATRBuffer[i]+
InpMiddleK*SimpleMA(i,InpMiddlePeriod,ExtBPBuffer)/ExtMiddleATRBuffer[i]+
InpSlowK*SimpleMA(i,InpSlowPeriod,ExtBPBuffer)/ExtSlowATRBuffer[i];
//--- now we can get current Ultimate value
ExtUOBuffer[i]=RawUO/ExtDivider*100;
}
else
{
//--- set current Ultimate value as previous Ultimate value
ExtUOBuffer[i]=ExtUOBuffer[i-1];
}
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+98
View File
@@ -0,0 +1,98 @@
//+------------------------------------------------------------------+
//| VIDYA.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Variable Index Dynamic Average"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
#property indicator_width1 1
#property indicator_label1 "VIDYA"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodCMO=9; // Period CMO
input int InpPeriodEMA=12; // Period EMA
input int InpShift=0; // Indicator's shift
//--- indicator buffers
double VIDYA_Buffer[];
//---
double ExtF;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,VIDYA_Buffer,INDICATOR_DATA);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpPeriodEMA+InpPeriodCMO-1);
//--- sets indicator shift
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"VIDYA("+string(InpPeriodCMO)+","+string(InpPeriodEMA)+")");
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"VIDYA("+string(InpPeriodCMO)+","+string(InpPeriodEMA)+")");
//--- calculate smooth factor
ExtF=2.0/(1.0+InpPeriodEMA);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Variable Index Dynamic Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- check for data
if(rates_total<InpPeriodEMA+InpPeriodCMO-1)
return(0);
//---
int limit;
if(prev_calculated<InpPeriodEMA+InpPeriodCMO-1)
{
limit=InpPeriodEMA+InpPeriodCMO-1;
for(int i=0;i<limit;i++)
VIDYA_Buffer[i]=price[i];
}
else limit=prev_calculated-1;
//--- main cycle
for(int i=limit;i<rates_total && !IsStopped();i++)
{
//--- calculate CMO and get absolute value
double mulCMO=fabs(CalculateCMO(i,InpPeriodCMO,price));
//--- calculate VIDYA
VIDYA_Buffer[i]=price[i]*ExtF*mulCMO+VIDYA_Buffer[i-1]*(1-ExtF*mulCMO);
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Chande Momentum Oscillator |
//+------------------------------------------------------------------+
double CalculateCMO(int Position,const int PeriodCMO,const double &price[])
{
double resCMO=0.0;
double UpSum=0.0,DownSum=0.0;
if(Position>=PeriodCMO && ArrayRange(price,0)>Position)
{
for(int i=0;i<PeriodCMO;i++)
{
double diff=price[Position-i]-price[Position-i-1];
if(diff>0.0)
UpSum+=diff;
else
DownSum+=(-diff);
}
if(UpSum+DownSum!=0.0)
resCMO=(UpSum-DownSum)/(UpSum+DownSum);
}
return(resCMO);
}
//+------------------------------------------------------------------+
+98
View File
@@ -0,0 +1,98 @@
//+------------------------------------------------------------------+
//| VROC.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Volume Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Green
#property indicator_style1 0
#property indicator_width1 1
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//--- input parametrs
input int InpPeriodVROC=25; // Period
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffer
double ExtVROCBuffer[];
//--- global variable
int ExtPeriodVROC;
//+------------------------------------------------------------------+
//| VROC initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(InpPeriodVROC<=1)
{
ExtPeriodVROC=25;
printf("Incorrect value for input variable InpPeriodVROC=%d. Indicator will use value=%d for calculations.",
InpPeriodVROC,ExtPeriodVROC);
}
else ExtPeriodVROC=InpPeriodVROC;
//--- define index buffer
SetIndexBuffer(0,ExtVROCBuffer);
//--- set indicator short name
IndicatorSetString(INDICATOR_SHORTNAME,"VROC("+string(ExtPeriodVROC)+")");
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodVROC-1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| VROC iteration function |
//+------------------------------------------------------------------+
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 count
if(rates_total<ExtPeriodVROC)
return(0);
//--- starting work
int pos=prev_calculated-1;
//--- initializing ExtVROCBuffer
if(pos<ExtPeriodVROC-1) pos=ExtPeriodVROC-1;
//--- main cycle by volume type
if(InpVolumeType==VOLUME_TICK)
CalculateVROC(pos,rates_total,tick_volume);
else
CalculateVROC(pos,rates_total,volume);
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate VROC by volume argument |
//+------------------------------------------------------------------+
void CalculateVROC(const int nPosition,
const int nRatesCount,
const long &VolBuffer[])
{
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
//--- getting some data
double PrevVolume=(double)(VolBuffer[i-(ExtPeriodVROC-1)]);
double CurrVolume=(double)VolBuffer[i];
//--- fill ExtVROCBuffer
if(PrevVolume!=0.0)
ExtVROCBuffer[i]=100.0*(CurrVolume-PrevVolume)/PrevVolume;
else
ExtVROCBuffer[i]=ExtVROCBuffer[i-1];
}
}
//+------------------------------------------------------------------+
+89
View File
@@ -0,0 +1,89 @@
//+------------------------------------------------------------------+
//| 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
#property indicator_width1 1
#property indicator_minimum 0.0
//--- input data
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffers
double ExtVolumesBuffer[];
double ExtColorsBuffer[];
//+------------------------------------------------------------------+
//| 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);
//----
}
//+------------------------------------------------------------------+
//| 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];
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;
}
//---
}
//+------------------------------------------------------------------+
+112
View File
@@ -0,0 +1,112 @@
//+------------------------------------------------------------------+
//| WPR.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Larry Williams' Percent Range"
//---- indicator settings
#property indicator_separate_window
#property indicator_level1 -20.0
#property indicator_level2 -80.0
#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor Silver
#property indicator_levelwidth 1
#property indicator_maximum 0.0
#property indicator_minimum -100.0
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//---- input parameters
input int InpWPRPeriod=14; // Period
//---- buffers
double ExtWPRBuffer[];
//--- global variables
int ExtPeriodWPR;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input value
if(InpWPRPeriod<3)
{
ExtPeriodWPR=14;
Print("Incorrect InpWPRPeriod value. Indicator will use value=",ExtPeriodWPR);
}
else ExtPeriodWPR=InpWPRPeriod;
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"%R"+"("+string(ExtPeriodWPR)+")");
//---- indicator's buffer
SetIndexBuffer(0,ExtWPRBuffer);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodWPR-1);
//--- digits
IndicatorSetInteger(INDICATOR_DIGITS,2);
//----
}
//+------------------------------------------------------------------+
//| Williams Percent Range |
//+------------------------------------------------------------------+
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[])
{
//---- insufficient data
if(rates_total<ExtPeriodWPR)
return(0);
//--- start working
int i=prev_calculated-1;
//--- correct position
if(i<ExtPeriodWPR-1) i=ExtPeriodWPR-1;
//--- main cycle
while(i<rates_total && !IsStopped())
{
//--- calculate maximum High
double dMaxHigh=MaxAr(high,ExtPeriodWPR,i);
//--- calculate minimum Low
double dMinLow=MinAr(low,ExtPeriodWPR,i);
//--- calculate WPR
if(dMaxHigh!=dMinLow)
ExtWPRBuffer[i]=-(dMaxHigh-close[i])*100/(dMaxHigh-dMinLow);
else
ExtWPRBuffer[i]=ExtWPRBuffer[i-1];
//--- increment i for next iteration
i++;
}
//--- return new prev_calculated value
return(rates_total);
}
//+------------------------------------------------------------------+
//| Maximum High |
//+------------------------------------------------------------------+
double MaxAr(const double &array[],int period,int cur_position)
{
double Highest=array[cur_position];
for(int i=cur_position-1;i>cur_position-period;i--)
{
if(Highest<array[i]) Highest=array[i];
}
return(Highest);
}
//+------------------------------------------------------------------+
//| Minimum Low |
//+------------------------------------------------------------------+
double MinAr(const double &array[],int period,int cur_position)
{
double Lowest=array[cur_position];
for(int i=cur_position-1;i>cur_position-period;i--)
{
if(Lowest>array[i]) Lowest=array[i];
}
return(Lowest);
}
//+------------------------------------------------------------------+
+95
View File
@@ -0,0 +1,95 @@
//+------------------------------------------------------------------+
//| W_AD.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Larry Williams' Accumulation/Distribution"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//---- buffers
double ExtWADBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- define buffer
SetIndexBuffer(0,ExtWADBuffer);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"W_A/D");
//--- round settings
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
if(rates_total<2)
return(0);
//--- start working
int pos=prev_calculated-1;
//--- correct position, set initial value
if(pos<=0)
{
pos=1;
ExtWADBuffer[0]=0.0;
}
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- get data
double hi=high[i];
double lo=low[i];
double cl=close[i];
double prev_cl=close[i-1];
//--- calculate TRH and TRL
double trh=MathMax(hi,prev_cl);
double trl=MathMin(lo,prev_cl);
//--- calculate WA/D
if(IsEqualDoubles(cl,prev_cl,_Point))
ExtWADBuffer[i]=ExtWADBuffer[i-1];
else
{
if(cl>prev_cl)
ExtWADBuffer[i]=ExtWADBuffer[i-1]+cl-trl;
else
ExtWADBuffer[i]=ExtWADBuffer[i-1]+cl-trh;
}
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool IsEqualDoubles(double d1,double d2,double epsilon)
{
if(epsilon<0.0) epsilon=-epsilon;
if(epsilon>0.1) epsilon=0.00001;
//---
double diff=d1-d2;
if(diff>epsilon || diff<-epsilon) return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
+297
View File
@@ -0,0 +1,297 @@
//+------------------------------------------------------------------+
//| ZigZag.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
//---- plot Zigzag
#property indicator_label1 "Zigzag"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 Red
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int ExtDepth=12;
input int ExtDeviation=5;
input int ExtBackstep=3;
//--- indicator buffers
double ZigzagBuffer[]; // main buffer
double HighMapBuffer[]; // highs
double LowMapBuffer[]; // lows
int level=3; // recounting depth
double deviation; // deviation in points
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ZigzagBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighMapBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,LowMapBuffer,INDICATOR_CALCULATIONS);
//--- set short name and digits
PlotIndexSetString(0,PLOT_LABEL,"ZigZag("+(string)ExtDepth+","+(string)ExtDeviation+","+(string)ExtBackstep+")");
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- to use in cycle
deviation=ExtDeviation*_Point;
//---
return(0);
}
//+------------------------------------------------------------------+
//| searching index of the highest bar |
//+------------------------------------------------------------------+
int iHighest(const double &array[],
int depth,
int startPos)
{
int index=startPos;
//--- start index validation
if(startPos<0)
{
Print("Invalid parameter in the function iHighest, startPos =",startPos);
return 0;
}
int size=ArraySize(array);
//--- depth correction if need
if(startPos-depth<0) depth=startPos;
double max=array[startPos];
//--- start searching
for(int i=startPos;i>startPos-depth;i--)
{
if(array[i]>max)
{
index=i;
max=array[i];
}
}
//--- return index of the highest bar
return(index);
}
//+------------------------------------------------------------------+
//| searching index of the lowest bar |
//+------------------------------------------------------------------+
int iLowest(const double &array[],
int depth,
int startPos)
{
int index=startPos;
//--- start index validation
if(startPos<0)
{
Print("Invalid parameter in the function iLowest, startPos =",startPos);
return 0;
}
int size=ArraySize(array);
//--- depth correction if need
if(startPos-depth<0) depth=startPos;
double min=array[startPos];
//--- start searching
for(int i=startPos;i>startPos-depth;i--)
{
if(array[i]<min)
{
index=i;
min=array[i];
}
}
//--- return index of the lowest bar
return(index);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
int i=0;
int limit=0,counterZ=0,whatlookfor=0;
int shift=0,back=0,lasthighpos=0,lastlowpos=0;
double val=0,res=0;
double curlow=0,curhigh=0,lasthigh=0,lastlow=0;
//--- auxiliary enumeration
enum looling_for
{
Pike=1, // searching for next high
Sill=-1 // searching for next low
};
//--- initializing
if(prev_calculated==0)
{
ArrayInitialize(ZigzagBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
}
//---
if(rates_total<100) return(0);
//--- set start position for calculations
if(prev_calculated==0) limit=ExtDepth;
//--- ZigZag was already counted before
if(prev_calculated>0)
{
i=rates_total-1;
//--- searching third extremum from the last uncompleted bar
while(counterZ<level && i>rates_total-100)
{
res=ZigzagBuffer[i];
if(res!=0) counterZ++;
i--;
}
i++;
limit=i;
//--- what type of exremum we are going to find
if(LowMapBuffer[i]!=0)
{
curlow=LowMapBuffer[i];
whatlookfor=Pike;
}
else
{
curhigh=HighMapBuffer[i];
whatlookfor=Sill;
}
//--- chipping
for(i=limit+1;i<rates_total && !IsStopped();i++)
{
ZigzagBuffer[i]=0.0;
LowMapBuffer[i]=0.0;
HighMapBuffer[i]=0.0;
}
}
//--- searching High and Low
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
val=low[iLowest(low,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((low[shift]-val)>deviation) val=0.0;
else
{
for(back=1;back<=ExtBackstep;back++)
{
res=LowMapBuffer[shift-back];
if((res!=0) && (res>val)) LowMapBuffer[shift-back]=0.0;
}
}
}
if(low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
//--- high
val=high[iHighest(high,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-high[shift])>deviation) val=0.0;
else
{
for(back=1;back<=ExtBackstep;back++)
{
res=HighMapBuffer[shift-back];
if((res!=0) && (res<val)) HighMapBuffer[shift-back]=0.0;
}
}
}
if(high[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
}
//--- last preparation
if(whatlookfor==0)// uncertain quantity
{
lastlow=0;
lasthigh=0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
//--- final rejection
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
res=0.0;
switch(whatlookfor)
{
case 0: // search for peak or lawn
if(lastlow==0 && lasthigh==0)
{
if(HighMapBuffer[shift]!=0)
{
lasthigh=high[shift];
lasthighpos=shift;
whatlookfor=Sill;
ZigzagBuffer[shift]=lasthigh;
res=1;
}
if(LowMapBuffer[shift]!=0)
{
lastlow=low[shift];
lastlowpos=shift;
whatlookfor=Pike;
ZigzagBuffer[shift]=lastlow;
res=1;
}
}
break;
case Pike: // search for peak
if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
{
ZigzagBuffer[lastlowpos]=0.0;
lastlowpos=shift;
lastlow=LowMapBuffer[shift];
ZigzagBuffer[shift]=lastlow;
res=1;
}
if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
lasthigh=HighMapBuffer[shift];
lasthighpos=shift;
ZigzagBuffer[shift]=lasthigh;
whatlookfor=Sill;
res=1;
}
break;
case Sill: // search for lawn
if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
{
ZigzagBuffer[lasthighpos]=0.0;
lasthighpos=shift;
lasthigh=HighMapBuffer[shift];
ZigzagBuffer[shift]=lasthigh;
}
if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
lastlow=LowMapBuffer[shift];
lastlowpos=shift;
ZigzagBuffer[shift]=lastlow;
whatlookfor=Pike;
}
break;
default: return(rates_total);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
+288
View File
@@ -0,0 +1,288 @@
//+------------------------------------------------------------------+
//| ZigzagColor.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_chart_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_ZIGZAG
#property indicator_color1 DodgerBlue,Red
//--- input parameters
input int ExtDepth=12;
input int ExtDeviation=5;
input int ExtBackstep=3;
int level=3; // recounting's depth
//--- indicator buffers
double ZigzagPeakBuffer[];
double ZigzagLawnBuffer[];
double HighMapBuffer[];
double LowMapBuffer[];
double ColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ZigzagPeakBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ZigzagLawnBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(3,HighMapBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,LowMapBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ZigZag("+(string)ExtDepth+","+(string)ExtDeviation+","+(string)ExtBackstep+")");
PlotIndexSetString(0,PLOT_LABEL,"ZigzagColor");
//--- set drawing line empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
}
//+------------------------------------------------------------------+
//| get highest value for range |
//+------------------------------------------------------------------+
double Highest(const double&array[],int range,int fromIndex)
{
double res;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res<array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| get lowest value for range |
//+------------------------------------------------------------------+
double Lowest(const double&array[],int range,int fromIndex)
{
double res;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res>array[i]) res=array[i];
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Detrended Price Oscillator |
//+------------------------------------------------------------------+
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[])
{
int i,limit=0;
//--- check for rates count
if(rates_total<100)
{
//--- clean up arrays
ArrayInitialize(ZigzagPeakBuffer,0.0);
ArrayInitialize(ZigzagLawnBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
ArrayInitialize(ColorBuffer,0.0);
//--- exit with zero result
return(0);
}
//--- preliminary calculations
int counterZ=0,whatlookfor=0;
int shift,back=0,lasthighpos=0,lastlowpos=0;
double val=0,res=0;
double curlow=0,curhigh=0,lasthigh=0,lastlow=0;
//--- set empty values
if(prev_calculated==0)
{
ArrayInitialize(ZigzagPeakBuffer,0.0);
ArrayInitialize(ZigzagLawnBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
//--- start calculation from bar number ExtDepth
limit=ExtDepth-1;
}
//---
if(prev_calculated>0)
{
i=rates_total-1;
while(counterZ<level && i>rates_total -100)
{
res=(ZigzagPeakBuffer[i]+ZigzagLawnBuffer[i]);
//---
if(res!=0) counterZ++;
i--;
}
i++;
limit=i;
//---
if(LowMapBuffer[i]!=0)
{
curlow=LowMapBuffer[i];
whatlookfor=1;
}
else
{
curhigh=HighMapBuffer[i];
whatlookfor=-1;
}
//---
for(i=limit+1;i<rates_total && !IsStopped();i++)
{
ZigzagPeakBuffer[i]=0.0;
ZigzagLawnBuffer[i]=0.0;
LowMapBuffer[i]=0.0;
HighMapBuffer[i]=0.0;
}
}
//----
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
val=Lowest(low,ExtDepth,shift);
//---
if(val==lastlow) val=0.0;
else
{
lastlow=val;
//---
if((low[shift]-val)>(ExtDeviation*_Point)) val=0.0;
else
{
//---
for(back=ExtBackstep;back>=1;back--)
{
res=LowMapBuffer[shift-back];
//---
if((res!=0) && (res>val)) LowMapBuffer[shift-back]=0.0;
}
}
}
//---
if(low[shift]==val) LowMapBuffer[shift]=val;
else
LowMapBuffer[shift]=0.0;
//--- high
val=Highest(high,ExtDepth,shift);
//---
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
//---
if((val-high[shift])>(ExtDeviation*_Point)) val=0.0;
else
{
//---
for(back=ExtBackstep;back>=1;back--)
{
res=HighMapBuffer[shift-back];
//---
if((res!=0) && (res<val)) HighMapBuffer[shift-back]=0.0;
}
}
}
//---
if(high[shift]==val) HighMapBuffer[shift]=val;
else HighMapBuffer[shift]=0.0;
}
// final cutting
if(whatlookfor==0)
{
lastlow=0;
lasthigh=0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
//----
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
res=0.0;
switch(whatlookfor)
{
// look for peak or lawn
case 0: if(lastlow==0 && lasthigh==0)
{
if(HighMapBuffer[shift]!=0)
{
lasthigh=high[shift];
lasthighpos=shift;
whatlookfor=-1;
ZigzagPeakBuffer[shift]=lasthigh;
ColorBuffer[shift]=0;
res=1;
}
if(LowMapBuffer[shift]!=0)
{
lastlow=low[shift];
lastlowpos=shift;
whatlookfor=1;
ZigzagLawnBuffer[shift]=lastlow;
ColorBuffer[shift]=1;
res=1;
}
}
break;
// look for peak
case 1: if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow &&
HighMapBuffer[shift]==0.0)
{
ZigzagLawnBuffer[lastlowpos]=0.0;
lastlowpos=shift;
lastlow=LowMapBuffer[shift];
ZigzagLawnBuffer[shift]=lastlow;
ColorBuffer[shift]=1;
res=1;
}
if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
lasthigh=HighMapBuffer[shift];
lasthighpos=shift;
ZigzagPeakBuffer[shift]=lasthigh;
ColorBuffer[shift]=0;
whatlookfor=-1;
res=1;
}
break;
// look for lawn
case -1: if(HighMapBuffer[shift]!=0.0 &&
HighMapBuffer[shift]>lasthigh &&
LowMapBuffer[shift]==0.0)
{
ZigzagPeakBuffer[lasthighpos]=0.0;
lasthighpos=shift;
lasthigh=HighMapBuffer[shift];
ZigzagPeakBuffer[shift]=lasthigh;
ColorBuffer[shift]=0;
}
if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
lastlow=LowMapBuffer[shift];
lastlowpos=shift;
ZigzagLawnBuffer[shift]=lastlow;
ColorBuffer[shift]=1;
whatlookfor=1;
}
break;
default: return(rates_total);
}
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+