Updated for RangeBars ver. 3.00
This commit is contained in:
@@ -45,7 +45,7 @@ int ExtADXPeriod;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -99,39 +99,15 @@ int OnCalculate(const int rates_total,
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- checking for bars count
|
||||
@@ -151,11 +127,11 @@ int OnCalculate(const int rates_total,
|
||||
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];
|
||||
double Hi =customChartIndicator.High[i];
|
||||
double prevHi=customChartIndicator.High[i-1];
|
||||
double Lo =customChartIndicator.Low[i];
|
||||
double prevLo=customChartIndicator.Low[i-1];
|
||||
double prevCl=customChartIndicator.Close[i-1];
|
||||
//--- fill main positive and main negative buffers
|
||||
double dTmpP=Hi-prevHi;
|
||||
double dTmpN=prevLo-Lo;
|
||||
|
||||
@@ -26,7 +26,7 @@ int ExtPeriodATR;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -72,39 +72,15 @@ int OnCalculate(const int rates_total,
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int i,limit;
|
||||
@@ -118,7 +94,7 @@ int OnCalculate(const int rates_total,
|
||||
ExtATRBuffer[0]=0.0;
|
||||
//--- filling out the array of True Range values for each period
|
||||
for(i=1;i<rates_total && !IsStopped();i++)
|
||||
ExtTRBuffer[i]=MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.Close[i-1])-MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Close[i-1]);
|
||||
ExtTRBuffer[i]=MathMax(customChartIndicator.High[i],customChartIndicator.Close[i-1])-MathMin(customChartIndicator.Low[i],customChartIndicator.Close[i-1]);
|
||||
//--- first AtrPeriod values of the indicator are not calculated
|
||||
double firstValue=0.0;
|
||||
for(i=1;i<=ExtPeriodATR;i++)
|
||||
@@ -135,7 +111,7 @@ int OnCalculate(const int rates_total,
|
||||
//--- the main loop of calculations
|
||||
for(i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtTRBuffer[i]=MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.Close[i-1])-MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Close[i-1]);
|
||||
ExtTRBuffer[i]=MathMax(customChartIndicator.High[i],customChartIndicator.Close[i-1])-MathMin(customChartIndicator.Low[i],customChartIndicator.Close[i-1]);
|
||||
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
|
||||
Binary file not shown.
@@ -19,18 +19,15 @@ double ExtAOBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtFastBuffer[];
|
||||
double ExtSlowBuffer[];
|
||||
//--- handles for MAs
|
||||
int ExtFastSMAHandle;
|
||||
int ExtSlowSMAHandle;
|
||||
//--- bars minimum for calculation
|
||||
#define DATA_LIMIT 33
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
#include <MovingAverages.mqh>
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -54,11 +51,8 @@ void OnInit()
|
||||
//--- get handles
|
||||
//ExtFastSMAHandle=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN);
|
||||
//ExtSlowSMAHandle=iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN);
|
||||
// renko mod
|
||||
// ExtFastSMAHandle=iCustom(Symbol(),_Period,"RangeBars\\Indicators\\RangeBars_MA",5,0,MODE_SMA,PRICE_MEDIAN,true);
|
||||
// ExtSlowSMAHandle=iCustom(Symbol(),_Period,"RangeBars\\Indicators\\RangeBars_MA",34,0,MODE_SMA,PRICE_MEDIAN,true);
|
||||
ExtFastSMAHandle=iCustom(Symbol(),_Period,"RangeBars\\RangeBars_MA",5,0,MODE_SMA,PRICE_MEDIAN,true);
|
||||
ExtSlowSMAHandle=iCustom(Symbol(),_Period,"RangeBars\\RangeBars_MA",34,0,MODE_SMA,PRICE_MEDIAN,true);
|
||||
// -- Set applied price to MEDIAN as required by AO indicator
|
||||
customChartIndicator.SetUseAppliedPriceFlag(PRICE_MEDIAN);
|
||||
//---- initialization done
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -80,48 +74,21 @@ int OnCalculate(const int rates_total,
|
||||
if(rates_total<=DATA_LIMIT)
|
||||
return(0);// not enough bars for calculation
|
||||
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- renko mod
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(_prev_calculated>rates_total || _prev_calculated<0) to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(_prev_calculated>0) to_copy++;
|
||||
}
|
||||
//--- get FastSMA buffer
|
||||
//--- get Fast MA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
SimpleMAOnBuffer(rates_total,_prev_calculated,0,5,customChartIndicator.Price,ExtFastBuffer);
|
||||
//--- get Slow MA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast SMA is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
SimpleMAOnBuffer(rates_total,_prev_calculated,0,35,customChartIndicator.Price,ExtSlowBuffer);
|
||||
|
||||
//--- first calculation or number of bars was changed
|
||||
int i,limit;
|
||||
if(_prev_calculated<=DATA_LIMIT)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -34,7 +34,7 @@ double ExtCCIBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -50,7 +50,7 @@ void OnInit()
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
customChartIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
|
||||
//
|
||||
//
|
||||
@@ -100,33 +100,36 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
// customChartIndicator.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[]
|
||||
// customChartIndicator.Open[] should be used instead of open[]
|
||||
// customChartIndicator.Low[] should be used instead of low[]
|
||||
// customChartIndicator.High[] should be used instead of high[]
|
||||
// customChartIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
// customChartIndicator.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
|
||||
// customChartIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) customChartIndicator.SetGetTimeFlag() must be called in OnInit() for customChartIndicator.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
|
||||
// customChartIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// customChartIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) customChartIndicator.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
|
||||
// customChartIndicator.Price[] should be used instead of Price[]
|
||||
// (!) customChartIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for customChartIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -150,13 +153,13 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
for(i=pos;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
//--- SMA on price buffer
|
||||
ExtSPBuffer[i]=SimpleMA(i,ExtCCIPeriod,rangeBarsIndicator.Price);
|
||||
ExtSPBuffer[i]=SimpleMA(i,ExtCCIPeriod,customChartIndicator.Price);
|
||||
//--- calculate D
|
||||
dTmp=0.0;
|
||||
for(j=0;j<ExtCCIPeriod;j++) dTmp+=MathAbs(rangeBarsIndicator.Price[i-j]-ExtSPBuffer[i]);
|
||||
for(j=0;j<ExtCCIPeriod;j++) dTmp+=MathAbs(customChartIndicator.Price[i-j]-ExtSPBuffer[i]);
|
||||
ExtDBuffer[i]=dTmp*dMul;
|
||||
//--- calculate M
|
||||
ExtMBuffer[i]=rangeBarsIndicator.Price[i]-ExtSPBuffer[i];
|
||||
ExtMBuffer[i]=customChartIndicator.Price[i]-ExtSPBuffer[i];
|
||||
//--- calculate CCI
|
||||
if(ExtDBuffer[i]!=0.0) ExtCCIBuffer[i]=ExtMBuffer[i]/ExtDBuffer[i];
|
||||
else ExtCCIBuffer[i]=0.0;
|
||||
|
||||
Binary file not shown.
@@ -26,7 +26,7 @@ int ExtArrowShift=-10;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -66,39 +66,15 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int i,limit;
|
||||
@@ -118,13 +94,13 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
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];
|
||||
if(customChartIndicator.High[i]>customChartIndicator.High[i+1] && customChartIndicator.High[i]>customChartIndicator.High[i+2] && customChartIndicator.High[i]>=customChartIndicator.High[i-1] && customChartIndicator.High[i]>=customChartIndicator.High[i-2])
|
||||
ExtUpperBuffer[i]=customChartIndicator.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];
|
||||
if(customChartIndicator.Low[i]<customChartIndicator.Low[i+1] && customChartIndicator.Low[i]<customChartIndicator.Low[i+2] && customChartIndicator.Low[i]<=customChartIndicator.Low[i-1] && customChartIndicator.Low[i]<=customChartIndicator.Low[i-2])
|
||||
ExtLowerBuffer[i]=customChartIndicator.Low[i];
|
||||
else ExtLowerBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
//------------------------------------------------------------------
|
||||
#property copyright "mladen"
|
||||
#property link "www.forex-tsd.com"
|
||||
//------------------------------------------------------------------
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
#property indicator_label1 "Gann zone"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrGainsboro,clrGainsboro
|
||||
#property indicator_label2 "Gann middle"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color2 clrGray
|
||||
#property indicator_label3 "Gann high/low"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrDimGray,clrLimeGreen,clrDarkOrange
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
//
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
//
|
||||
//
|
||||
|
||||
enum enMaTypes
|
||||
{
|
||||
ma_sma, // Simple moving average
|
||||
ma_ema, // Exponential moving average
|
||||
ma_smma, // Smoothed MA
|
||||
ma_lwma // Linear weighted MA
|
||||
};
|
||||
enum enFilterWhat
|
||||
{
|
||||
flt_prc, // Filter the prices
|
||||
flt_val, // Filter the averages value
|
||||
flt_all // Filter all
|
||||
};
|
||||
ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame
|
||||
input int AvgPeriod = 10; // Average period
|
||||
input enMaTypes AvgType = ma_sma; // Average method
|
||||
input double Filter = 0; // Filter to use (<=0 for no filter)
|
||||
input enFilterWhat FilterOn = flt_prc; // Filter :
|
||||
input bool alertsOn = false; // Turn alerts on?
|
||||
input bool alertsOnCurrent = true; // Alert on current bar?
|
||||
input bool alertsMessage = true; // Display messageas on alerts?
|
||||
input bool alertsSound = false; // Play sound on alerts?
|
||||
input bool alertsEmail = false; // Send email on alerts?
|
||||
input bool alertsNotify = false; // Send push notification on alerts?
|
||||
input bool Interpolate = true; // Interpolate mtf data ?
|
||||
|
||||
double sup[],supc[],mid[],fup[],fdn[],_count[];
|
||||
ENUM_TIMEFRAMES timeFrame;
|
||||
string indName;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,fup,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,fdn,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,mid,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,sup,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,supc,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(5,_count,INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
customChartIndicator.SetGetTimeFlag();
|
||||
|
||||
// timeFrame = MathMax(_Period,TimeFrame);
|
||||
indName = getIndicatorName();
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,periodToString(timeFrame)+" Gann high/low activator("+string(AvgPeriod)+")");
|
||||
return(0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
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 (Bars(_Symbol,_Period)<rates_total) return(-1);
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
|
||||
double pfilter = Filter; if (FilterOn==flt_val) pfilter=0;
|
||||
double vfilter = Filter; if (FilterOn==flt_prc) vfilter=0;
|
||||
|
||||
for (int i=(int)MathMax(_prev_calculated-1,1); i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
fup[i] = iFilter(iCustomMa(AvgType,iFilter(customChartIndicator.High[i-1],pfilter,AvgPeriod,i,rates_total,0),AvgPeriod,i,rates_total,0),vfilter,AvgPeriod,i,rates_total,1);
|
||||
fdn[i] = iFilter(iCustomMa(AvgType,iFilter(customChartIndicator.Low[i-1] ,pfilter,AvgPeriod,i,rates_total,2),AvgPeriod,i,rates_total,1),vfilter,AvgPeriod,i,rates_total,3);
|
||||
mid[i] = (fup[i]+fdn[i])/2.0;
|
||||
double pclose = iFilter(customChartIndicator.Close[i],pfilter,AvgPeriod,i,rates_total,4);
|
||||
supc[i] = (pclose>fup[i]) ? 1 : (pclose<fdn[i]) ? 2 : supc[i-1];
|
||||
sup[i] = (supc[i]==1) ? fdn[i] : (supc[i]==2) ? fup[i] : pclose;
|
||||
}
|
||||
manageAlerts(customChartIndicator.Time,supc,rates_total);
|
||||
_count[rates_total-1] = MathMax(rates_total-_prev_calculated+1,1);
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#define _filterInstances 5
|
||||
double workFil[][_filterInstances*3];
|
||||
|
||||
#define _fchange 0
|
||||
#define _fachang 1
|
||||
#define _fvalue 2
|
||||
|
||||
double iFilter(double value, double filter, int period, int i, int bars, int instanceNo=0)
|
||||
{
|
||||
if (filter<=0 || period<=0) return(value);
|
||||
if (ArrayRange(workFil,0)!= bars) ArrayResize(workFil,bars); instanceNo*=3;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
workFil[i][instanceNo+_fvalue] = value;
|
||||
if (i>0)
|
||||
{
|
||||
workFil[i][instanceNo+_fchange] = MathAbs(workFil[i][instanceNo+_fvalue]-workFil[i-1][instanceNo+_fvalue]);
|
||||
workFil[i][instanceNo+_fachang] = workFil[i][instanceNo+_fchange];
|
||||
|
||||
double fdev=0, fdif=0;
|
||||
for (int k=1; k<period && (i-k)>=0; k++) workFil[i][instanceNo+_fachang] += workFil[i-k][instanceNo+_fchange]; workFil[i][instanceNo+_fachang] /= (double)period;
|
||||
for (int k=0; k<period && (i-k)>=0; k++) fdev += MathPow(workFil[i-k][instanceNo+_fchange]-workFil[i-k][instanceNo+_fachang],2); fdev = MathSqrt(fdev/(double)period); fdif = filter*fdev;
|
||||
if (MathAbs(workFil[i][instanceNo+_fvalue]-workFil[i-1][instanceNo+_fvalue])<fdif)
|
||||
workFil[i][instanceNo+_fvalue]=workFil[i-1][instanceNo+_fvalue];
|
||||
}
|
||||
return(workFil[i][instanceNo+_fvalue]);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
void manageAlerts(const datetime& time[], double& trend[], int bars)
|
||||
{
|
||||
if (!alertsOn) return;
|
||||
int whichBar = bars-1; if (!alertsOnCurrent) whichBar = bars-2; datetime time1 = time[whichBar];
|
||||
if (trend[whichBar] != trend[whichBar-1])
|
||||
{
|
||||
if (trend[whichBar] == 1) doAlert(time1,"up");
|
||||
if (trend[whichBar] == 2) doAlert(time1,"down");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
void doAlert(datetime forTime, string doWhat)
|
||||
{
|
||||
static string previousAlert="nothing";
|
||||
static datetime previousTime;
|
||||
string message;
|
||||
|
||||
if (previousAlert != doWhat || previousTime != forTime)
|
||||
{
|
||||
previousAlert = doWhat;
|
||||
previousTime = forTime;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
message = periodToString(_Period)+" "+_Symbol+" at "+TimeToString(TimeLocal(),TIME_SECONDS)+" Gann high/low activator state changed to "+doWhat;
|
||||
if (alertsMessage) Alert(message);
|
||||
if (alertsEmail) SendMail(_Symbol+" Gann high/low activator",message);
|
||||
if (alertsNotify) SendNotification(message);
|
||||
if (alertsSound) PlaySound("alert2.wav");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#define _maInstances 2
|
||||
#define _maWorkBufferx1 1*_maInstances
|
||||
#define _maWorkBufferx2 2*_maInstances
|
||||
|
||||
double iCustomMa(int mode, double price, double length, int r, int bars, int instanceNo=0)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case ma_sma : return(iSma(price,(int)length,r,bars,instanceNo));
|
||||
case ma_ema : return(iEma(price,length,r,bars,instanceNo));
|
||||
case ma_smma : return(iSmma(price,(int)length,r,bars,instanceNo));
|
||||
case ma_lwma : return(iLwma(price,(int)length,r,bars,instanceNo));
|
||||
default : return(price);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double workSma[][_maWorkBufferx2];
|
||||
double iSma(double price, int period, int r, int _bars, int instanceNo=0)
|
||||
{
|
||||
if (period<=1) return(price);
|
||||
if (ArrayRange(workSma,0)!= _bars) ArrayResize(workSma,_bars); instanceNo *= 2; int k;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
workSma[r][instanceNo+0] = price;
|
||||
workSma[r][instanceNo+1] = price; for(k=1; k<period && (r-k)>=0; k++) workSma[r][instanceNo+1] += workSma[r-k][instanceNo+0];
|
||||
workSma[r][instanceNo+1] /= 1.0*k;
|
||||
return(workSma[r][instanceNo+1]);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double workEma[][_maWorkBufferx1];
|
||||
double iEma(double price, double period, int r, int _bars, int instanceNo=0)
|
||||
{
|
||||
if (period<=1) return(price);
|
||||
if (ArrayRange(workEma,0)!= _bars) ArrayResize(workEma,_bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
workEma[r][instanceNo] = price;
|
||||
double alpha = 2.0 / (1.0+period);
|
||||
if (r>0)
|
||||
workEma[r][instanceNo] = workEma[r-1][instanceNo]+alpha*(price-workEma[r-1][instanceNo]);
|
||||
return(workEma[r][instanceNo]);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double workSmma[][_maWorkBufferx1];
|
||||
double iSmma(double price, double period, int r, int _bars, int instanceNo=0)
|
||||
{
|
||||
if (period<=1) return(price);
|
||||
if (ArrayRange(workSmma,0)!= _bars) ArrayResize(workSmma,_bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (r<period)
|
||||
workSmma[r][instanceNo] = price;
|
||||
else workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period;
|
||||
return(workSmma[r][instanceNo]);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double workLwma[][_maWorkBufferx1];
|
||||
double iLwma(double price, double period, int r, int _bars, int instanceNo=0)
|
||||
{
|
||||
if (period<=1) return(price);
|
||||
if (ArrayRange(workLwma,0)!= _bars) ArrayResize(workLwma,_bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
workLwma[r][instanceNo] = price;
|
||||
double sumw = period;
|
||||
double sum = period*price;
|
||||
|
||||
for(int k=1; k<period && (r-k)>=0; k++)
|
||||
{
|
||||
double weight = period-k;
|
||||
sumw += weight;
|
||||
sum += weight*workLwma[r-k][instanceNo];
|
||||
}
|
||||
return(sum/sumw);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
string getIndicatorName()
|
||||
{
|
||||
string progPath = MQL5InfoString(MQL5_PROGRAM_PATH); int start=-1;
|
||||
while (true)
|
||||
{
|
||||
int foundAt = StringFind(progPath,"\\",start+1);
|
||||
if (foundAt>=0)
|
||||
start = foundAt;
|
||||
else break;
|
||||
}
|
||||
|
||||
string indicatorName = StringSubstr(progPath,start+1);
|
||||
indicatorName = StringSubstr(indicatorName,0,StringLen(indicatorName)-4);
|
||||
return(indicatorName);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int _tfsPer[]={PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
|
||||
string _tfsStr[]={"1 minute","2 minutes","3 minutes","4 minutes","5 minutes","6 minutes","10 minutes","12 minutes","15 minutes","20 minutes","30 minutes","1 hour","2 hours","3 hours","4 hours","6 hours","8 hours","12 hours","daily","weekly","monthly"};
|
||||
string periodToString(int period)
|
||||
{
|
||||
if (period==PERIOD_CURRENT)
|
||||
period = _Period;
|
||||
int i; for(i=0;i<ArraySize(_tfsPer);i++) if(period==_tfsPer[i]) break;
|
||||
return(_tfsStr[i]);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ int period;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -97,42 +97,18 @@ int OnCalculate(const int rates_total,
|
||||
if(rates_total<period+1)return(0);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
ArraySetAsSeries(rangeBarsIndicator.Close,true);
|
||||
ArraySetAsSeries(customChartIndicator.Close,true);
|
||||
//---
|
||||
int limit;
|
||||
if(rates_total<_prev_calculated || _prev_calculated<=0)
|
||||
@@ -154,8 +130,8 @@ int OnCalculate(const int rates_total,
|
||||
{
|
||||
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(NormalizeDouble(customChartIndicator.Close[i],_Digits)>NormalizeDouble(MaHighBuffer[i+1],_Digits)) TrendBuffer[i]=1;
|
||||
if(NormalizeDouble(customChartIndicator.Close[i],_Digits)<NormalizeDouble(MaLowBuffer[i+1],_Digits)) TrendBuffer[i]=-1;
|
||||
//---
|
||||
if(TrendBuffer[i]<0)
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -25,7 +25,7 @@ double ExtColorBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -67,36 +67,14 @@ int OnCalculate(const int rates_total,
|
||||
int i,limit;
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -106,10 +84,10 @@ int OnCalculate(const int rates_total,
|
||||
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];
|
||||
ExtLBuffer[0]=customChartIndicator.Low[0];
|
||||
ExtHBuffer[0]=customChartIndicator.High[0];
|
||||
ExtOBuffer[0]=customChartIndicator.Open[0];
|
||||
ExtCBuffer[0]=customChartIndicator.Close[0];
|
||||
limit=1;
|
||||
}
|
||||
else limit=_prev_calculated-1;
|
||||
@@ -118,9 +96,9 @@ int OnCalculate(const int rates_total,
|
||||
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));
|
||||
double haClose=(customChartIndicator.Open[i]+customChartIndicator.High[i]+customChartIndicator.Low[i]+customChartIndicator.Close[i])/4;
|
||||
double haHigh=MathMax(customChartIndicator.High[i],MathMax(haOpen,haClose));
|
||||
double haLow=MathMin(customChartIndicator.Low[i],MathMin(haOpen,haClose));
|
||||
|
||||
ExtLBuffer[i]=haLow;
|
||||
ExtHBuffer[i]=haHigh;
|
||||
|
||||
@@ -38,7 +38,7 @@ double ExtChikouBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -115,36 +115,14 @@ int OnCalculate(const int rates_total,
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -157,20 +135,20 @@ int OnCalculate(const int rates_total,
|
||||
//---
|
||||
for(int i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtChikouBuffer[i]=rangeBarsIndicator.Close[i];
|
||||
ExtChikouBuffer[i]=customChartIndicator.Close[i];
|
||||
//--- tenkan sen
|
||||
double _high=Highest(rangeBarsIndicator.High,InpTenkan,i);
|
||||
double _low=Lowest(rangeBarsIndicator.Low,InpTenkan,i);
|
||||
double _high=Highest(customChartIndicator.High,InpTenkan,i);
|
||||
double _low=Lowest(customChartIndicator.Low,InpTenkan,i);
|
||||
ExtTenkanBuffer[i]=(_high+_low)/2.0;
|
||||
//--- kijun sen
|
||||
_high=Highest(rangeBarsIndicator.High,InpKijun,i);
|
||||
_low=Lowest(rangeBarsIndicator.Low,InpKijun,i);
|
||||
_high=Highest(customChartIndicator.High,InpKijun,i);
|
||||
_low=Lowest(customChartIndicator.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);
|
||||
_high=Highest(customChartIndicator.High,InpSenkou,i);
|
||||
_low=Lowest(customChartIndicator.Low,InpSenkou,i);
|
||||
ExtSpanBBuffer[i]=(_high+_low)/2.0;
|
||||
}
|
||||
//--- done
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,93 @@
|
||||
#property description "Linear Regression"
|
||||
#property description "https://www.mql5.com/en/articles/270"
|
||||
#property copyright "ds2"
|
||||
#property version "1.0"
|
||||
//+------------------------------------------------------------------+
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 Cyan
|
||||
//+------------------------------------------------------------------+
|
||||
input int LRPeriod = 20; // Bars in regression
|
||||
//+------------------------------------------------------------------+
|
||||
// The main buffer - drawing a line on a chart
|
||||
double ExtLRBuffer[];
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
SetIndexBuffer(0, ExtLRBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, LRPeriod-1);
|
||||
|
||||
IndicatorSetString (INDICATOR_SHORTNAME,"Linear Regression");
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
|
||||
customChartIndicator.SetUseAppliedPriceFlag(PRICE_CLOSE);
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (rates_total < LRPeriod)
|
||||
return(0);
|
||||
|
||||
int limit = _prev_calculated ? _prev_calculated-1 : LRPeriod-1;
|
||||
|
||||
// The cycle along the calculated bars
|
||||
for (int bar = limit; bar < rates_total; bar++)
|
||||
{
|
||||
double lrvalue = 0; // the linear regression value in this bar
|
||||
double Sx=0, Sy=0, Sxy=0, Sxx=0;
|
||||
|
||||
// Finding intermediate values-sums
|
||||
Sx = 0;
|
||||
Sy = 0;
|
||||
Sxx = 0;
|
||||
Sxy = 0;
|
||||
for (int x = 1; x <= LRPeriod; x++)
|
||||
{
|
||||
double y = customChartIndicator.GetPrice(bar-LRPeriod+x);
|
||||
Sx += x;
|
||||
Sy += y;
|
||||
Sxx += x*x;
|
||||
Sxy += x*y;
|
||||
}
|
||||
|
||||
// Regression ratios
|
||||
double a = (LRPeriod * Sxy - Sx * Sy) / (LRPeriod * Sxx - Sx * Sx);
|
||||
double b = (Sy - a * Sx) / LRPeriod;
|
||||
|
||||
lrvalue = a*LRPeriod + b;
|
||||
|
||||
// Saving regression results
|
||||
ExtLRBuffer[bar] = lrvalue;
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -26,7 +26,7 @@ double ExtLineBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -169,7 +169,7 @@ void OnInit()
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
|
||||
customChartIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
|
||||
|
||||
//
|
||||
//
|
||||
@@ -197,40 +197,16 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
{
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
int _begin = 0;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- check for bars count
|
||||
@@ -246,10 +222,10 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//--- 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;
|
||||
case MODE_EMA: CalculateEMA(rates_total,_prev_calculated,_begin,customChartIndicator.Price); break;
|
||||
case MODE_LWMA: CalculateLWMA(rates_total,_prev_calculated,_begin,customChartIndicator.Price); break;
|
||||
case MODE_SMMA: CalculateSmoothedMA(rates_total,_prev_calculated,_begin,customChartIndicator.Price); break;
|
||||
case MODE_SMA: CalculateSimpleMA(rates_total,_prev_calculated,_begin,customChartIndicator.Price); break;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#property copyright "2009, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Moving Average Convergence/Divergence"
|
||||
#property description "Adapted for use with TickChart by Artur Zas."
|
||||
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
@@ -35,17 +37,8 @@ double ExtFastMaBuffer[];
|
||||
double ExtSlowMaBuffer[];
|
||||
double ExtMacdBuffer[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
@@ -79,53 +72,44 @@ 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))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
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[]
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
int _rates_total = customChartIndicator.GetRatesTotal();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
//--- check for data
|
||||
if(rates_total<InpSignalSMA)
|
||||
if(_rates_total<InpSignalSMA)
|
||||
return(0);
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(_prev_calculated>rates_total || _prev_calculated<0) to_copy=rates_total;
|
||||
if(_prev_calculated>_rates_total || _prev_calculated<0) to_copy=_rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-_prev_calculated;
|
||||
to_copy=_rates_total-_prev_calculated;
|
||||
if(_prev_calculated>0) to_copy++;
|
||||
}
|
||||
|
||||
//--- get Fast EMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpFastEMA,rangeBarsIndicator.Close,ExtFastMaBuffer);
|
||||
ExponentialMAOnBuffer(_rates_total,_prev_calculated,0,InpFastEMA,customChartIndicator.Close,ExtFastMaBuffer);
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpSlowEMA,rangeBarsIndicator.Close,ExtSlowMaBuffer);
|
||||
ExponentialMAOnBuffer(_rates_total,_prev_calculated,0,InpSlowEMA,customChartIndicator.Close,ExtSlowMaBuffer);
|
||||
//---
|
||||
int limit;
|
||||
if(_prev_calculated==0)
|
||||
limit=0;
|
||||
else limit=_prev_calculated-1;
|
||||
//--- calculate MACD
|
||||
for(int i=limit;i<rates_total && !IsStopped();i++)
|
||||
|
||||
for(int i=limit;i<_rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtMacdBuffer[i] = ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
if(ExtMacdBuffer[i] > 0)
|
||||
@@ -140,8 +124,9 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
}
|
||||
}
|
||||
//--- calculate Signal
|
||||
SimpleMAOnBuffer(rates_total,_prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
|
||||
SimpleMAOnBuffer(_rates_total,_prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
|
||||
//--- OnCalculate done. Return new _prev_calculated.
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#property copyright "2009, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Moving Average Convergence/Divergence"
|
||||
#property description "Adapted for use with TickChart by Artur Zas."
|
||||
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
@@ -31,15 +33,11 @@ double ExtFastMaBuffer[];
|
||||
double ExtSlowMaBuffer[];
|
||||
double ExtMacdBuffer[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -78,11 +76,15 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
// Precoess data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
int _rates_total = customChartIndicator.GetRatesTotal();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -98,6 +100,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
to_copy=rates_total-_prev_calculated;
|
||||
if(_prev_calculated>0) to_copy++;
|
||||
}
|
||||
|
||||
//--- get Fast EMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpFastEMA,customChartIndicator.Close,ExtFastMaBuffer);
|
||||
|
||||
@@ -26,7 +26,7 @@ int ExtMomentumPeriod;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -40,7 +40,7 @@ void OnInit()
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
customChartIndicator.SetUseAppliedPriceFlag(InpApplyToPrice);
|
||||
|
||||
//
|
||||
//
|
||||
@@ -88,39 +88,15 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
static int begin = 0;
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- start calculation
|
||||
@@ -137,8 +113,8 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//--- 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];
|
||||
if(customChartIndicator.Price[i-ExtMomentumPeriod] > 0)
|
||||
ExtMomentumBuffer[i]=customChartIndicator.Price[i]*100/customChartIndicator.Price[i-ExtMomentumPeriod];
|
||||
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| iNRTR.mq5 |
|
||||
//| MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 4
|
||||
//--- plot Support
|
||||
#property indicator_label1 "Support"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 DodgerBlue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
//--- plot Resistance
|
||||
#property indicator_label2 "Resistance"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 Red
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
//--- plot UpTarget
|
||||
#property indicator_label3 "UpTarget"
|
||||
#property indicator_type3 DRAW_ARROW
|
||||
#property indicator_color3 RoyalBlue
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
//--- plot DnTarget
|
||||
#property indicator_label4 "DnTarget"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 Crimson
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 2
|
||||
//--- input parameters
|
||||
input int period = 40; /*period*/ // ATR period in bars
|
||||
input double k = 2.0; /*k*/ // ATR change coefficient
|
||||
//--- indicator buffers
|
||||
double SupportBuffer[];
|
||||
double ResistanceBuffer[];
|
||||
double UpTargetBuffer[];
|
||||
double DnTargetBuffer[];
|
||||
double Trend[];
|
||||
double ATRBuffer[];
|
||||
int Handle;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,SupportBuffer,INDICATOR_DATA);
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,159);
|
||||
|
||||
SetIndexBuffer(1,ResistanceBuffer,INDICATOR_DATA);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW,159);
|
||||
|
||||
SetIndexBuffer(2,UpTargetBuffer,INDICATOR_DATA);
|
||||
PlotIndexSetInteger(2,PLOT_ARROW,158);
|
||||
|
||||
SetIndexBuffer(3,DnTargetBuffer,INDICATOR_DATA);
|
||||
PlotIndexSetInteger(3,PLOT_ARROW,158);
|
||||
|
||||
SetIndexBuffer(4,Trend,INDICATOR_DATA);
|
||||
SetIndexBuffer(5,ATRBuffer,INDICATOR_CALCULATIONS);
|
||||
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
|
||||
PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
|
||||
PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0);
|
||||
PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0);
|
||||
PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0);
|
||||
|
||||
Handle=iATR(_Symbol,PERIOD_CURRENT,period);
|
||||
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
static bool error=true;
|
||||
int start;
|
||||
if(_prev_calculated==0)
|
||||
{
|
||||
error=true;
|
||||
}
|
||||
if(error)
|
||||
{
|
||||
ArrayInitialize(Trend,0);
|
||||
ArrayInitialize(UpTargetBuffer,0);
|
||||
ArrayInitialize(DnTargetBuffer,0);
|
||||
ArrayInitialize(SupportBuffer,0);
|
||||
ArrayInitialize(ResistanceBuffer,0);
|
||||
start=period;
|
||||
error=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=_prev_calculated-1;
|
||||
}
|
||||
if(CopyBuffer(Handle,0,0,rates_total-start,ATRBuffer)==-1)
|
||||
{
|
||||
error=true;
|
||||
return(0);
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
Trend[i]=Trend[i-1];
|
||||
UpTargetBuffer[i]=UpTargetBuffer[i-1];
|
||||
DnTargetBuffer[i]=DnTargetBuffer[i-1];
|
||||
SupportBuffer[i]=SupportBuffer[i-1];
|
||||
ResistanceBuffer[i]=ResistanceBuffer[i-1];
|
||||
switch((int)Trend[i])
|
||||
{
|
||||
case 2:
|
||||
if(customChartIndicator.Low[i]>UpTargetBuffer[i])
|
||||
{
|
||||
UpTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
SupportBuffer[i]=customChartIndicator.Close[i]-k*ATRBuffer[i];
|
||||
}
|
||||
if(customChartIndicator.Close[i]<SupportBuffer[i])
|
||||
{
|
||||
DnTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
ResistanceBuffer[i]=customChartIndicator.Close[i]+k*ATRBuffer[i];
|
||||
Trend[i]=3;
|
||||
UpTargetBuffer[i]=0;
|
||||
SupportBuffer[i]=0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(customChartIndicator.High[i]<DnTargetBuffer[i])
|
||||
{
|
||||
DnTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
ResistanceBuffer[i]=customChartIndicator.Close[i]+k*ATRBuffer[i];
|
||||
}
|
||||
if(customChartIndicator.Close[i]>ResistanceBuffer[i])
|
||||
{
|
||||
UpTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
SupportBuffer[i]=customChartIndicator.Close[i]-k*ATRBuffer[i];
|
||||
Trend[i]=2;
|
||||
DnTargetBuffer[i]=0;
|
||||
ResistanceBuffer[i]=0;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
UpTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
DnTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
Trend[i]=1;
|
||||
break;
|
||||
case 1:
|
||||
if(customChartIndicator.Low[i]>UpTargetBuffer[i])
|
||||
{
|
||||
UpTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
SupportBuffer[i]=customChartIndicator.Close[i]-k*ATRBuffer[i];
|
||||
Trend[i]=2;
|
||||
DnTargetBuffer[i]=0;
|
||||
}
|
||||
if(customChartIndicator.High[i]<DnTargetBuffer[i])
|
||||
{
|
||||
DnTargetBuffer[i]=customChartIndicator.Close[i];
|
||||
ResistanceBuffer[i]=customChartIndicator.Close[i]+k*ATRBuffer[i];
|
||||
Trend[i]=3;
|
||||
UpTargetBuffer[i]=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -24,7 +24,7 @@ double ExtOBVBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -42,7 +42,7 @@ void OnInit()
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//---- OnInit done
|
||||
|
||||
customIndicator.SetGetVolumesFlag();
|
||||
customChartIndicator.SetGetVolumesFlag();
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -63,10 +63,13 @@ int OnCalculate(const int rates_total,
|
||||
// Process data through RangeBar indicator
|
||||
//
|
||||
|
||||
if(!customIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -84,14 +87,14 @@ int OnCalculate(const int rates_total,
|
||||
{
|
||||
pos=1;
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
ExtOBVBuffer[0]=(double)customIndicator.Tick_volume[0];
|
||||
else ExtOBVBuffer[0]=(double)customIndicator.Real_volume[0];
|
||||
ExtOBVBuffer[0]=(double)customChartIndicator.Tick_volume[0];
|
||||
else ExtOBVBuffer[0]=(double)customChartIndicator.Real_volume[0];
|
||||
}
|
||||
//--- main cycle
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateOBV(pos,rates_total,customIndicator.Close,customIndicator.Tick_volume);
|
||||
CalculateOBV(pos,rates_total,customChartIndicator.Close,customChartIndicator.Tick_volume);
|
||||
else
|
||||
CalculateOBV(pos,rates_total,customIndicator.Close,customIndicator.Real_volume);
|
||||
CalculateOBV(pos,rates_total,customChartIndicator.Close,customChartIndicator.Real_volume);
|
||||
//---- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ double ExtSarMaximum;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -91,39 +91,15 @@ int OnCalculate(const int rates_total,
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- detect current position
|
||||
@@ -135,12 +111,12 @@ int OnCalculate(const int rates_total,
|
||||
pos=1;
|
||||
ExtAFBuffer[0]=ExtSarStep;
|
||||
ExtAFBuffer[1]=ExtSarStep;
|
||||
ExtSARBuffer[0]=rangeBarsIndicator.High[0];
|
||||
ExtSARBuffer[0]=customChartIndicator.High[0];
|
||||
ExtLastRevPos=0;
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[1]=GetHigh(pos,ExtLastRevPos,rangeBarsIndicator.High);
|
||||
ExtEPBuffer[0]=rangeBarsIndicator.Low[pos];
|
||||
ExtEPBuffer[1]=rangeBarsIndicator.Low[pos];
|
||||
ExtSARBuffer[1]=GetHigh(pos,ExtLastRevPos,customChartIndicator.High);
|
||||
ExtEPBuffer[0]=customChartIndicator.Low[pos];
|
||||
ExtEPBuffer[1]=customChartIndicator.Low[pos];
|
||||
}
|
||||
//---main cycle
|
||||
for(int i=pos;i<rates_total-1 && !IsStopped();i++)
|
||||
@@ -148,24 +124,24 @@ int OnCalculate(const int rates_total,
|
||||
//--- check for reverse
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
if(ExtSARBuffer[i]>rangeBarsIndicator.Low[i])
|
||||
if(ExtSARBuffer[i]>customChartIndicator.Low[i])
|
||||
{
|
||||
//--- switch to SHORT
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[i]=GetHigh(i,ExtLastRevPos,rangeBarsIndicator.High);
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.Low[i];
|
||||
ExtSARBuffer[i]=GetHigh(i,ExtLastRevPos,customChartIndicator.High);
|
||||
ExtEPBuffer[i]=customChartIndicator.Low[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ExtSARBuffer[i]<rangeBarsIndicator.High[i])
|
||||
if(ExtSARBuffer[i]<customChartIndicator.High[i])
|
||||
{
|
||||
//--- switch to LONG
|
||||
ExtDirectionLong=true;
|
||||
ExtSARBuffer[i]=GetLow(i,ExtLastRevPos,rangeBarsIndicator.Low);
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.High[i];
|
||||
ExtSARBuffer[i]=GetLow(i,ExtLastRevPos,customChartIndicator.Low);
|
||||
ExtEPBuffer[i]=customChartIndicator.High[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
@@ -174,9 +150,9 @@ int OnCalculate(const int rates_total,
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
//--- check for new High
|
||||
if(rangeBarsIndicator.High[i]>ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
if(customChartIndicator.High[i]>ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.High[i];
|
||||
ExtEPBuffer[i]=customChartIndicator.High[i];
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
|
||||
if(ExtAFBuffer[i]>ExtSarMaximum)
|
||||
ExtAFBuffer[i]=ExtSarMaximum;
|
||||
@@ -193,15 +169,15 @@ int OnCalculate(const int rates_total,
|
||||
//--- 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]);
|
||||
if(ExtSARBuffer[i+1]>customChartIndicator.Low[i] || ExtSARBuffer[i+1]>customChartIndicator.Low[i-1])
|
||||
ExtSARBuffer[i+1]=MathMin(customChartIndicator.Low[i],customChartIndicator.Low[i-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- check for new Low
|
||||
if(rangeBarsIndicator.Low[i]<ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
if(customChartIndicator.Low[i]<ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=rangeBarsIndicator.Low[i];
|
||||
ExtEPBuffer[i]=customChartIndicator.Low[i];
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
|
||||
if(ExtAFBuffer[i]>ExtSarMaximum)
|
||||
ExtAFBuffer[i]=ExtSarMaximum;
|
||||
@@ -218,8 +194,8 @@ int OnCalculate(const int rates_total,
|
||||
//--- 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]);
|
||||
if(ExtSARBuffer[i+1]<customChartIndicator.High[i] || ExtSARBuffer[i+1]<customChartIndicator.High[i-1])
|
||||
ExtSARBuffer[i+1]=MathMax(customChartIndicator.High[i],customChartIndicator.High[i-1]);
|
||||
}
|
||||
}
|
||||
//---- OnCalculate done. Return new prev_calculated.
|
||||
|
||||
@@ -24,7 +24,7 @@ int ExtRocPeriod;
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -57,7 +57,7 @@ void OnInit()
|
||||
// Indicator uses Price[] array for calculations so we need to set this in the MedianRenkoIndicator class
|
||||
//
|
||||
|
||||
rangeBarsIndicator.SetUseAppliedPriceFlag(PRICE_CLOSE);
|
||||
customChartIndicator.SetUseAppliedPriceFlag(PRICE_CLOSE);
|
||||
|
||||
//
|
||||
//
|
||||
@@ -80,36 +80,14 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -125,10 +103,10 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//--- the main loop of calculations
|
||||
for(int i=pos;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
if(rangeBarsIndicator.Price[i]==0.0)
|
||||
if(customChartIndicator.Price[i]==0.0)
|
||||
ExtRocBuffer[i]=0.0;
|
||||
else
|
||||
ExtRocBuffer[i]=(rangeBarsIndicator.Price[i]-rangeBarsIndicator.Price[i-ExtRocPeriod])/rangeBarsIndicator.Price[i]*100;
|
||||
ExtRocBuffer[i]=(customChartIndicator.Price[i]-customChartIndicator.Price[i-ExtRocPeriod])/customChartIndicator.Price[i]*100;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
|
||||
@@ -30,7 +30,7 @@ double ExtNegBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -78,39 +78,15 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int i,pos;
|
||||
@@ -122,7 +98,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
ArraySetAsSeries(ExtRSIBuffer,false);
|
||||
ArraySetAsSeries(ExtPosBuffer,false);
|
||||
ArraySetAsSeries(ExtNegBuffer,false);
|
||||
ArraySetAsSeries(rangeBarsIndicator.Close,false);
|
||||
ArraySetAsSeries(customChartIndicator.Close,false);
|
||||
//--- preliminary calculations
|
||||
pos=_prev_calculated-1;
|
||||
if(pos<=InpRSIPeriod)
|
||||
@@ -138,7 +114,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
ExtRSIBuffer[i]=0.0;
|
||||
ExtPosBuffer[i]=0.0;
|
||||
ExtNegBuffer[i]=0.0;
|
||||
diff=rangeBarsIndicator.Close[i]-rangeBarsIndicator.Close[i-1];
|
||||
diff=customChartIndicator.Close[i]-customChartIndicator.Close[i-1];
|
||||
if(diff>0)
|
||||
sump+=diff;
|
||||
else
|
||||
@@ -162,7 +138,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//--- the main loop of calculations
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
diff=rangeBarsIndicator.Close[i]-rangeBarsIndicator.Close[i-1];
|
||||
diff=customChartIndicator.Close[i]-customChartIndicator.Close[i-1];
|
||||
ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod;
|
||||
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod;
|
||||
if(ExtNegBuffer[i]!=0.0)
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| StdDev.mq5 |
|
||||
//| Copyright 2009-2017, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009-2017, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Standard Deviation"
|
||||
#property description "Adapted for use with TickChart by Artur Zas."
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 MediumSeaGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
//--- input parametrs
|
||||
input int InpStdDevPeriod=20; // Period
|
||||
input int InpStdDevShift=0; // Shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE InpPrice=PRICE_CLOSE; // Apply to
|
||||
//---- buffers
|
||||
double ExtStdDevBuffer[];
|
||||
double ExtMABuffer[];
|
||||
//--- global variables
|
||||
int ExtStdDevPeriod,ExtStdDevShift;
|
||||
|
||||
#include <MovingAverages.mqh>
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpStdDevPeriod<=1)
|
||||
{
|
||||
ExtStdDevPeriod=20;
|
||||
printf("Incorrect value for input variable InpStdDevPeriod=%d. Indicator will use value=%d for calculations.",InpStdDevPeriod,ExtStdDevPeriod);
|
||||
}
|
||||
else ExtStdDevPeriod=InpStdDevPeriod;
|
||||
if(InpStdDevShift<0)
|
||||
{
|
||||
ExtStdDevShift=0;
|
||||
printf("Incorrect value for input variable InpStdDevShift=%d. Indicator will use value=%d for calculations.",InpStdDevShift,ExtStdDevShift);
|
||||
}
|
||||
else ExtStdDevShift=InpStdDevShift;
|
||||
//--- set indicator short name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"StdDev("+string(ExtStdDevPeriod)+")");
|
||||
//---- define indicator buffers as indexes
|
||||
SetIndexBuffer(0,ExtStdDevBuffer);
|
||||
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set index label
|
||||
PlotIndexSetString(0,PLOT_LABEL,"StdDev("+string(ExtStdDevPeriod)+")");
|
||||
//--- set index shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,ExtStdDevShift);
|
||||
//----
|
||||
|
||||
customChartIndicator.SetUseAppliedPriceFlag(InpPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//--- variables of indicator
|
||||
int pos;
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtStdDevPeriod-1);//+begin);
|
||||
//--- check for rates count
|
||||
if(rates_total<ExtStdDevPeriod)
|
||||
return(0);
|
||||
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
int _rates_total = customChartIndicator.GetRatesTotal();
|
||||
|
||||
//--- starting work
|
||||
pos=_prev_calculated-1;
|
||||
//--- correct position for first iteration
|
||||
if(pos<ExtStdDevPeriod)
|
||||
{
|
||||
pos=ExtStdDevPeriod-1;
|
||||
ArrayInitialize(ExtStdDevBuffer,0.0);
|
||||
ArrayInitialize(ExtMABuffer,0.0);
|
||||
}
|
||||
//--- main cycle
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA :
|
||||
for(int i=pos;i<_rates_total && !IsStopped();i++)
|
||||
{
|
||||
if(i==InpStdDevPeriod-1)
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod, customChartIndicator.Price);
|
||||
else
|
||||
ExtMABuffer[i]=ExponentialMA(i,InpStdDevPeriod,ExtMABuffer[i-1], customChartIndicator.Price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(customChartIndicator.Price, ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
case MODE_SMMA :
|
||||
for(int i=pos;i<_rates_total && !IsStopped();i++)
|
||||
{
|
||||
if(i==InpStdDevPeriod-1)
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,customChartIndicator.Price);
|
||||
else
|
||||
ExtMABuffer[i]=SmoothedMA(i,InpStdDevPeriod,ExtMABuffer[i-1],customChartIndicator.Price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(customChartIndicator.Price,ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
case MODE_LWMA :
|
||||
for(int i=pos;i<_rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtMABuffer[i]=LinearWeightedMA(i,InpStdDevPeriod,customChartIndicator.Price);
|
||||
ExtStdDevBuffer[i]=StdDevFunc(customChartIndicator.Price,ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
default :
|
||||
for(int i=pos;i<_rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,customChartIndicator.Price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(customChartIndicator.Price,ExtMABuffer,i);
|
||||
}
|
||||
}
|
||||
//---- OnCalculate done. Return new prev_calculated.
|
||||
return(_rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Standard Deviation |
|
||||
//+------------------------------------------------------------------+
|
||||
double StdDevFunc(const double &price[],const double &MAprice[],int position)
|
||||
{
|
||||
double dTmp=0.0;
|
||||
for(int i=0;i<ExtStdDevPeriod;i++) dTmp+=MathPow(price[position-i]-MAprice[position],2);
|
||||
dTmp=MathSqrt(dTmp/ExtStdDevPeriod);
|
||||
return(dTmp);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -30,7 +30,7 @@ double ExtLowesBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -82,11 +82,13 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
//
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -116,8 +118,8 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
double dmax=-1000000.0;
|
||||
for(k=i-InpKPeriod+1;k<=i;k++)
|
||||
{
|
||||
if(dmin>rangeBarsIndicator.Low[k]) dmin=rangeBarsIndicator.Low[k];
|
||||
if(dmax<rangeBarsIndicator.High[k]) dmax=rangeBarsIndicator.High[k];
|
||||
if(dmin>customChartIndicator.Low[k]) dmin=customChartIndicator.Low[k];
|
||||
if(dmax<customChartIndicator.High[k]) dmax=customChartIndicator.High[k];
|
||||
}
|
||||
ExtLowesBuffer[i]=dmin;
|
||||
ExtHighesBuffer[i]=dmax;
|
||||
@@ -137,7 +139,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
double sumhigh=0.0;
|
||||
for(k=(i-InpSlowing+1);k<=i;k++)
|
||||
{
|
||||
sumlow +=(rangeBarsIndicator.Close[k]-ExtLowesBuffer[k]);
|
||||
sumlow +=(customChartIndicator.Close[k]-ExtLowesBuffer[k]);
|
||||
sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
|
||||
}
|
||||
if(sumhigh==0.0) ExtMainBuffer[i]=100.0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#property copyright "Copyright 2018, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
#property version "1.01"
|
||||
#property copyright "Copyright 2018-2020, Level Up Software"
|
||||
#property link "https://www.az-invest.eu"
|
||||
#property description "A timescale indicator for use on X Tick Chart."
|
||||
#property version "1.03"
|
||||
#property indicator_separate_window
|
||||
#property indicator_plots 0
|
||||
|
||||
@@ -20,9 +21,11 @@ enum ENUM_DISPLAY_FORMAT
|
||||
|
||||
input color InpTextColor = clrWhiteSmoke; // Font color
|
||||
input int InpFontSize = 9; // Font size
|
||||
input int InpSpacing = 8; // Date/Time spacing
|
||||
input int InpSpacing = 3; // Date/Time spacing factor
|
||||
input ENUM_DISPLAY_FORMAT InpDispFormat = DisplayFormat1; // Display format
|
||||
|
||||
int __spacing = InpSpacing;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -31,12 +34,14 @@ int OnInit()
|
||||
//--- indicator buffers mapping
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"\n");
|
||||
IndicatorSetDouble(INDICATOR_MINIMUM,0);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM,9);
|
||||
IndicatorSetInteger(INDICATOR_HEIGHT,28);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM, 9);
|
||||
IndicatorSetInteger(INDICATOR_HEIGHT,16);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//---
|
||||
|
||||
customChartIndicator.SetGetTimeFlag();
|
||||
|
||||
RecalcSpacing();
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
@@ -59,7 +64,10 @@ int OnCalculate(const int rates_total,
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int start = customChartIndicator.GetPrevCalculated() - 1;
|
||||
@@ -69,13 +77,44 @@ int OnCalculate(const int rates_total,
|
||||
|
||||
if((start == 0) || customChartIndicator.IsNewBar)
|
||||
{
|
||||
ObjectsDeleteAll(__chartId,PREFIX_SEED);
|
||||
DrawTimeLine(0,rates_total,time);
|
||||
DrawTimeLine(0,customChartIndicator.GetRatesTotal(),time);
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
bool RecalcSpacing()
|
||||
{
|
||||
static int __prevScale = 5;
|
||||
int __currentScale = (int)ChartGetInteger(0, CHART_SCALE);
|
||||
|
||||
if(__prevScale == __currentScale)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(__currentScale)
|
||||
{
|
||||
case 5: __spacing = InpSpacing;
|
||||
break;
|
||||
case 4: __spacing = InpSpacing * 2;
|
||||
break;
|
||||
case 3: __spacing = InpSpacing * 4;
|
||||
break;
|
||||
case 2: __spacing = InpSpacing * 8;
|
||||
break;
|
||||
case 1: __spacing = InpSpacing * 16;
|
||||
break;
|
||||
case 0: __spacing = InpSpacing * 32;
|
||||
break;
|
||||
}
|
||||
|
||||
__prevScale = __currentScale;
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
void DrawTimeLine(const int nPosition, const int nRatesCount, const datetime &canvasTime[])
|
||||
@@ -84,15 +123,17 @@ void DrawTimeLine(const int nPosition, const int nRatesCount, const datetime &ca
|
||||
bool _start = false;
|
||||
int c = 0;
|
||||
|
||||
for(int i=nPosition;i<nRatesCount;i++)
|
||||
ObjectsDeleteAll(__chartId,PREFIX_SEED);
|
||||
|
||||
for(int i=nPosition; i<nRatesCount; i++)
|
||||
{
|
||||
curBarTime = (datetime)customChartIndicator.Time[i];
|
||||
curBarTime = customChartIndicator.GetTime(i);
|
||||
if(curBarTime == 0)
|
||||
continue;
|
||||
else
|
||||
_start = true;
|
||||
|
||||
if(c%InpSpacing == 0)
|
||||
if(c%__spacing == 0)
|
||||
DrawDateTimeMarker(i,curBarTime,canvasTime[i]);
|
||||
|
||||
if(_start)
|
||||
@@ -129,6 +170,28 @@ string NormalizeTime(datetime _dt)
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| ChartEvent function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
|
||||
if(id==CHARTEVENT_CHART_CHANGE)
|
||||
{
|
||||
if(RecalcSpacing() == false)
|
||||
return;
|
||||
|
||||
datetime __time[];
|
||||
CopyTime(_Symbol,_Period,0,Bars(_Symbol,_Period),__time);
|
||||
|
||||
DrawTimeLine(0,customChartIndicator.GetRatesTotal(),__time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// GUI wrapper function
|
||||
// https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_text
|
||||
@@ -185,4 +248,4 @@ bool TextCreate(const long chart_ID=0, // chart's ID
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ double Level[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -98,7 +98,7 @@ int OnInit()
|
||||
|
||||
IndicatorSetString(INDICATOR_SHORTNAME," VEMA Wilder's DMI ("+string(AdxPeriod)+")");
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
customChartIndicator.SetGetVolumesFlag();
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -136,39 +136,15 @@ int OnCalculate(const int rates_total,
|
||||
const int& spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
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
|
||||
//
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (ArrayRange(averages,0)!=rates_total) ArrayResize(averages,rates_total);
|
||||
@@ -182,16 +158,16 @@ int OnCalculate(const int 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 currTR = MathMax(customChartIndicator.High[i],customChartIndicator.Close[i-1])-MathMin(customChartIndicator.Low[i],customChartIndicator.Close[i-1]);
|
||||
double DeltaHi = customChartIndicator.High[i] - customChartIndicator.High[i-1];
|
||||
double DeltaLo = customChartIndicator.Low[i-1] - customChartIndicator.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;
|
||||
case vol_ticks: vol = (double)customChartIndicator.Tick_volume[i]; break;
|
||||
case vol_real: vol = (double)customChartIndicator.Real_volume[i]; break;
|
||||
default: vol = 1;
|
||||
}
|
||||
if ((DeltaHi > DeltaLo) && (DeltaHi > 0)) plusDM = DeltaHi;
|
||||
|
||||
@@ -61,7 +61,7 @@ enum PRICE_TYPE
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
#define VWAP_Daily "cc__VWAP_Daily"
|
||||
#define VWAP_Weekly "cc__VWAP_Weekly"
|
||||
@@ -169,8 +169,8 @@ int OnInit()
|
||||
ObjectSetString(0,VWAP_Monthly,OBJPROP_TEXT," ");
|
||||
}
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
rangeBarsIndicator.SetGetTimeFlag();
|
||||
customChartIndicator.SetGetVolumesFlag();
|
||||
customChartIndicator.SetGetTimeFlag();
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
@@ -199,36 +199,16 @@ int OnCalculate(const int rates_total,
|
||||
{
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
// Process data through Tick Chat indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
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 _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -240,7 +220,7 @@ int OnCalculate(const int rates_total,
|
||||
LastTimePeriod=PERIOD_CURRENT;
|
||||
}
|
||||
|
||||
if(rates_total>_prev_calculated || bIsFirstRun || Calc_Every_Tick || (_prev_calculated == 0) || rangeBarsIndicator.IsNewBar)
|
||||
if(rates_total>_prev_calculated || bIsFirstRun || Calc_Every_Tick || (_prev_calculated == 0) ||customChartIndicator.IsNewBar)
|
||||
{
|
||||
nIdxDaily = 0;
|
||||
nIdxWeekly = 0;
|
||||
@@ -260,22 +240,22 @@ int OnCalculate(const int rates_total,
|
||||
VWAP_Buffer_Weekly[nIdx]=EMPTY_VALUE;
|
||||
VWAP_Buffer_Monthly[nIdx]=EMPTY_VALUE;
|
||||
|
||||
if(rangeBarsIndicator.Time[nIdx] < 86400)
|
||||
if(customChartIndicator.Time[nIdx] < 86400)
|
||||
continue;
|
||||
|
||||
if(CreateDateTime(DAILY,rangeBarsIndicator.Time[nIdx])!=dtLastDay)
|
||||
if(CreateDateTime(DAILY,customChartIndicator.Time[nIdx])!=dtLastDay)
|
||||
{
|
||||
nIdxDaily=nIdx;
|
||||
nSumDailyTPV = 0;
|
||||
nSumDailyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(WEEKLY,rangeBarsIndicator.Time[nIdx])!=dtLastWeek)
|
||||
if(CreateDateTime(WEEKLY,customChartIndicator.Time[nIdx])!=dtLastWeek)
|
||||
{
|
||||
nIdxWeekly=nIdx;
|
||||
nSumWeeklyTPV = 0;
|
||||
nSumWeeklyVol = 0;
|
||||
}
|
||||
if(CreateDateTime(MONTHLY,rangeBarsIndicator.Time[nIdx])!=dtLastMonth)
|
||||
if(CreateDateTime(MONTHLY,customChartIndicator.Time[nIdx])!=dtLastMonth)
|
||||
{
|
||||
nIdxMonthly=nIdx;
|
||||
nSumMonthlyTPV = 0;
|
||||
@@ -289,45 +269,45 @@ int OnCalculate(const int rates_total,
|
||||
switch(Price_Type)
|
||||
{
|
||||
case OPEN:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Open[nIdx];
|
||||
nPriceArr[nIdx]=customChartIndicator.Open[nIdx];
|
||||
break;
|
||||
case CLOSE:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Close[nIdx];
|
||||
nPriceArr[nIdx]=customChartIndicator.Close[nIdx];
|
||||
break;
|
||||
case HIGH:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.High[nIdx];
|
||||
nPriceArr[nIdx]=customChartIndicator.High[nIdx];
|
||||
break;
|
||||
case LOW:
|
||||
nPriceArr[nIdx]=rangeBarsIndicator.Low[nIdx];
|
||||
nPriceArr[nIdx]=customChartIndicator.Low[nIdx];
|
||||
break;
|
||||
case HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/2;
|
||||
nPriceArr[nIdx]=(customChartIndicator.High[nIdx]+customChartIndicator.Low[nIdx])/2;
|
||||
break;
|
||||
case OPEN_CLOSE:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Open[nIdx]+rangeBarsIndicator.Close[nIdx])/2;
|
||||
nPriceArr[nIdx]=(customChartIndicator.Open[nIdx]+customChartIndicator.Close[nIdx])/2;
|
||||
break;
|
||||
case CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/3;
|
||||
nPriceArr[nIdx]=(customChartIndicator.Close[nIdx]+customChartIndicator.High[nIdx]+customChartIndicator.Low[nIdx])/3;
|
||||
break;
|
||||
case OPEN_CLOSE_HIGH_LOW:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Open[nIdx]+rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/4;
|
||||
nPriceArr[nIdx]=(customChartIndicator.Open[nIdx]+customChartIndicator.Close[nIdx]+customChartIndicator.High[nIdx]+customChartIndicator.Low[nIdx])/4;
|
||||
break;
|
||||
default:
|
||||
nPriceArr[nIdx]=(rangeBarsIndicator.Close[nIdx]+rangeBarsIndicator.High[nIdx]+rangeBarsIndicator.Low[nIdx])/3;
|
||||
nPriceArr[nIdx]=(customChartIndicator.Close[nIdx]+customChartIndicator.High[nIdx]+customChartIndicator.Low[nIdx])/3;
|
||||
break;
|
||||
}
|
||||
|
||||
if((rangeBarsIndicator.Tick_volume[nIdx] > 0) && (rangeBarsIndicator.Real_volume[nIdx] == 0))
|
||||
if((customChartIndicator.Tick_volume[nIdx] > 0) && (customChartIndicator.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];
|
||||
// Print("tick vol = "+customChartIndicator.Tick_volume[nIdx]);
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * customChartIndicator.Tick_volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)customChartIndicator.Tick_volume[nIdx];
|
||||
}
|
||||
else if(rangeBarsIndicator.Real_volume[nIdx] && rangeBarsIndicator.Tick_volume[nIdx] )
|
||||
else if(customChartIndicator.Real_volume[nIdx] && customChartIndicator.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];
|
||||
// Print("real vol = "+customChartIndicator.Real_volume[nIdx]);
|
||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * customChartIndicator.Real_volume[nIdx]);
|
||||
nTotalVol[nIdx] = (double)customChartIndicator.Real_volume[nIdx];
|
||||
}
|
||||
|
||||
if(Enable_Daily && (nIdx>=nIdxDaily))
|
||||
@@ -375,9 +355,9 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
}
|
||||
|
||||
dtLastDay=CreateDateTime(DAILY,rangeBarsIndicator.Time[nIdx]);
|
||||
dtLastWeek=CreateDateTime(WEEKLY,rangeBarsIndicator.Time[nIdx]);
|
||||
dtLastMonth=CreateDateTime(MONTHLY,rangeBarsIndicator.Time[nIdx]);
|
||||
dtLastDay=CreateDateTime(DAILY,customChartIndicator.Time[nIdx]);
|
||||
dtLastWeek=CreateDateTime(WEEKLY,customChartIndicator.Time[nIdx]);
|
||||
dtLastMonth=CreateDateTime(MONTHLY,customChartIndicator.Time[nIdx]);
|
||||
}
|
||||
|
||||
bIsFirstRun=false;
|
||||
|
||||
Binary file not shown.
@@ -31,7 +31,7 @@ double deviation; // deviation in points
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -132,16 +132,15 @@ int OnCalculate(const int rates_total,
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int i=0;
|
||||
@@ -204,12 +203,12 @@ int OnCalculate(const int rates_total,
|
||||
//--- searching High and Low
|
||||
for(shift=limit;shift<rates_total && !IsStopped();shift++)
|
||||
{
|
||||
val=rangeBarsIndicator.Low[iLowest(rangeBarsIndicator.Low,ExtDepth,shift)];
|
||||
val=customChartIndicator.Low[iLowest(customChartIndicator.Low,ExtDepth,shift)];
|
||||
if(val==lastlow) val=0.0;
|
||||
else
|
||||
{
|
||||
lastlow=val;
|
||||
if((rangeBarsIndicator.Low[shift]-val)>deviation) val=0.0;
|
||||
if((customChartIndicator.Low[shift]-val)>deviation) val=0.0;
|
||||
else
|
||||
{
|
||||
for(back=1;back<=ExtBackstep;back++)
|
||||
@@ -219,14 +218,14 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
}
|
||||
}
|
||||
if(rangeBarsIndicator.Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
|
||||
if(customChartIndicator.Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
|
||||
//--- high
|
||||
val=rangeBarsIndicator.High[iHighest(rangeBarsIndicator.High,ExtDepth,shift)];
|
||||
val=customChartIndicator.High[iHighest(customChartIndicator.High,ExtDepth,shift)];
|
||||
if(val==lasthigh) val=0.0;
|
||||
else
|
||||
{
|
||||
lasthigh=val;
|
||||
if((val-rangeBarsIndicator.High[shift])>deviation) val=0.0;
|
||||
if((val-customChartIndicator.High[shift])>deviation) val=0.0;
|
||||
else
|
||||
{
|
||||
for(back=1;back<=ExtBackstep;back++)
|
||||
@@ -236,7 +235,7 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
}
|
||||
}
|
||||
if(rangeBarsIndicator.High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
|
||||
if(customChartIndicator.High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
|
||||
}
|
||||
|
||||
//--- last preparation
|
||||
@@ -262,7 +261,7 @@ int OnCalculate(const int rates_total,
|
||||
{
|
||||
if(HighMapBuffer[shift]!=0)
|
||||
{
|
||||
lasthigh=rangeBarsIndicator.High[shift];
|
||||
lasthigh=customChartIndicator.High[shift];
|
||||
lasthighpos=shift;
|
||||
whatlookfor=Sill;
|
||||
ZigzagBuffer[shift]=lasthigh;
|
||||
@@ -270,7 +269,7 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
if(LowMapBuffer[shift]!=0)
|
||||
{
|
||||
lastlow=rangeBarsIndicator.Low[shift];
|
||||
lastlow=customChartIndicator.Low[shift];
|
||||
lastlowpos=shift;
|
||||
whatlookfor=Pike;
|
||||
ZigzagBuffer[shift]=lastlow;
|
||||
|
||||
@@ -60,7 +60,7 @@ double dtosf2[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
@@ -110,33 +110,36 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(Close))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
// customChartIndicator.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[]
|
||||
// customChartIndicator.Open[] should be used instead of open[]
|
||||
// customChartIndicator.Low[] should be used instead of low[]
|
||||
// customChartIndicator.High[] should be used instead of high[]
|
||||
// customChartIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
// customChartIndicator.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
|
||||
// customChartIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) customChartIndicator.SetGetTimeFlag() must be called in OnInit() for customChartIndicator.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
|
||||
// customChartIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// customChartIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) customChartIndicator.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
|
||||
// customChartIndicator.Price[] should be used instead of Price[]
|
||||
// (!) customChartIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for customChartIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -155,7 +158,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
|
||||
|
||||
for (int i=(int)MathMax(_prev_calculated-1,0); i<rates_total; i++)
|
||||
{
|
||||
rsibuf[i] = iRsi(rangeBarsIndicator.Close[i],RsiPeriod,i,rates_total);
|
||||
rsibuf[i] = iRsi(customChartIndicator.Close[i],RsiPeriod,i,rates_total);
|
||||
|
||||
double min = rsibuf[i];
|
||||
double max = rsibuf[i];
|
||||
|
||||
Binary file not shown.
@@ -5,6 +5,8 @@
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009-2017, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Adapted for use with TickChart by Artur Zas."
|
||||
|
||||
//---- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
@@ -12,7 +14,7 @@
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 Green,Red
|
||||
#property indicator_style1 0
|
||||
#property indicator_width1 1
|
||||
#property indicator_width1 2
|
||||
#property indicator_minimum 0.0
|
||||
//--- input data
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
@@ -25,11 +27,12 @@ double ExtColorsBuffer[];
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -43,7 +46,7 @@ void OnInit()
|
||||
//---- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
|
||||
rangeBarsIndicator.SetGetVolumesFlag();
|
||||
customChartIndicator.SetGetVolumesFlag();
|
||||
//----
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -63,38 +66,41 @@ int OnCalculate(const int rates_total,
|
||||
//---check for rates total
|
||||
if(rates_total<2)
|
||||
return(0);
|
||||
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
// Process data through XTickChart indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
// customChartIndicator.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[]
|
||||
// customChartIndicator.Open[] should be used instead of open[]
|
||||
// customChartIndicator.Low[] should be used instead of low[]
|
||||
// customChartIndicator.High[] should be used instead of high[]
|
||||
// customChartIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
// customChartIndicator.IsNewBar (true/false) informs you if a bar has 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
|
||||
// customChartIndicator.Time[] shold be used instead of Time[] for checking the tick chart bar time.
|
||||
// (!) customChartIndicator.SetGetTimeFlag() must be called in OnInit() for customChartIndicator.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
|
||||
// customChartIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// customChartIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) customChartIndicator.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
|
||||
// customChartIndicator.Price[] should be used instead of Price[]
|
||||
// (!) customChartIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for customChartIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
@@ -105,10 +111,11 @@ int OnCalculate(const int rates_total,
|
||||
//--- correct position
|
||||
if(start<1) start=1;
|
||||
//--- main cycle
|
||||
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateVolume(start,rates_total,rangeBarsIndicator.Tick_volume);
|
||||
CalculateVolume(start,rates_total,customChartIndicator.Tick_volume);
|
||||
else
|
||||
CalculateVolume(start,rates_total,rangeBarsIndicator.Real_volume);
|
||||
CalculateVolume(start,rates_total,customChartIndicator.Real_volume);
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user