Update to version 2.02
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| ADX.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, 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;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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 =rangeBarsIndicator.High[i];
|
||||
double prevHi=rangeBarsIndicator.High[i-1];
|
||||
double Lo =rangeBarsIndicator.Low[i];
|
||||
double prevLo=rangeBarsIndicator.Low[i-1];
|
||||
double prevCl=rangeBarsIndicator.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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,168 @@
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| CCI.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, 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
|
||||
input ENUM_APPLIED_PRICE InpApplyToPrice= PRICE_CLOSE; // Apply to
|
||||
//--- global variable
|
||||
int ExtCCIPeriod;
|
||||
//---- indicator buffer
|
||||
double ExtSPBuffer[];
|
||||
double ExtDBuffer[];
|
||||
double ExtMBuffer[];
|
||||
double ExtCCIBuffer[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
|
||||
//
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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[])
|
||||
{
|
||||
*/
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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,rangeBarsIndicator.Price);
|
||||
//--- calculate D
|
||||
dTmp=0.0;
|
||||
for(j=0;j<ExtCCIPeriod;j++) dTmp+=MathAbs(rangeBarsIndicator.Price[i-j]-ExtSPBuffer[i]);
|
||||
ExtDBuffer[i]=dTmp*dMul;
|
||||
//--- calculate M
|
||||
ExtMBuffer[i]=rangeBarsIndicator.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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,134 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fractals.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, 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;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
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(rangeBarsIndicator.High[i]>rangeBarsIndicator.High[i+1] && rangeBarsIndicator.High[i]>rangeBarsIndicator.High[i+2] && rangeBarsIndicator.High[i]>=rangeBarsIndicator.High[i-1] && rangeBarsIndicator.High[i]>=rangeBarsIndicator.High[i-2])
|
||||
ExtUpperBuffer[i]=rangeBarsIndicator.High[i];
|
||||
else ExtUpperBuffer[i]=EMPTY_VALUE;
|
||||
|
||||
//---- Lower Fractal
|
||||
if(rangeBarsIndicator.Low[i]<rangeBarsIndicator.Low[i+1] && rangeBarsIndicator.Low[i]<rangeBarsIndicator.Low[i+2] && rangeBarsIndicator.Low[i]<=rangeBarsIndicator.Low[i-1] && rangeBarsIndicator.Low[i]<=rangeBarsIndicator.Low[i-2])
|
||||
ExtLowerBuffer[i]=rangeBarsIndicator.Low[i];
|
||||
else ExtLowerBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,175 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Gann_Hi_Lo_Activator_SSL.mq5 |
|
||||
//| avoitenko |
|
||||
//| https://login.mql5.com/en/users/avoitenko |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright ""
|
||||
#property link "https://login.mql5.com/en/users/avoitenko"
|
||||
#property version "1.00"
|
||||
#property description "Author: Kalenzo"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
//--- output line
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrDodgerBlue, clrOrangeRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
#property indicator_label1 "GHL (13, SMMA)"
|
||||
//--- input parameters
|
||||
input uint InpPeriod=13; // Period
|
||||
input ENUM_MA_METHOD InpMethod=MODE_SMMA;// Method
|
||||
//--- buffers
|
||||
double GannBuffer[];
|
||||
double ColorBuffer[];
|
||||
double MaHighBuffer[];
|
||||
double MaLowBuffer[];
|
||||
double TrendBuffer[];
|
||||
//--- global vars
|
||||
int ma_high_handle;
|
||||
int ma_low_handle;
|
||||
int period;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- check period
|
||||
period=(int)fmax(InpPeriod,2);
|
||||
//--- set buffers
|
||||
SetIndexBuffer(0,GannBuffer);
|
||||
SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,MaHighBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,MaLowBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,TrendBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set direction
|
||||
ArraySetAsSeries(GannBuffer,true);
|
||||
ArraySetAsSeries(ColorBuffer,true);
|
||||
ArraySetAsSeries(MaHighBuffer,true);
|
||||
ArraySetAsSeries(MaLowBuffer,true);
|
||||
ArraySetAsSeries(TrendBuffer,true);
|
||||
//--- get handles
|
||||
ma_high_handle=iMA(NULL,0,period,0,InpMethod,PRICE_HIGH);
|
||||
ma_low_handle =iMA(NULL,0,period,0,InpMethod,PRICE_LOW);
|
||||
if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
|
||||
{
|
||||
Print("Unable to create handle for iMA");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
//--- set indicator properties
|
||||
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- set label
|
||||
short_name=StringFormat("GHL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- done
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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<period+1)return(0);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
ArraySetAsSeries(rangeBarsIndicator.Close,true);
|
||||
//---
|
||||
int limit;
|
||||
if(rates_total<_prev_calculated || _prev_calculated<=0)
|
||||
{
|
||||
limit=rates_total-period-1;
|
||||
ArrayInitialize(GannBuffer,EMPTY_VALUE);
|
||||
ArrayInitialize(ColorBuffer,0);
|
||||
ArrayInitialize(MaHighBuffer,0);
|
||||
ArrayInitialize(MaLowBuffer,0);
|
||||
ArrayInitialize(TrendBuffer,0);
|
||||
}
|
||||
else
|
||||
limit=rates_total-_prev_calculated;
|
||||
//--- get MA
|
||||
if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
|
||||
if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
|
||||
//--- main cycle
|
||||
for(int i=limit; i>=0 && !_StopFlag; i--)
|
||||
{
|
||||
TrendBuffer[i]=TrendBuffer[i+1];
|
||||
//---
|
||||
if(NormalizeDouble(rangeBarsIndicator.Close[i],_Digits)>NormalizeDouble(MaHighBuffer[i+1],_Digits)) TrendBuffer[i]=1;
|
||||
if(NormalizeDouble(rangeBarsIndicator.Close[i],_Digits)<NormalizeDouble(MaLowBuffer[i+1],_Digits)) TrendBuffer[i]=-1;
|
||||
//---
|
||||
if(TrendBuffer[i]<0)
|
||||
{
|
||||
GannBuffer[i]=MaHighBuffer[i];
|
||||
ColorBuffer[i]=1;
|
||||
}
|
||||
//---
|
||||
if(TrendBuffer[i]>0)
|
||||
{
|
||||
GannBuffer[i]=MaLowBuffer[i];
|
||||
ColorBuffer[i]=0;
|
||||
}
|
||||
}
|
||||
//--- done
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,137 @@
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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;
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- preliminary calculations
|
||||
if(_prev_calculated==0)
|
||||
{
|
||||
//--- set first candle
|
||||
ExtLBuffer[0]=rangeBarsIndicator.Low[0];
|
||||
ExtHBuffer[0]=rangeBarsIndicator.High[0];
|
||||
ExtOBuffer[0]=rangeBarsIndicator.Open[0];
|
||||
ExtCBuffer[0]=rangeBarsIndicator.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=(rangeBarsIndicator.Open[i]+rangeBarsIndicator.High[i]+rangeBarsIndicator.Low[i]+rangeBarsIndicator.Close[i])/4;
|
||||
double haHigh=MathMax(rangeBarsIndicator.High[i],MathMax(haOpen,haClose));
|
||||
double haLow=MathMin(rangeBarsIndicator.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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,179 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int limit;
|
||||
//---
|
||||
if(_prev_calculated==0) limit=0;
|
||||
else limit=_prev_calculated-1;
|
||||
//---
|
||||
for(int i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtChikouBuffer[i]=rangeBarsIndicator.Close[i];
|
||||
//--- tenkan sen
|
||||
double _high=Highest(rangeBarsIndicator.High,InpTenkan,i);
|
||||
double _low=Lowest(rangeBarsIndicator.Low,InpTenkan,i);
|
||||
ExtTenkanBuffer[i]=(_high+_low)/2.0;
|
||||
//--- kijun sen
|
||||
_high=Highest(rangeBarsIndicator.High,InpKijun,i);
|
||||
_low=Lowest(rangeBarsIndicator.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(rangeBarsIndicator.High,InpSenkou,i);
|
||||
_low=Lowest(rangeBarsIndicator.Low,InpSenkou,i);
|
||||
ExtSpanBBuffer[i]=(_high+_low)/2.0;
|
||||
}
|
||||
//--- done
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,257 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE;
|
||||
|
||||
//--- indicator buffers
|
||||
double ExtLineBuffer[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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);
|
||||
|
||||
//
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//---- initialization done
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
/*int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{*/
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _begin = 0;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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,rangeBarsIndicator.Price); break;
|
||||
case MODE_LWMA: CalculateLWMA(rates_total,_prev_calculated,_begin,rangeBarsIndicator.Price); break;
|
||||
case MODE_SMMA: CalculateSmoothedMA(rates_total,_prev_calculated,_begin,rangeBarsIndicator.Price); break;
|
||||
case MODE_SMA: CalculateSimpleMA(rates_total,_prev_calculated,_begin,rangeBarsIndicator.Price); break;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -36,17 +36,17 @@ double ExtSlowMaBuffer[];
|
||||
double ExtMacdBuffer[];
|
||||
|
||||
//
|
||||
// Initialize MedianRenko indicator for data processing
|
||||
// according to settings of the MedianRenko indicator already on chart
|
||||
//
|
||||
//
|
||||
|
||||
#include <RangeBarIndicator.mqh>
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -84,7 +84,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(rangeBarsIndicator.GetPrevCalculated());
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Momentum.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, 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
|
||||
input ENUM_APPLIED_PRICE InpApplyToPrice= PRICE_CLOSE; // Apply to
|
||||
//---- indicator buffers
|
||||
double ExtMomentumBuffer[];
|
||||
//--- global variable
|
||||
int ExtMomentumPeriod;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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[])
|
||||
{
|
||||
*/
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
|
||||
static int begin = 0;
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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++)
|
||||
{
|
||||
if(rangeBarsIndicator.Price[i-ExtMomentumPeriod] > 0)
|
||||
ExtMomentumBuffer[i]=rangeBarsIndicator.Price[i]*100/rangeBarsIndicator.Price[i-ExtMomentumPeriod];
|
||||
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,248 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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]=rangeBarsIndicator.High[0];
|
||||
ExtLastRevPos=0;
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[1]=GetHigh(pos,ExtLastRevPos,rangeBarsIndicator.High);
|
||||
ExtEPBuffer[0]=rangeBarsIndicator.Low[pos];
|
||||
ExtEPBuffer[1]=rangeBarsIndicator.Low[pos];
|
||||
}
|
||||
//---main cycle
|
||||
for(int i=pos;i<rates_total-1 && !IsStopped();i++)
|
||||
{
|
||||
//--- check for reverse
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
if(ExtSARBuffer[i]>rangeBarsIndicator.Low[i])
|
||||
{
|
||||
//--- switch to SHORT
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[i]=GetHigh(i,ExtLastRevPos,rangeBarsIndicator.High);
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.Low[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ExtSARBuffer[i]<rangeBarsIndicator.High[i])
|
||||
{
|
||||
//--- switch to LONG
|
||||
ExtDirectionLong=true;
|
||||
ExtSARBuffer[i]=GetLow(i,ExtLastRevPos,rangeBarsIndicator.Low);
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.High[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
}
|
||||
//--- continue calculations
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
//--- check for new High
|
||||
if(rangeBarsIndicator.High[i]>ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.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]>rangeBarsIndicator.Low[i] || ExtSARBuffer[i+1]>rangeBarsIndicator.Low[i-1])
|
||||
ExtSARBuffer[i+1]=MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Low[i-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- check for new Low
|
||||
if(rangeBarsIndicator.Low[i]<ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.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]<rangeBarsIndicator.High[i] || ExtSARBuffer[i+1]<rangeBarsIndicator.High[i-1])
|
||||
ExtSARBuffer[i+1]=MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,136 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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
|
||||
|
||||
//
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(PRICE_CLOSE);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Rate of Change |
|
||||
//+------------------------------------------------------------------+
|
||||
//int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- 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(rangeBarsIndicator.Price[i]==0.0)
|
||||
ExtRocBuffer[i]=0.0;
|
||||
else
|
||||
ExtRocBuffer[i]=(rangeBarsIndicator.Price[i]-rangeBarsIndicator.Price[i-ExtRocPeriod])/rangeBarsIndicator.Price[i]*100;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -26,14 +26,12 @@ double ExtPosBuffer[];
|
||||
double ExtNegBuffer[];
|
||||
|
||||
//
|
||||
// Initialize MedianRenko indicator for data processing
|
||||
// according to settings of the MedianRenko indicator already on chart
|
||||
//
|
||||
//
|
||||
|
||||
#include <RangeBarIndicator.mqh>
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -79,26 +77,36 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
|
||||
//
|
||||
// Precoess data through MedianRenko indicator
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(rates_total);
|
||||
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// medianRenkoIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
// medianRenkoIndicator.Open[] should be used instead of open[]
|
||||
// medianRenkoIndicator.Low[] should be used instead of low[]
|
||||
// medianRenkoIndicator.High[] should be used instead of high[]
|
||||
// medianRenkoIndicator.Close[] should be used instead of close[]
|
||||
// if applied_price is used
|
||||
// medianRenkoIndicator.Price[] should be used instead of price[]
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
+6
-17
@@ -26,14 +26,12 @@ double ExtHighesBuffer[];
|
||||
double ExtLowesBuffer[];
|
||||
|
||||
//
|
||||
// Initialize MedianRenko indicator for data processing
|
||||
// according to settings of the MedianRenko indicator already on chart
|
||||
//
|
||||
//
|
||||
|
||||
#include <RangeBarIndicator.mqh>
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -79,23 +77,14 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// Precoess data through MedianRenko indicator
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(rates_total);
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// medianRenkoIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
// medianRenkoIndicator.Open[] should be used instead of open[]
|
||||
// medianRenkoIndicator.Low[] should be used instead of low[]
|
||||
// medianRenkoIndicator.High[] should be used instead of high[]
|
||||
// medianRenkoIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
//------------------------------------------------------------------
|
||||
#property copyright "mladen"
|
||||
#property link "www.forex-tsd.com"
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 4
|
||||
|
||||
#property indicator_label1 "ADX trend"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 C'200,255,180',clrMistyRose
|
||||
#property indicator_label2 "ADX"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrLimeGreen
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
#property indicator_label3 "ADXR"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGold
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
#property indicator_label4 "Level"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrSilver
|
||||
#property indicator_style4 STYLE_DOT
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
enum enVolume
|
||||
{
|
||||
vol_noVolume, // do not use volume
|
||||
vol_ticks, // use ticks
|
||||
vol_real // use real volume
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
input int AdxPeriod = 14; // ADX (DMI) period
|
||||
input double AdxLevel = 20; // ADX level
|
||||
input bool ShowADX = true; // ADX visible
|
||||
input bool ShowADXR = false; // ADXR visible
|
||||
input enVolume VolumeType = vol_ticks; // Volume to use
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double DIp[];
|
||||
double DIm[];
|
||||
double ADX[];
|
||||
double ADXR[];
|
||||
double Level[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,DIp,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,DIm,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ADX,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ADXR,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,Level,INDICATOR_DATA);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
IndicatorSetString(INDICATOR_SHORTNAME," VEMA Wilder's DMI ("+string(AdxPeriod)+")");
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
double averages[][9];
|
||||
#define _Vol 0
|
||||
#define _DIp 1
|
||||
#define _DIm 2
|
||||
#define _TR 3
|
||||
#define _Adx 4
|
||||
#define _DIpa 5
|
||||
#define _DIma 6
|
||||
#define _TRa 7
|
||||
#define _Adxa 8
|
||||
|
||||
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[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (ArrayRange(averages,0)!=rates_total) ArrayResize(averages,rates_total);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double sf = 1.0/(double)AdxPeriod;
|
||||
for (int i=(int)MathMax(_prev_calculated-1,1); i<rates_total; i++)
|
||||
{
|
||||
double currTR = MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.Close[i-1])-MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Close[i-1]);
|
||||
double DeltaHi = rangeBarsIndicator.High[i] - rangeBarsIndicator.High[i-1];
|
||||
double DeltaLo = rangeBarsIndicator.Low[i-1] - rangeBarsIndicator.Low[i];
|
||||
double plusDM = 0.00;
|
||||
double minusDM = 0.00;
|
||||
double vol;
|
||||
switch(VolumeType)
|
||||
{
|
||||
case vol_ticks: vol = (double)rangeBarsIndicator.Tick_volume[i]; break;
|
||||
case vol_real: vol = (double)rangeBarsIndicator.Real_volume[i]; break;
|
||||
default: vol = 1;
|
||||
}
|
||||
if ((DeltaHi > DeltaLo) && (DeltaHi > 0)) plusDM = DeltaHi;
|
||||
if ((DeltaLo > DeltaHi) && (DeltaLo > 0)) minusDM = DeltaLo;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
averages[i][_Vol] = averages[i-1][_Vol] + sf*(vol - averages[i-1][_Vol]);
|
||||
averages[i][_DIp] = averages[i-1][_DIp] + sf*(vol*plusDM - averages[i-1][_DIp]);
|
||||
averages[i][_DIm] = averages[i-1][_DIm] + sf*(vol*minusDM - averages[i-1][_DIm]);
|
||||
averages[i][_TR] = averages[i-1][_TR] + sf*(vol*currTR - averages[i-1][_TR]);
|
||||
averages[i][_DIpa] = averages[i][_DIp]/MathMax(averages[i][_Vol],1);
|
||||
averages[i][_DIma] = averages[i][_DIm]/MathMax(averages[i][_Vol],1);
|
||||
averages[i][_TRa] = averages[i][_TR] /MathMax(averages[i][_Vol],1);
|
||||
Level[i] = AdxLevel;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
DIp[i] = 0.00;
|
||||
DIm[i] = 0.00;
|
||||
ADX[i] = EMPTY_VALUE;
|
||||
ADXR[i] = EMPTY_VALUE;
|
||||
if (averages[i][_TRa] > 0)
|
||||
{
|
||||
DIp[i] = 100.00 * averages[i][_DIpa]/averages[i][_TRa];
|
||||
DIm[i] = 100.00 * averages[i][_DIma]/averages[i][_TRa];
|
||||
}
|
||||
|
||||
if(ShowADX)
|
||||
{
|
||||
double DX;
|
||||
if((DIp[i] + DIm[i])>0)
|
||||
DX = 100*MathAbs(DIp[i] - DIm[i])/(DIp[i] + DIm[i]);
|
||||
else DX = 0.00;
|
||||
averages[i][_Adx] = averages[i-1][_Adx]+ sf*(vol*DX - averages[i-1][_Adx]);
|
||||
averages[i][_Adxa] = averages[i][_Adx]/MathMax(averages[i][_Vol],1);
|
||||
ADX[i] = averages[i][_Adxa];
|
||||
if(ShowADXR && i>=AdxPeriod)
|
||||
ADXR[i] = 0.5*(ADX[i] + ADX[i-AdxPeriod]);
|
||||
}
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| VWAP_Lite.mq5 |
|
||||
//| Copyright 2016, SOL Digital Consultoria LTDA |
|
||||
//| http://www.soldigitalconsultoria.com.br |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2016, SOL Digital Consultoria LTDA"
|
||||
#property link "http://www.soldigitalconsultoria.com.br"
|
||||
#property version "1.49"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
#property indicator_label1 "VWAP Daily"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_DASH
|
||||
#property indicator_width1 2
|
||||
|
||||
#property indicator_label2 "VWAP Weekly"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_style2 STYLE_DASH
|
||||
#property indicator_width2 2
|
||||
|
||||
#property indicator_label3 "VWAP Monthly"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGreen
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 2
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
enum DATE_TYPE
|
||||
{
|
||||
DAILY,
|
||||
WEEKLY,
|
||||
MONTHLY
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
enum PRICE_TYPE
|
||||
{
|
||||
OPEN,
|
||||
CLOSE,
|
||||
HIGH,
|
||||
LOW,
|
||||
OPEN_CLOSE,
|
||||
HIGH_LOW,
|
||||
CLOSE_HIGH_LOW,
|
||||
OPEN_CLOSE_HIGH_LOW
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
#define VWAP_Daily "cc__VWAP_Daily"
|
||||
#define VWAP_Weekly "cc__VWAP_Weekly"
|
||||
#define VWAP_Monthly "cc__VWAP_Monthly"
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
datetime CreateDateTime(DATE_TYPE nReturnType=DAILY,datetime dtDay=D'2000.01.01 00:00:00',int pHour=0,int pMinute=0,int pSecond=0)
|
||||
{
|
||||
datetime dtReturnDate;
|
||||
MqlDateTime timeStruct;
|
||||
|
||||
TimeToStruct(dtDay,timeStruct);
|
||||
timeStruct.hour = pHour;
|
||||
timeStruct.min = pMinute;
|
||||
timeStruct.sec = pSecond;
|
||||
dtReturnDate=(StructToTime(timeStruct));
|
||||
|
||||
if(nReturnType==WEEKLY)
|
||||
{
|
||||
while(timeStruct.day_of_week!=0)
|
||||
{
|
||||
dtReturnDate=(dtReturnDate-86400);
|
||||
TimeToStruct(dtReturnDate,timeStruct);
|
||||
}
|
||||
}
|
||||
|
||||
if(nReturnType==MONTHLY)
|
||||
{
|
||||
timeStruct.day=1;
|
||||
dtReturnDate=(StructToTime(timeStruct));
|
||||
}
|
||||
|
||||
return dtReturnDate;
|
||||
}
|
||||
|
||||
sinput string Indicator_Name = "Volume Weighted Average Price (VWAP)";
|
||||
input PRICE_TYPE Price_Type = CLOSE_HIGH_LOW;
|
||||
input bool Calc_Every_Tick = false;
|
||||
input bool Enable_Daily = true;
|
||||
input bool Show_Daily_Value = true;
|
||||
input bool Enable_Weekly = false;
|
||||
input bool Show_Weekly_Value = false;
|
||||
input bool Enable_Monthly = false;
|
||||
input bool Show_Monthly_Value = false;
|
||||
|
||||
double VWAP_Buffer_Daily[],VWAP_Buffer_Weekly[],VWAP_Buffer_Monthly[];
|
||||
double nPriceArr[],nTotalTPV[],nTotalVol[];
|
||||
double nSumDailyTPV = 0, nSumWeeklyTPV = 0, nSumMonthlyTPV = 0;
|
||||
double nSumDailyVol = 0, nSumWeeklyVol = 0, nSumMonthlyVol = 0;
|
||||
int nIdxDaily=0,nIdxWeekly=0,nIdxMonthly=0,nIdx=0;
|
||||
bool bIsFirstRun=true;
|
||||
string sDailyStr = "", sWeeklyStr = "", sMonthlyStr = "";
|
||||
datetime dtLastDay = CreateDateTime(DAILY), dtLastWeek = CreateDateTime(WEEKLY), dtLastMonth = CreateDateTime(MONTHLY);
|
||||
ENUM_TIMEFRAMES LastTimePeriod=PERIOD_MN1;
|
||||
int nStringYDistance=50;
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
|
||||
SetIndexBuffer(0,VWAP_Buffer_Daily,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,VWAP_Buffer_Weekly,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,VWAP_Buffer_Monthly,INDICATOR_DATA);
|
||||
|
||||
if(Show_Daily_Value)
|
||||
{
|
||||
ObjectCreate(0,VWAP_Daily,OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,VWAP_Daily,OBJPROP_CORNER,CORNER_LEFT_LOWER);
|
||||
ObjectSetInteger(0,VWAP_Daily,OBJPROP_XDISTANCE,10);//180);
|
||||
ObjectSetInteger(0,VWAP_Daily,OBJPROP_YDISTANCE,nStringYDistance);
|
||||
ObjectSetInteger(0,VWAP_Daily,OBJPROP_COLOR,indicator_color1);
|
||||
ObjectSetInteger(0,VWAP_Daily,OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,VWAP_Daily,OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,VWAP_Daily,OBJPROP_TEXT," ");
|
||||
nStringYDistance=nStringYDistance+20;
|
||||
}
|
||||
|
||||
if(Show_Weekly_Value)
|
||||
{
|
||||
ObjectCreate(0,VWAP_Weekly,OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,VWAP_Weekly,OBJPROP_CORNER,CORNER_LEFT_LOWER);
|
||||
ObjectSetInteger(0,VWAP_Weekly,OBJPROP_XDISTANCE,10);//180);
|
||||
ObjectSetInteger(0,VWAP_Weekly,OBJPROP_YDISTANCE,nStringYDistance);
|
||||
ObjectSetInteger(0,VWAP_Weekly,OBJPROP_COLOR,indicator_color2);
|
||||
ObjectSetInteger(0,VWAP_Weekly,OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,VWAP_Weekly,OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,VWAP_Weekly,OBJPROP_TEXT," ");
|
||||
nStringYDistance=nStringYDistance+20;
|
||||
}
|
||||
|
||||
if(Show_Monthly_Value)
|
||||
{
|
||||
ObjectCreate(0,VWAP_Monthly,OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,VWAP_Monthly,OBJPROP_CORNER,CORNER_LEFT_LOWER);
|
||||
ObjectSetInteger(0,VWAP_Monthly,OBJPROP_XDISTANCE,10);//180);
|
||||
ObjectSetInteger(0,VWAP_Monthly,OBJPROP_YDISTANCE,nStringYDistance);
|
||||
ObjectSetInteger(0,VWAP_Monthly,OBJPROP_COLOR,indicator_color3);
|
||||
ObjectSetInteger(0,VWAP_Monthly,OBJPROP_FONTSIZE,7);
|
||||
ObjectSetString(0,VWAP_Monthly,OBJPROP_FONT,"Verdana");
|
||||
ObjectSetString(0,VWAP_Monthly,OBJPROP_TEXT," ");
|
||||
}
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
rangeBarsIndicator.SetGetTimeFlag();
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int pReason)
|
||||
{
|
||||
if(Show_Daily_Value) ObjectDelete(0,VWAP_Daily);
|
||||
if(Show_Weekly_Value) ObjectDelete(0,VWAP_Weekly);
|
||||
if(Show_Monthly_Value) ObjectDelete(0,VWAP_Monthly);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if(PERIOD_CURRENT!=LastTimePeriod)
|
||||
{
|
||||
bIsFirstRun=true;
|
||||
LastTimePeriod=PERIOD_CURRENT;
|
||||
}
|
||||
|
||||
if(rates_total>_prev_calculated || bIsFirstRun || Calc_Every_Tick || (_prev_calculated == 0) || rangeBarsIndicator.IsNewBar)
|
||||
{
|
||||
nIdxDaily = 0;
|
||||
nIdxWeekly = 0;
|
||||
nIdxMonthly = 0;
|
||||
|
||||
ArrayResize(nPriceArr,rates_total);
|
||||
ArrayResize(nTotalTPV,rates_total);
|
||||
ArrayResize(nTotalVol,rates_total);
|
||||
|
||||
if(Enable_Daily) {nIdx = nIdxDaily; nSumDailyTPV = 0; nSumDailyVol = 0;}
|
||||
if(Enable_Weekly) {nIdx = nIdxWeekly; nSumWeeklyTPV = 0; nSumWeeklyVol = 0;}
|
||||
if(Enable_Monthly) {nIdx = nIdxMonthly; nSumMonthlyTPV = 0; nSumMonthlyVol = 0;}
|
||||
|
||||
for(; nIdx<rates_total; nIdx++)
|
||||
{
|
||||
VWAP_Buffer_Daily[nIdx]=EMPTY_VALUE;
|
||||
VWAP_Buffer_Weekly[nIdx]=EMPTY_VALUE;
|
||||
VWAP_Buffer_Monthly[nIdx]=EMPTY_VALUE;
|
||||
|
||||
if(rangeBarsIndicator.Time[nIdx] < 86400)
|
||||
continue;
|
||||
|
||||
if(CreateDateTime(DAILY,rangeBarsIndicator.Time[nIdx])!=dtLastDay)
|
||||
{
|
||||
nIdxDaily=nIdx;
|
||||
nSumDailyTPV = 0;
|
||||
nSumDailyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(WEEKLY,rangeBarsIndicator.Time[nIdx])!=dtLastWeek)
|
||||
{
|
||||
nIdxWeekly=nIdx;
|
||||
nSumWeeklyTPV = 0;
|
||||
nSumWeeklyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(MONTHLY,rangeBarsIndicator.Time[nIdx])!=dtLastMonth)
|
||||
{
|
||||
nIdxMonthly=nIdx;
|
||||
nSumMonthlyTPV = 0;
|
||||
nSumMonthlyVol = 0;
|
||||
}
|
||||
|
||||
nPriceArr[nIdx] = 0;
|
||||
nTotalTPV[nIdx] = 0;
|
||||
nTotalVol[nIdx] = 0;
|
||||
|
||||
switch(Price_Type)
|
||||
{
|
||||
case OPEN:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Open[nIdx];
|
||||
break;
|
||||
case CLOSE:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Close[nIdx];
|
||||
break;
|
||||
case HIGH:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.High[nIdx];
|
||||
break;
|
||||
case LOW:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Low[nIdx];
|
||||
break;
|
||||
case HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/2;
|
||||
break;
|
||||
case OPEN_CLOSE:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Open[nIdx]+rangeBarsIndicator.Close[nIdx])/2;
|
||||
break;
|
||||
case CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/3;
|
||||
break;
|
||||
case OPEN_CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Open[nIdx]+rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/4;
|
||||
break;
|
||||
default:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/3;
|
||||
break;
|
||||
}
|
||||
|
||||
if((rangeBarsIndicator.Tick_volume[nIdx] > 0) && (rangeBarsIndicator.Real_volume[nIdx] == 0))
|
||||
{
|
||||
// Print("tick vol = "+rangeBarsIndicator.Tick_volume[nIdx]);
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * rangeBarsIndicator.Tick_volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)rangeBarsIndicator.Tick_volume[nIdx];
|
||||
}
|
||||
else if(rangeBarsIndicator.Real_volume[nIdx] && rangeBarsIndicator.Tick_volume[nIdx] )
|
||||
{
|
||||
// Print("real vol = "+rangeBarsIndicator.Real_volume[nIdx]);
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * rangeBarsIndicator.Real_volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)rangeBarsIndicator.Real_volume[nIdx];
|
||||
}
|
||||
|
||||
if(Enable_Daily && (nIdx>=nIdxDaily))
|
||||
{
|
||||
nSumDailyTPV += nTotalTPV[nIdx];
|
||||
nSumDailyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumDailyVol)
|
||||
VWAP_Buffer_Daily[nIdx]=(nSumDailyTPV/nSumDailyVol);
|
||||
|
||||
if((sDailyStr!="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits)) && Show_Daily_Value)
|
||||
{
|
||||
sDailyStr="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits);
|
||||
ObjectSetString(0,VWAP_Daily,OBJPROP_TEXT,sDailyStr);
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Weekly && (nIdx>=nIdxWeekly))
|
||||
{
|
||||
nSumWeeklyTPV += nTotalTPV[nIdx];
|
||||
nSumWeeklyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumWeeklyVol)
|
||||
VWAP_Buffer_Weekly[nIdx]=(nSumWeeklyTPV/nSumWeeklyVol);
|
||||
|
||||
if((sWeeklyStr!="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits)) && Show_Weekly_Value)
|
||||
{
|
||||
sWeeklyStr="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits);
|
||||
ObjectSetString(0,VWAP_Weekly,OBJPROP_TEXT,sWeeklyStr);
|
||||
}
|
||||
}
|
||||
|
||||
if(Enable_Monthly && (nIdx>=nIdxMonthly))
|
||||
{
|
||||
nSumMonthlyTPV += nTotalTPV[nIdx];
|
||||
nSumMonthlyVol += nTotalVol[nIdx];
|
||||
|
||||
if(nSumMonthlyVol)
|
||||
VWAP_Buffer_Monthly[nIdx]=(nSumMonthlyTPV/nSumMonthlyVol);
|
||||
|
||||
if((sMonthlyStr!="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits)) && Show_Monthly_Value)
|
||||
{
|
||||
sMonthlyStr="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits);
|
||||
ObjectSetString(0,VWAP_Monthly,OBJPROP_TEXT,sMonthlyStr);
|
||||
}
|
||||
}
|
||||
|
||||
dtLastDay=CreateDateTime(DAILY,rangeBarsIndicator.Time[nIdx]);
|
||||
dtLastWeek=CreateDateTime(WEEKLY,rangeBarsIndicator.Time[nIdx]);
|
||||
dtLastMonth=CreateDateTime(MONTHLY,rangeBarsIndicator.Time[nIdx]);
|
||||
}
|
||||
|
||||
bIsFirstRun=false;
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,322 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ZigZag.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, 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
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
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=rangeBarsIndicator.Low[iLowest(rangeBarsIndicator.Low,ExtDepth,shift)];
|
||||
if(val==lastlow) val=0.0;
|
||||
else
|
||||
{
|
||||
lastlow=val;
|
||||
if((rangeBarsIndicator.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(rangeBarsIndicator.Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
|
||||
//--- high
|
||||
val=rangeBarsIndicator.High[iHighest(rangeBarsIndicator.High,ExtDepth,shift)];
|
||||
if(val==lasthigh) val=0.0;
|
||||
else
|
||||
{
|
||||
lasthigh=val;
|
||||
if((val-rangeBarsIndicator.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(rangeBarsIndicator.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=rangeBarsIndicator.High[shift];
|
||||
lasthighpos=shift;
|
||||
whatlookfor=Sill;
|
||||
ZigzagBuffer[shift]=lasthigh;
|
||||
res=1;
|
||||
}
|
||||
if(LowMapBuffer[shift]!=0)
|
||||
{
|
||||
lastlow=rangeBarsIndicator.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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,247 @@
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| DT oscillator.mq5 |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "www.forex-tsd.com"
|
||||
#property link "www.forex-tsd.com"
|
||||
#property version "1.00"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 3
|
||||
#property indicator_level1 70
|
||||
#property indicator_level2 30
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 PowderBlue,MistyRose
|
||||
#property indicator_label1 "DT oscillator filling"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 DeepSkyBlue
|
||||
#property indicator_width2 2
|
||||
#property indicator_label2 "DT oscillator"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 PaleVioletRed
|
||||
#property indicator_width3 1
|
||||
#property indicator_label3 "DT oscillator signal"
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
input int RsiPeriod = 13; // Rsi period
|
||||
input int StochPeriod = 8; // Stochastic period
|
||||
input int SlowingPeriod = 5; // Slowing
|
||||
input int SignalPeriod = 3; // Signal period
|
||||
input bool TapeVisible = true; // Tape visibility
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double dtosc[];
|
||||
double dtoss[];
|
||||
double dtosf1[];
|
||||
double dtosf2[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer( 0,dtosf1,INDICATOR_DATA);
|
||||
SetIndexBuffer( 1,dtosf2,INDICATOR_DATA);
|
||||
SetIndexBuffer( 2,dtosc ,INDICATOR_DATA);
|
||||
SetIndexBuffer( 3,dtoss ,INDICATOR_DATA);
|
||||
return(0);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double rsibuf[];
|
||||
double stobuf[];
|
||||
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (ArraySize(rsibuf)!=rates_total) ArrayResize(rsibuf,rates_total);
|
||||
if (ArraySize(stobuf)!=rates_total) ArrayResize(stobuf,rates_total);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
for (int i=(int)MathMax(_prev_calculated-1,0); i<rates_total; i++)
|
||||
{
|
||||
rsibuf[i] = iRsi(rangeBarsIndicator.Close[i],RsiPeriod,i,rates_total);
|
||||
|
||||
double min = rsibuf[i];
|
||||
double max = rsibuf[i];
|
||||
for (int k=1; k<StochPeriod && (i-k)>=0; k++)
|
||||
{
|
||||
min = MathMin(rsibuf[i-k],min);
|
||||
max = MathMax(rsibuf[i-k],max);
|
||||
}
|
||||
if (max!=min)
|
||||
stobuf[i] = 100*(rsibuf[i]-min)/(max-min);
|
||||
else stobuf[i] = 0;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
dtosc[i] = 0; for (int k=0; k<SlowingPeriod && (i-k)>=0; k++) dtosc[i] += stobuf[i-k]; dtosc[i] /= SlowingPeriod;
|
||||
dtoss[i] = 0; for (int k=0; k<SignalPeriod && (i-k)>=0; k++) dtoss[i] += dtosc[i-k]; dtoss[i] /= SignalPeriod;
|
||||
if (TapeVisible)
|
||||
{ dtosf1[i] = dtosc[i]; dtosf2[i] = dtoss[i]; }
|
||||
else { dtosf1[i] = EMPTY_VALUE; dtosf2[i] = EMPTY_VALUE; }
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double rsiWork[][3];
|
||||
#define _price 0
|
||||
#define _chgAvg 1
|
||||
#define _totChg 2
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double iRsi(double price, double period, int i, int bars)
|
||||
{
|
||||
if (ArrayRange(rsiWork,0)!=bars) ArrayResize(rsiWork,bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
rsiWork[i][_price] = price;
|
||||
if (i==0)
|
||||
{
|
||||
rsiWork[i][_chgAvg] = 0;
|
||||
rsiWork[i][_totChg] = 0;
|
||||
return(50);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double sf = 1.0 / period;
|
||||
double change = rsiWork[i][_price]-rsiWork[i-1][_price];
|
||||
|
||||
rsiWork[i][_chgAvg] = rsiWork[i-1][_chgAvg] + sf*( change -rsiWork[i-1][_chgAvg]);
|
||||
rsiWork[i][_totChg] = rsiWork[i-1][_totChg] + sf*(MathAbs(change)-rsiWork[i-1][_totChg]);
|
||||
|
||||
double changeRatio = (rsiWork[i][_totChg]!=0 ? rsiWork[i][_chgAvg]/rsiWork[i][_totChg] : 0 );
|
||||
return(50.0*(changeRatio+1.0));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,139 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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);
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
//----
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- starting work
|
||||
int start=_prev_calculated-1;
|
||||
//--- correct position
|
||||
if(start<1) start=1;
|
||||
//--- main cycle
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateVolume(start,rates_total,rangeBarsIndicator.Tick_volume);
|
||||
else
|
||||
CalculateVolume(start,rates_total,rangeBarsIndicator.Real_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;
|
||||
}
|
||||
//---
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user