version 3.14

This commit is contained in:
Artur
2021-04-28 17:27:12 +02:00
parent a73e2c0713
commit 380071b195
131 changed files with 5283 additions and 235 deletions
Binary file not shown.
+175
View File
@@ -0,0 +1,175 @@
//+------------------------------------------------------------------+
//| ma cross.mq5 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLightSeaGreen
#property indicator_width1 2
#property indicator_label1 "Bull ADX Cross"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2
#property indicator_label2 "Bear ADX Cross"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
input int AdxPeriod = 14; // ADX period
input bool alertsOn = true; // Turn alerts on?
input bool alertsOnCurrent = false; // Alert on current bar?
input bool alertsMessage = true; // Display messages 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 int lookback = 256; // Maximum lookback period
double crossUp[],crossDn[],cross[];
#include <IncOnRingBuffer\CATROnRingBuffer.mqh>
#include <IncOnRingBuffer\CADXOnRingBuffer.mqh>
CATROnRingBuffer atr;
CADXOnRingBuffer adx;
int _start = 0;
//
// Initialize custom chart indicator for data processing
// according to settings of the custom chart indicator already on chart
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,crossUp,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,233);
SetIndexBuffer(1,crossDn,INDICATOR_DATA); PlotIndexSetInteger(1,PLOT_ARROW,234);
SetIndexBuffer(2,cross);
if(!adx.Init(AdxPeriod,MODE_EMA,lookback)) return(INIT_FAILED);
if(!atr.Init(15,MODE_SMA,lookback)) return(INIT_FAILED);
customChartIndicator.SetGetTimeFlag();
IndicatorSetString(INDICATOR_SHORTNAME,"ADX cross "+(string)AdxPeriod+")");
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
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();
atr.MainOnArray(rates_total,_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close);
adx.MainOnArray(rates_total,_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close);
ArraySetAsSeries(customChartIndicator.Low, false);
ArraySetAsSeries(customChartIndicator.High, false);
if(_prev_calculated==0)
{
_start = rates_total-adx.Size()+1;
}
else
_start = MathMax(_prev_calculated-1,1);
for(int i=_start;i<rates_total;i++)
{
int ix = rates_total-1-i;
cross[i] = (ix>0) ? (adx.pdi[ix]>adx.ndi[ix]) ? 1 : (adx.pdi[ix]<adx.ndi[ix]) ? 2 : cross[i-1] : 0;
crossUp[i] = EMPTY_VALUE;
crossDn[i] = EMPTY_VALUE;
if (i>0 && cross[i]!=cross[i-1])
{
if (cross[i] == 1) crossUp[i] = customChartIndicator.Low[i]-atr[ix];
if (cross[i] == 2) crossDn[i] = customChartIndicator.High[i]+atr[ix];
}
}
manageAlerts(customChartIndicator.Time,cross,rates_total);
return (rates_total);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
void manageAlerts(const datetime& _time[], double& _trend[], int bars)
{
if (alertsOn)
{
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," plus DI crossing minus DI up");
if (_trend[whichBar] == 2) doAlert(time1," plus DI crossing minus DI down");
}
}
}
//
//
//
//
//
void doAlert(datetime forTime, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
if (previousAlert != doWhat || previousTime != forTime)
{
previousAlert = doWhat;
previousTime = forTime;
//
//
//
//
//
string message = TimeToString(TimeLocal(),TIME_SECONDS)+" "+_Symbol+" Adx "+doWhat;
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(_Symbol+"Adx",message);
if (alertsNotify) SendNotification(message);
if (alertsSound) PlaySound("alert2.wav");
}
}
Binary file not shown.
@@ -40,17 +40,11 @@ double ExtTmpBuffer[];
//--- global variables
int ExtADXPeriod;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
@@ -99,15 +93,42 @@ int OnCalculate(const int rates_total,
const int &Spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
//--- checking for bars count
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,6 @@
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Average True Range"
#property description "Adapted for use with TickChart by Artur Zas."
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
@@ -22,15 +21,10 @@ double ExtTRBuffer[];
//--- global variable
int ExtPeriodATR;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -72,16 +66,44 @@ int OnCalculate(const int rates_total,
const long &volume[],
const int &spread[])
{
//
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
int i,limit;
Binary file not shown.
Binary file not shown.
@@ -26,8 +26,7 @@ double ExtSlowBuffer[];
//
#include <MovingAverages.mqh>
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
Binary file not shown.
Binary file not shown.
Binary file not shown.
+83
View File
@@ -0,0 +1,83 @@
//+------------------------------------------------------------------
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property link "https://www.mql5.com"
#property description "CCI (alternative)"
//+------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_label1 "CCI alternative"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDarkGray,clrSkyBlue,clrDodgerBlue
#property indicator_width1 2
//--- input parameters
input int inpPeriod=14; // CCI period
//--- buffers and global variables declarations
double val[],valc[],prices[];
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,val,INDICATOR_DATA);
SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,prices,INDICATOR_CALCULATIONS);
//---
IndicatorSetString(INDICATOR_SHORTNAME,"CCI (alternative)("+(string)inpPeriod+")");
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator de-initialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
///
if(Bars(_Symbol,_Period)<rates_total) return(_prev_calculated);
int i=(int)MathMax(_prev_calculated-1,1); for(; i<rates_total && !_StopFlag; i++)
{
int _start=MathMax(i-inpPeriod+1,0);
prices[i]=(customChartIndicator.High[ArrayMaximum(customChartIndicator.High,_start,inpPeriod)]+customChartIndicator.Low[ArrayMinimum(customChartIndicator.Low,_start,inpPeriod)]+customChartIndicator.Close[i])/3;
double avg = 0; for(int k=0; k<inpPeriod && (i-k)>=0; k++) avg += prices[i-k]; avg /= inpPeriod;
double dev = 0; for(int k=0; k<inpPeriod && (i-k)>=0; k++) dev += MathAbs(prices[i-k]-avg); dev /= inpPeriod;
val[i] = (dev!=0) ? (prices[i]-avg)/(0.015*dev) : 0;
valc[i]=(i>0) ?(val[i]>val[i-1]) ? 1 :(val[i]<val[i-1]) ? 2 : valc[i-1]: 0;
}
return (i);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -8,7 +8,6 @@
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Commodity Channel Index"
#property description "Adapted for use with TickChart by Artur Zas."
#include <MovingAverages.mqh>
//---
#property indicator_separate_window
@@ -30,15 +29,10 @@ double ExtDBuffer[];
double ExtMBuffer[];
double ExtCCIBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -103,7 +97,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(Close))
return(0);
Binary file not shown.
+145
View File
@@ -0,0 +1,145 @@
//+------------------------------------------------------------------+
//| CHV.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Chaikin Volatility"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
//--- enum
enum SmoothMethod
{
SMA=0,// Simple MA
EMA=1 // Exponential MA
};
//--- input parameters
input int InpSmoothPeriod=10; // Smoothing period
input int InpCHVPeriod=10; // CHV period
input SmoothMethod InpSmoothType=EMA; // Smoothing method
//---- buffers
double ExtCHVBuffer[];
double ExtHLBuffer[];
double ExtSHLBuffer[];
//--- global variables
int ExtSmoothPeriod,ExtCHVPeriod;
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input variables
string MAName;
//--- set MA name
if(InpSmoothType==SMA)
MAName="SMA";
else
MAName="EMA";
//--- check inputs
if(InpSmoothPeriod<=0)
{
ExtSmoothPeriod=10;
printf("Incorrect value for input variable InpSmoothPeriod=%d. Indicator will use value=%d for calculations.",InpSmoothPeriod,ExtSmoothPeriod);
}
else ExtSmoothPeriod=InpSmoothPeriod;
if(InpCHVPeriod<=0)
{
ExtCHVPeriod=10;
printf("Incorrect value for input variable InpCHVPeriod=%d. Indicator will use value=%d for calculations.",InpCHVPeriod,ExtCHVPeriod);
}
else ExtCHVPeriod=InpCHVPeriod;
//---- define buffers
SetIndexBuffer(0,ExtCHVBuffer);
SetIndexBuffer(1,ExtHLBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtSHLBuffer,INDICATOR_CALCULATIONS);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtSmoothPeriod+ExtCHVPeriod-1);
//--- set index label
PlotIndexSetString(0,PLOT_LABEL,"CHV("+string(ExtSmoothPeriod)+","+MAName+")");
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"Chaikin Volatility("+string(ExtSmoothPeriod)+","+MAName+")");
//--- round settings
IndicatorSetInteger(INDICATOR_DIGITS,1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- variables of indicator
int i,pos,posCHV;
//--- check for rates total
posCHV=ExtCHVPeriod+ExtSmoothPeriod-2;
if(rates_total<posCHV)
return(0);
//
// Process data through MedianRenko indicator
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
//
//
//
//--- start working
if(_prev_calculated<1)
pos=0;
else pos=_prev_calculated-1;
//--- fill H-L(i) buffer
for(i=pos;i<rates_total && !IsStopped();i++) ExtHLBuffer[i]=customChartIndicator.High[i]-customChartIndicator.Low[i];
//--- calculate smoothed H-L(i) buffer
if(pos<ExtSmoothPeriod-1)
{
pos=ExtSmoothPeriod-1;
for(i=0;i<pos;i++) ExtSHLBuffer[i]=0.0;
}
if(InpSmoothType==SMA)
SimpleMAOnBuffer(rates_total,_prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
else
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
//--- correct calc position
if(pos<posCHV) pos=posCHV;
//--- calculate CHV buffer
for(i=pos;i<rates_total && !IsStopped();i++)
{
if(ExtSHLBuffer[i-ExtCHVPeriod]!=0.0)
ExtCHVBuffer[i]=100.0*(ExtSHLBuffer[i]-ExtSHLBuffer[i-ExtCHVPeriod])/ExtSHLBuffer[i-ExtCHVPeriod];
else
ExtCHVBuffer[i]=0.0;
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
Binary file not shown.
@@ -55,15 +55,10 @@ double dtoss[];
double dtosf1[];
double dtosf2[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -112,7 +107,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(Close))
return(0);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+133
View File
@@ -0,0 +1,133 @@
//+------------------------------------------------------------------+
//| Envelopes.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_label1 "Upper band"
#property indicator_label2 "Lower band"
//--- input parameters
input int InpMAPeriod=14; // Period
input int InpMAShift=0; // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
input double InpDeviation=0.1; // Deviation
//--- indicator buffers
double ExtUpBuffer[];
double ExtDownBuffer[];
double ExtMABuffer[];
int weightSum;
//--- MA handle
//int ExtMAHandle;
#include <MovingAverages.mqh>
#include <AZ-INVEST/CustomBarConfig.mqh>
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtUpBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtDownBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtMABuffer,INDICATOR_CALCULATIONS);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1);
//--- name for DataWindow
IndicatorSetString(INDICATOR_SHORTNAME,"Env("+string(InpMAPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"Env("+string(InpMAPeriod)+")Upper");
PlotIndexSetString(1,PLOT_LABEL,"Env("+string(InpMAPeriod)+")Lower");
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpMAShift);
//---
customChartIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Envelopes |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,
const datetime &Time[],
const double &Open[],
const double &High[],
const double &Low[],
const double &Close[],
const long &TickVolume[],
const long &Volume[],
const int &Spread[])
{
int i,limit;
//--- check for bars count
if(rates_total<InpMAPeriod)
return(0);
//--
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time,Close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(Close))
return(0);
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 ma buffer
if(IsStopped()) return(0); //Checking for stop flag
switch(InpMAMethod)
{
case MODE_SMA:
SimpleMAOnBuffer(rates_total,_prev_calculated,0,InpMAPeriod,customChartIndicator.Price,ExtMABuffer);
break;
case MODE_EMA:
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpMAPeriod,customChartIndicator.Price,ExtMABuffer);
break;
case MODE_SMMA:
SmoothedMAOnBuffer(rates_total,_prev_calculated,0,InpMAPeriod,customChartIndicator.Price,ExtMABuffer);
break;
case MODE_LWMA:
LinearWeightedMAOnBuffer(rates_total,_prev_calculated,0,InpMAPeriod,customChartIndicator.Price,ExtMABuffer,weightSum);
break;
}
//--- preliminary calculations
limit=_prev_calculated-1;
if(limit<InpMAPeriod)
limit=InpMAPeriod;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
ExtUpBuffer[i]=(1+InpDeviation/100.0)*ExtMABuffer[i];
ExtDownBuffer[i]=(1-InpDeviation/100.0)*ExtMABuffer[i];
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -21,15 +21,10 @@ double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int ExtArrowShift=-10;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -66,15 +61,42 @@ int OnCalculate(const int rates_total,const int prev_calculated,
const int &Spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
int i,limit;
Binary file not shown.
Binary file not shown.
@@ -19,8 +19,7 @@
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
Binary file not shown.
@@ -31,15 +31,10 @@ int ma_high_handle;
int ma_low_handle;
int period;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -97,15 +92,42 @@ int OnCalculate(const int rates_total,
if(rates_total<period+1)return(0);
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
ArraySetAsSeries(customChartIndicator.Close,true);
Binary file not shown.
Binary file not shown.
+395
View File
@@ -0,0 +1,395 @@
//+------------------------------------------------------------------+
//| HalfTrend.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 10
#property indicator_plots 6
//--- plot
#property indicator_label1 "UP"
#property indicator_color1 MediumOrchid // up[] DodgerBlue
#property indicator_type1 DRAW_LINE
#property indicator_width1 2
#property indicator_label2 "DN"
#property indicator_color2 Red // down[]
#property indicator_type2 DRAW_LINE
#property indicator_width2 2
#property indicator_label3 "ATR-LOW"
#property indicator_color3 Red // atrlo[],atrhi[]
#property indicator_type3 DRAW_LINE //
#property indicator_width3 1
#property indicator_label4 "ATR-HIGH"
#property indicator_color4 MediumOrchid // atrlo[],atrhi[]
#property indicator_type4 DRAW_LINE //From Histogram
#property indicator_width4 1
#property indicator_label5 "ARR-UP"
#property indicator_color5 MediumOrchid // arrdwn[]
#property indicator_type5 DRAW_ARROW
#property indicator_width5 1
#property indicator_label6 "ARR-DN"
#property indicator_color6 Red // arrup[]
#property indicator_type6 DRAW_ARROW
#property indicator_width6 1
input int Diamond = 2;
input int ChannelDeviation = 2;
input bool ShowChannels = true;
input bool ShowArrows = true;
input bool alertsOn = false;
input bool alertsOnCurrent = false;
input bool alertsMessage = true;
input bool alertsSound = true;
input bool alertsEmail = false;
input int lookback = 256; // Maximum lookback period
bool nexttrend;
double minhighprice, maxlowprice;
double up[], down[], atrlo[], atrhi[], trend[];
double arrup[], arrdwn[];
//int ind_mahi, ind_malo, ind_atr;
//double iMAHigh[], iMALow[], iATRx[];
#include <AZ-INVEST/CustomBarConfig.mqh>
#include <AZ-INVEST/SDK/IndicatorAccess.mqh>
#include <IncOnRingBuffer\CATROnRingBuffer.mqh>
#include <IncOnRingBuffer\CMAOnRingBuffer.mqh>
CIndicatorAccess iAccess;
CATROnRingBuffer atr;
CMAOnRingBuffer maHigh;
CMAOnRingBuffer maLow;
//iMAHigh, iMALow, iATRx
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, up, INDICATOR_DATA);
SetIndexBuffer(1, down, INDICATOR_DATA);
SetIndexBuffer(2, atrlo, INDICATOR_DATA);
SetIndexBuffer(3, atrhi, INDICATOR_DATA);
SetIndexBuffer(4, arrup, INDICATOR_DATA);
SetIndexBuffer(5, arrdwn, INDICATOR_DATA);
SetIndexBuffer(6, trend, INDICATOR_CALCULATIONS);
// SetIndexBuffer(7, iMAHigh, INDICATOR_CALCULATIONS);
// SetIndexBuffer(8, iMALow, INDICATOR_CALCULATIONS);
// SetIndexBuffer(9, iATRx, INDICATOR_CALCULATIONS);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
ArraySetAsSeries(up, true);
ArraySetAsSeries(down, true);
ArraySetAsSeries(atrlo, true);
ArraySetAsSeries(atrhi, true);
ArraySetAsSeries(arrup, true);
ArraySetAsSeries(arrdwn, true);
ArraySetAsSeries(trend, true);
// ArraySetAsSeries(iMAHigh, true);
// ArraySetAsSeries(iMALow, true);
// ArraySetAsSeries(iATRx, true);
if(ShowChannels)
{
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,clrDodgerBlue);
PlotIndexSetInteger(3,PLOT_LINE_COLOR,0,clrRed);
PlotIndexSetInteger(2,PLOT_LINE_STYLE,STYLE_DOT);
PlotIndexSetInteger(3,PLOT_LINE_STYLE,STYLE_DOT);
}
else
{
PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,clrNONE);
PlotIndexSetInteger(3,PLOT_LINE_COLOR,0,clrNONE);
}
if(ShowArrows)
{
bool rep5= PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_ARROW);
bool rep6=PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(4, PLOT_ARROW, 233); //233
PlotIndexSetInteger(5, PLOT_ARROW, 234); //234
//Comment(ShowArrows +"\n"+rep5 +"\n"+ rep6);
}
else
{ PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_NONE);
PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_NONE);
}
//ind_mahi = iMA(NULL, 0, Diamond, 0, MODE_SMA, PRICE_HIGH);
//ind_malo = iMA(NULL, 0, Diamond, 0, MODE_SMA, PRICE_LOW);
//ind_atr = iATR(NULL, 0, 100);
//if(ind_mahi == INVALID_HANDLE || ind_mahi == INVALID_HANDLE || ind_atr == INVALID_HANDLE)
// {
// PrintFormat("Failed to create handle of the indicators, error code %d", GetLastError());
// return(INIT_FAILED);
//}
customChartIndicator.SetGetTimeFlag();
if(!atr.Init(100,MODE_SMA,lookback))
{
PrintFormat("Failed to create ATR on ring buffer");
return(INIT_FAILED);
}
if(!maHigh.Init(Diamond, MODE_SMA, lookback))
{
PrintFormat("Failed to create maHigh on ring buffer");
return(INIT_FAILED);
}
if(!maLow.Init(Diamond, MODE_SMA, lookback))
{
PrintFormat("Failed to create maLow on ring buffer");
return(INIT_FAILED);
}
nexttrend = 0;
minhighprice = iHigh(NULL, 0, Bars(NULL, 0) - 1); // ?
maxlowprice = iLow(NULL, 0, Bars(NULL, 0) - 1); // ?
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |`
//+------------------------------------------------------------------+
int OnCalculate(
const int rates_total, // size of input time series
const int prev_calculated, // number of handled bars at the previous call
const datetime& time[], // Time array
const double& open[], // Open array
const double& high[], // High array
const double& low[], // Low array
const double& close[], // Close array
const long& tick_volume[], // Tick Volume array
const long& volume[], // Real Volume array
const int& spread[] // Spread array
)
{
//
// Process data through custom chart indicator
//
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 = ArraySize(customChartIndicator.Close);
//
int i, limit, to_copy;
double _atr, lowprice_i, highprice_i, lowma, highma;
ArraySetAsSeries(customChartIndicator.Time, true);
ArraySetAsSeries(customChartIndicator.High, true);
ArraySetAsSeries(customChartIndicator.Low, true);
ArraySetAsSeries(customChartIndicator.Close, true);
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 += 10;
}
// if(!RefreshBuffers(iMAHigh, iMALow, iATRx, ind_mahi, ind_malo, ind_atr, to_copy))
// return(0);
atr.MainOnArray(_rates_total,_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close);
maHigh.MainOnArray(_rates_total, _prev_calculated, customChartIndicator.High);
maLow.MainOnArray(_rates_total, _prev_calculated, customChartIndicator.Low);
//
if(_prev_calculated == 0)
limit = _rates_total - 2;
else
limit = _rates_total - _prev_calculated + 1;
for(i = limit; i >= 0; i--)
{
//lowprice_i = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, Diamond, i));
//highprice_i = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, Diamond, i));
//lowma = NormalizeDouble(iMALow[i], _Digits);
//highma = NormalizeDouble(iMAHigh[i], _Digits);
lowprice_i = customChartIndicator.Low[iAccess.Lowest(customChartIndicator.Low, Diamond, i)];
highprice_i = customChartIndicator.High[iAccess.Highest(customChartIndicator.High, Diamond, i)];
lowma = NormalizeDouble(maLow[i], _Digits);
highma = NormalizeDouble(maHigh[i], _Digits);
//
trend[i] = trend[i + 1];
//atr = iATRx[i] / 2;
_atr = atr[i] / 2;
arrup[i] = EMPTY_VALUE;
arrdwn[i] = EMPTY_VALUE;
if(trend[i + 1] != 1.0)
{
maxlowprice = MathMax(lowprice_i, maxlowprice);
if(highma < maxlowprice && customChartIndicator.Close[i] < customChartIndicator.Low[i + 1])
{
trend[i] = 1.0;
nexttrend = 0;
minhighprice = highprice_i;
}
}
else
{
minhighprice = MathMin(highprice_i, minhighprice);
if(lowma > minhighprice && customChartIndicator.Close[i] > customChartIndicator.High[i + 1])
{
trend[i] = 0.0;
nexttrend = 1;
maxlowprice = lowprice_i;
}
}
//---
if(trend[i] == 0.0)
{
if(trend[i + 1] != 0.0)
{
up[i] = down[i + 1];
up[i + 1] = up[i];
arrup[i] = up[i] - 2 * _atr;
}
else
{
up[i] = MathMax(maxlowprice, up[i + 1]);
}
atrhi[i] = up[i] + ChannelDeviation*_atr;
atrlo[i] = up[i] - ChannelDeviation*_atr;
down[i] = 0.0;
}
else
{
if(trend[i + 1] != 1.0)
{
down[i] = up[i + 1];
down[i + 1] = down[i];
arrdwn[i] = down[i] + 2 * _atr;
}
else
{
down[i] = MathMin(minhighprice, down[i + 1]);
}
atrhi[i] = down[i] + ChannelDeviation*_atr;
atrlo[i] = down[i] - ChannelDeviation*_atr;
up[i] = 0.0;
}
}
manageAlerts();
return (rates_total);
}
/*
//+------------------------------------------------------------------+
//| Filling indicator buffers from the indicators |
//+------------------------------------------------------------------+
bool RefreshBuffers(double &hi_buffer[],
double &lo_buffer[],
double &atr_buffer[],
int hi_handle,
int lo_handle,
int atr_handle,
int amount
)
{
//--- reset error code
ResetLastError();
//--- fill a part of the iMACDBuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(hi_handle, 0, 0, amount, hi_buffer) < 0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the MaHigh indicator, error code %d", GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the SignalBuffer array with values from the indicator buffer that has index 1
if(CopyBuffer(lo_handle, 0, 0, amount, lo_buffer) < 0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the MaLow indicator, error code %d", GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- fill a part of the StdDevBuffer array with values from the indicator buffer
if(CopyBuffer(atr_handle, 0, 0, amount, atr_buffer) < 0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the ATR indicator, error code %d", GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
//--- everything is fine
return(true);
}
*/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void manageAlerts()
{
int whichBar;
if (alertsOn)
{
if (alertsOnCurrent)
whichBar = 0;
else
whichBar = 1;
if (arrup[whichBar] != EMPTY_VALUE) doAlert(whichBar, "up");
if (arrdwn[whichBar] != EMPTY_VALUE) doAlert(whichBar, "down");
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void doAlert(int forBar, string doWhat)
{
static string previousAlert = "nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != iTime(NULL, 0, forBar))
{
previousAlert = doWhat;
previousTime = iTime(NULL, 0, forBar);
message = StringFormat("%s at %s", Symbol(), TimeToString(TimeLocal(), TIME_SECONDS), " HalfTrend signal ", doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(Symbol(), StringFormat("HalfTrend %s", message));
if (alertsSound) PlaySound("alert2.wav");
}
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -20,15 +20,10 @@ double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -67,13 +62,38 @@ int OnCalculate(const int rates_total,
int i,limit;
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
Binary file not shown.
@@ -6,7 +6,6 @@
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
#property description "Adapted for use with TickChart by Artur Zas."
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
@@ -34,15 +33,10 @@ double ExtSpanABuffer[];
double ExtSpanBBuffer[];
double ExtChikouBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -116,13 +110,38 @@ int OnCalculate(const int rates_total,
const int &spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,8 +14,11 @@ 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;
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
void OnInit()
Binary file not shown.
@@ -21,15 +21,10 @@ input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE;
//--- indicator buffers
double ExtLineBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -197,16 +192,43 @@ int OnCalculate(const int rates_total,const int prev_calculated,
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
int _begin = 0;
//
//
//
//--- check for bars count
Binary file not shown.
@@ -6,8 +6,6 @@
#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
@@ -37,8 +35,11 @@ double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
double ExtMacdBuffer[];
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
@@ -72,36 +73,62 @@ int OnCalculate(const int rates_total,const int prev_calculated,
const long &Volume[],
const int &Spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = 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,customChartIndicator.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,customChartIndicator.Close,ExtSlowMaBuffer);
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpSlowEMA,customChartIndicator.Close,ExtSlowMaBuffer);
//---
int limit;
if(_prev_calculated==0)
@@ -109,7 +136,7 @@ int OnCalculate(const int rates_total,const int prev_calculated,
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)
@@ -124,9 +151,8 @@ 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);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -6,8 +6,6 @@
#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,8 +33,7 @@ double ExtMacdBuffer[];
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
@@ -78,13 +75,12 @@ int OnCalculate(const int rates_total,const int prev_calculated,
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();
//
//
//
@@ -100,7 +96,6 @@ 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);
Binary file not shown.
@@ -21,16 +21,12 @@ double ExtMomentumBuffer[];
//--- global variable
int ExtMomentumPeriod;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
@@ -88,15 +84,42 @@ int OnCalculate(const int rates_total,const int prev_calculated,
static int begin = 0;
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
//--- start calculation
Binary file not shown.
@@ -47,15 +47,10 @@ double Trend[];
double ATRBuffer[];
int Handle;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -106,13 +101,38 @@ int OnCalculate(const int rates_total,
)
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
Binary file not shown.
@@ -18,18 +18,11 @@ input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffer
double ExtOBVBuffer[];
//
// Initialize RangeBar indicator for data processing
// according to settings of the RangeBar indicator already on chart
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
//| On Balance Volume initialization function |
@@ -60,12 +53,12 @@ int OnCalculate(const int rates_total,
const int &spread[])
{
//
// Process data through RangeBar indicator
// Process data through MedianRenko indicator
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
Binary file not shown.
+679
View File
@@ -0,0 +1,679 @@
//+------------------------------------------------------------------+
//| Oscillator Candles.mq5 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property description"Oscillator Candles by pipPod"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots 1
//---
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrLimeGreen,clrFireBrick
//---
#property indicator_levelcolor clrLightSlateGray
//---
double indicator_level1= 0;
double indicator_level2= 20;
double indicator_level3= 30;
double indicator_level4= 50;
double indicator_level5= 70;
double indicator_level6= 80;
double indicator_level7= 100;
double indicator_level8=-100;
//---
#include <MovingAverages.mqh>
#include <AZ-INVEST/CustomBarConfig.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum indicators
{
INDICATOR_MACD, //Moving Average Convergence/Divergence
INDICATOR_STOCHASTIC, //Stochastic Oscillator
INDICATOR_RSI, //Relative Strength Index
INDICATOR_CCI, //Commodity Channel Index
INDICATOR_MOMENTUM, //Momentum Index
};
//--- indicator to show
input indicators Indicator=INDICATOR_MACD;
//--- indicator parameters
input string MACD;
input ushort FastEMA=12; //Fast EMA Period
input ushort SlowEMA=26; //Slow EMA Period
//---
input string Stochastic;
input ushort Kperiod=7; //K Period
input ushort Slowing=3;
input ENUM_STO_PRICE PriceField=STO_LOWHIGH; //Price Field
//---
input string RSI;
input ushort RSIPeriod=14; //RSI Period
//---
input string CCI;
input ushort CCIPeriod=14; //CCI Period
//---
input string Momentum;
input ushort MomPeriod=14; //Momentum Period
//---
input string _; //---
input bool PriceLine=true; //Horizontal Value Line
#define priceLine "priceLine"
input bool AutoColor=false;//Auto Color Candles
//---index buffers for drawing candles
double OpenBuffer[];
double HighBuffer[];
double LowBuffer[];
double CloseBuffer[];
double ColorBuffer[];
//---Stochastic buffers
double HighesBuffer[];
double LowestBuffer[];
//---CCI buffers
double PriceBuffer[];
double MovAvBuffer[];
//---
long chartID=ChartID();
short window;
#define OBJ_NONE -1
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
string shortName;
switch(Indicator)
{
case INDICATOR_MACD:
shortName=StringFormat("MACD(%d,%d)",FastEMA,SlowEMA);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
IndicatorSetInteger(INDICATOR_LEVELS,1);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,indicator_level1);
PlotIndexSetString(0,PLOT_LABEL,"MACD Open;MACD High;MACD Low;MACD Close");
for(int i=0;i<5;i++)
PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,SlowEMA-1);
break;
case INDICATOR_STOCHASTIC:
shortName=StringFormat("Stochastic(%d,%d)",Kperiod,Slowing);
SetIndexBuffer(5,HighesBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,LowestBuffer,INDICATOR_CALCULATIONS);
IndicatorSetInteger(INDICATOR_DIGITS,0);
IndicatorSetInteger(INDICATOR_LEVELS,3);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,indicator_level2);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,indicator_level4);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,indicator_level6);
PlotIndexSetString(0,PLOT_LABEL,"Stoch Open;Stoch High;Stoch Low;Stoch Close");
for(int i=0;i<5;i++)
PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,Kperiod-1+Slowing-1);
break;
case INDICATOR_RSI:
shortName=StringFormat("RSI(%d)",RSIPeriod);
IndicatorSetInteger(INDICATOR_DIGITS,0);
IndicatorSetInteger(INDICATOR_LEVELS,3);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,indicator_level3);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,indicator_level4);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,indicator_level5);
PlotIndexSetString(0,PLOT_LABEL,"RSI Open;RSI High;RSI Low;RSI Close");
for(int i=0;i<5;i++)
PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,RSIPeriod-1);
break;
case INDICATOR_CCI:
shortName=StringFormat("CCI(%d)",CCIPeriod);
SetIndexBuffer(5,PriceBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,MovAvBuffer,INDICATOR_CALCULATIONS);
IndicatorSetInteger(INDICATOR_DIGITS,0);
IndicatorSetInteger(INDICATOR_LEVELS,3);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,indicator_level1);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,indicator_level7);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,indicator_level8);
PlotIndexSetString(0,PLOT_LABEL,"CCI Open;CCI High;CCI Low;CCI Close");
for(int i=0;i<5;i++)
PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,CCIPeriod-1);
break;
case INDICATOR_MOMENTUM:
shortName=StringFormat("Momentum(%d)",MomPeriod);
IndicatorSetInteger(INDICATOR_DIGITS,2);
IndicatorSetInteger(INDICATOR_LEVELS,1);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,indicator_level7);
PlotIndexSetString(0,PLOT_LABEL,"Mom Open;Mom High;Mom Low;Mom Close");
for(int i=0;i<5;i++)
PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,MomPeriod-1);
}
//---set name, get window
IndicatorSetString(INDICATOR_SHORTNAME,shortName);
window=(short)ChartWindowFind(chartID,shortName);
//---index buffers
SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);
SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);
SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);
//---color bars
if(AutoColor)
SetColors();
//---delete price line
if(!PriceLine && ObjectFind(chartID,priceLine)!=OBJ_NONE)
ObjectDelete(chartID,priceLine);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
//
//---bars to count
int toFill=rates_total-_prev_calculated;
if(_prev_calculated>0)
toFill++;
//---fill OHLC buffers
switch(Indicator)
{
case INDICATOR_MACD:
if(MACD(customChartIndicator.GetRatesTotal(),_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close)!=toFill)
return(0);
break;
case INDICATOR_STOCHASTIC:
if(Stochastic(customChartIndicator.GetRatesTotal(),_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close)!=toFill)
return(0);
break;
case INDICATOR_RSI:
if(RSI(customChartIndicator.GetRatesTotal(),_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close)!=toFill)
return(0);
break;
case INDICATOR_CCI:
if(CCI(customChartIndicator.GetRatesTotal(),_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close)!=toFill)
return(0);
break;
case INDICATOR_MOMENTUM:
if(Momentum(customChartIndicator.GetRatesTotal(),_prev_calculated,customChartIndicator.High,customChartIndicator.Low,customChartIndicator.Close)!=toFill)
return(0);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Moving Average Convergence/Divergence |
//+------------------------------------------------------------------+
int MACD(const int rates_total,
const int prev_calculated,
const double &high[],
const double &low[],
const double &close[])
{
//---check bars and input vars
if(rates_total<=SlowEMA || FastEMA<=1 || SlowEMA<FastEMA)
return(0);
//---declare vars
int begin,count=0;
double highFast,highSlow,
lowFast,lowSlow,
closeFast,closeSlow;
static double prevCloseFast,prevCloseSlow;
//--- initial zero
if(prev_calculated==0)
{
for(int i=0;i<SlowEMA && !IsStopped();i++)
{
OpenBuffer[i]=HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
count++;
}
begin=SlowEMA;
}
else
begin=prev_calculated-1;
//--- calculate MACD
for(int i=begin;i<rates_total && !IsStopped();i++)
{
highFast = ExponentialMA(i,FastEMA,prevCloseFast,high);
highSlow = ExponentialMA(i,SlowEMA,prevCloseSlow,high);
lowFast = ExponentialMA(i,FastEMA,prevCloseFast,low);
lowSlow = ExponentialMA(i,SlowEMA,prevCloseSlow,low);
closeFast = ExponentialMA(i,FastEMA,prevCloseFast,close);
closeSlow = ExponentialMA(i,SlowEMA,prevCloseSlow,close);
//---fill OHLC buffers
HighBuffer[i]= highFast-highSlow;
LowBuffer[i] = lowFast-lowSlow;
CloseBuffer[i]=closeFast-closeSlow;
//---check for new bar
static int k;
if(k!=i)
{
prevCloseFast = closeFast;
prevCloseSlow = closeSlow;
OpenBuffer[i] = CloseBuffer[i-1];
k=i;
}
//---set candle color
ColorBuffer[i]=(CloseBuffer[i]>OpenBuffer[i])?0:1;
//---horizontal value line
if(PriceLine)
PriceLine(CloseBuffer[i]);
count++;
}
//--- macd done. return count.
return(count);
}
//+------------------------------------------------------------------+
//| Stochastic Oscillator |
//+------------------------------------------------------------------+
int Stochastic(const int rates_total,
const int prev_calculated,
const double &high[],
const double &low[],
const double &close[])
{
//--- check for bars count
if(rates_total<=Kperiod+Slowing || Kperiod<=1)
return(0);
//--- declare variables
int begin,count=0;
double sumLowH,sumLowL,sumLowC,sumHigh;
double min,max;
//---
begin=Kperiod-1;
if(begin<prev_calculated)
begin=prev_calculated-1;
else
for(int i=0;i<begin && !IsStopped();i++)
LowestBuffer[i]=HighesBuffer[i]=0.0;
//--- calculate HighesBuffer[] and LowestBuffer[]
for(int i=begin;i<rates_total && !IsStopped();i++)
{
min = 1000000.0;
max =-1000000.0;
for(int k=(i-Kperiod+1);k<=i;k++)
{
switch(PriceField)
{
case STO_LOWHIGH:
if(min>low[k])
min=low[k];
if(max<high[k])
max=high[k];
break;
case STO_CLOSECLOSE:
if(min>close[k])
min=close[k];
if(max<close[k])
max=close[k];
}
}
LowestBuffer[i] = min;
HighesBuffer[i] = max;
}
//--- %K
begin=Kperiod-1;
if(begin<prev_calculated)
begin=prev_calculated-1;
else
for(int i=0;i<begin && !IsStopped();i++)
{
OpenBuffer[i]=HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
count++;
}
//--- main cycle
for(int i=begin;i<rates_total && !IsStopped();i++)
{
sumLowH=sumLowL=sumLowC=sumHigh=0.0;
for(int k=(i-Slowing+1);k<=i;k++)
{
sumLowH += (high[i]-LowestBuffer[k]);
sumLowL += (low[i]-LowestBuffer[k]);
sumLowC += (close[k]-LowestBuffer[k]);
sumHigh += (HighesBuffer[k]-LowestBuffer[k]);
}
//---check for new bar
static int k;
if(k!=i)
{
OpenBuffer[i]=CloseBuffer[i-1];
k=i;
}
//---check zero divide and fill candle buffers
if(sumHigh==0.0)
HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=50.0;
else
{
HighBuffer[i]= OpenBuffer[i]+(sumLowH/sumHigh*100-OpenBuffer[i])/Slowing;
LowBuffer[i] = OpenBuffer[i]+(sumLowL/sumHigh*100-OpenBuffer[i])/Slowing;
CloseBuffer[i]=sumLowC/sumHigh*100;
}
//---set candle color
ColorBuffer[i]=(CloseBuffer[i]>OpenBuffer[i])?0:1;
//---horizontal value line
if(PriceLine)
PriceLine(CloseBuffer[i]);
count++;
}
//--- stochastic done. return count.
return(count);
}
//+------------------------------------------------------------------+
//| Relative Strength index |
//+------------------------------------------------------------------+
int RSI(const int rates_total,
const int prev_calculated,
const double &high[],
const double &low[],
const double &close[])
{
//--- check bars and input vars
if(rates_total<=RSIPeriod || RSIPeriod<=1)
return(0);
int begin,count=0;
//--- declare vars
double diffC,
diffH,
diffL;
double currPositive = 0.0,
currNegative = 0.0;
static double prevPositive = 0.0,
prevNegative = 0.0;
//--- preliminary calculations
begin=prev_calculated-1;
if(begin<=RSIPeriod)
{
//--- first RSIPeriod values of the indicator are not calculated
OpenBuffer[0]=HighBuffer[0]=LowBuffer[0]=CloseBuffer[0]=0.0;
double sumPositive = 0.0,
sumNegative = 0.0;
count++;
for(int i=1;i<=RSIPeriod && !IsStopped();i++)
{
OpenBuffer[i]=HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
diffC=close[i]-close[i-1];
sumPositive += (diffC>0.0? diffC:0.0);
sumNegative += (diffC<0.0?-diffC:0.0);
count++;
}
//--- calculate first visible value
currPositive = sumPositive/RSIPeriod;
currNegative = sumNegative/RSIPeriod;
//--- check zero divide, calculate first rsi and fill candle buffers
if(currNegative!=0.0)
OpenBuffer[RSIPeriod]=HighBuffer[RSIPeriod]=LowBuffer[RSIPeriod]=
CloseBuffer[RSIPeriod]=100.0-100.0/(1.0+currPositive/currNegative);
else
if(currPositive!=0.0)
OpenBuffer[RSIPeriod]=HighBuffer[RSIPeriod]=LowBuffer[RSIPeriod]=
CloseBuffer[RSIPeriod]=100.0;
else
OpenBuffer[RSIPeriod]=HighBuffer[RSIPeriod]=LowBuffer[RSIPeriod]=
CloseBuffer[RSIPeriod]=50.0;
prevPositive = currPositive;
prevNegative = currNegative;
//--- prepare the position value for main calculation
begin=RSIPeriod+1;
}
//--- the main loop of calculations
for(int i=begin;i<rates_total && !IsStopped();i++)
{
diffC = close[i]-close[i-1];
diffH = (high[i]-close[i-1])/RSIPeriod;
diffL = (low[i]-close[i-1])/RSIPeriod;
currPositive = (prevPositive*(RSIPeriod-1)+(diffC>0.0? diffC:0.0))/RSIPeriod;
currNegative = (prevNegative*(RSIPeriod-1)+(diffC<0.0?-diffC:0.0))/RSIPeriod;
//--- check zero divide, calculate rsi and fill candle buffers
if(prevNegative!=0.0)
{
HighBuffer[i]= 100.0-100.0/(1.0+(prevPositive+diffH)/prevNegative);
LowBuffer[i] = 100.0-100.0/(1.0+prevPositive/(prevNegative-diffL));
}
else
if(prevPositive!=0.0)
HighBuffer[i]= LowBuffer[i] = 100.0;
else
HighBuffer[i]=LowBuffer[i]=50.0;
if(currNegative!=0.0)
CloseBuffer[i]=100.0-100.0/(1.0+currPositive/currNegative);
else
if(currPositive!=0.0)
CloseBuffer[i]=100.0;
else
CloseBuffer[i]=50.0;
//---check for new bar
static int k;
if(k!=i)
{
prevPositive = currPositive;
prevNegative = currNegative;
OpenBuffer[i]= CloseBuffer[i-1];
k=i;
}
//---set candle color
ColorBuffer[i]=(CloseBuffer[i]>OpenBuffer[i])?0:1;
//---horizontal value line
if(PriceLine)
PriceLine(CloseBuffer[i]);
count++;
}
//---rsi done.return count.
return(count);
}
//+------------------------------------------------------------------+
//| Commodity Channel Index |
//+------------------------------------------------------------------+
int CCI(const int rates_total,
const int prev_calculated,
const double &high[],
const double &low[],
const double &close[])
{
//--- check bars and input vars
if(rates_total<=CCIPeriod || CCIPeriod<=1)
return(0);
//--- declare vars
int begin,count=0;
double sum,mul;
//--- initial zero
if(prev_calculated<1)
{
for(int i=0;i<CCIPeriod-1 && !IsStopped();i++)
{
OpenBuffer[i]=HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
PriceBuffer[i] = (high[i]+low[i]+close[i])/3;
MovAvBuffer[i] = 0.0;
count++;
}
}
//--- calculate position
begin=prev_calculated-1;
if(begin<CCIPeriod-1)
begin=CCIPeriod-1;
//--- typical price and its moving average
for(int i=begin;i<rates_total && !IsStopped();i++)
{
PriceBuffer[i] = (high[i]+low[i]+close[i])/3;
MovAvBuffer[i] = SimpleMA(i,CCIPeriod,PriceBuffer);
}
//--- standard deviations and cci counting
mul=0.015/CCIPeriod;
begin=prev_calculated-1;
if(begin<CCIPeriod-1)
begin=CCIPeriod-1;
//---
for(int i=begin;i<rates_total && !IsStopped();i++)
{
sum=0.0;
int k=i-CCIPeriod+1;
while(k<=i)
{
sum+=MathAbs(PriceBuffer[k]-MovAvBuffer[i]);
k++;
}
sum*=mul;
//---check zero divide and fill candle buffers
if(sum==0.0)
HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
else
{
HighBuffer[i]=(high[i]-MovAvBuffer[i])/sum;
LowBuffer[i] =(low[i]-MovAvBuffer[i])/sum;
CloseBuffer[i]=(close[i]-MovAvBuffer[i])/sum;
}
//---check for new bar
static int m;
if(m!=i)
{
OpenBuffer[i]=CloseBuffer[i-1];
m=i;
}
//---set candle color
ColorBuffer[i]=(CloseBuffer[i]>OpenBuffer[i])?0:1;
//---horizontal value line
if(PriceLine)
PriceLine(CloseBuffer[i]);
count++;
}
//---cci done. return count.
return(count);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
int Momentum(const int rates_total,
const int prev_calculated,
const double &high[],
const double &low[],
const double &close[])
{
//--- check bars and input param
if(rates_total<=MomPeriod || MomPeriod<=0)
return(0);
int begin,count=0;
//--- initial zero
if(prev_calculated<=0)
{
for(int i=0;i<MomPeriod && !IsStopped();i++)
{
OpenBuffer[i]=HighBuffer[i]=LowBuffer[i]=CloseBuffer[i]=0.0;
count++;
}
begin=MomPeriod;
}
else
begin=prev_calculated-1;
static double closeMomPeriod;
//--- the main loop of calculations
for(int i=begin;i<rates_total && !IsStopped();i++)
{
//---check for new bar
static int k;
if(k!=i)
{
closeMomPeriod= close[i-MomPeriod];
// if(closeMomPeriod == 0)
// continue;
if(closeMomPeriod == 0)
closeMomPeriod = 1;
OpenBuffer[i] = CloseBuffer[i-1];
k=i;
}
HighBuffer[i]= high[i]*100/closeMomPeriod;
LowBuffer[i] = low[i]*100/closeMomPeriod;
CloseBuffer[i]=close[i]*100/closeMomPeriod;
//---set candle color
ColorBuffer[i]=(CloseBuffer[i]>OpenBuffer[i])?0:1;
//---horizontal value line
if(PriceLine)
PriceLine(CloseBuffer[i]);
count++;
}
//--- momentum done. return count
return(count);
}
//+------------------------------------------------------------------+
//| Horizontal value line |
//+------------------------------------------------------------------+
void PriceLine(const double &close_price)
{
if(ObjectFind(chartID,priceLine)!=OBJ_NONE)
ObjectDelete(chartID,priceLine);
if(!ObjectCreate(chartID,priceLine,OBJ_HLINE,window,0,close_price))
{
Print(__FUNCTION__,": error ",GetLastError());
return;
}
ObjectSetInteger(chartID,priceLine,OBJPROP_WIDTH,1);
ObjectSetInteger(chartID,priceLine,OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(chartID,priceLine,OBJPROP_COLOR,clrLightSlateGray);
ObjectSetInteger(chartID,priceLine,OBJPROP_HIDDEN,true);
ObjectSetInteger(chartID,priceLine,OBJPROP_SELECTABLE,false);
return;
}
//+------------------------------------------------------------------+
//| Auto colors for candles |
//+------------------------------------------------------------------+
bool SetColors()
{
color colorBase=clrNONE,
colorQote=clrNONE;
string base,
qote;
string Name[9] = {"AUD","CAD","CHF","EUR","GBP","JPY","NZD","USD","XAU"};
color Color[9] =
{
clrDarkOrange,clrWhiteSmoke,clrFireBrick,clrRoyalBlue,
clrSilver,clrYellow,clrDarkViolet,clrLimeGreen,clrGold
};
base = StringSubstr(_Symbol,0,3); //Base currency name
qote = StringSubstr(_Symbol,3,3); //Quote currency name
for(int i=0;i<9;i++)
{
if(base==Name[i])
colorBase=Color[i];
if(qote==Name[i])
colorQote=Color[i];
}
if(!PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorBase) ||
!PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colorQote))
return(false);
if(ChartGetInteger(0,CHART_COLOR_CANDLE_BULL)!=colorBase)
{
if(!ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,colorBase) ||
!ChartSetInteger(0,CHART_COLOR_CHART_UP,colorBase))
return(false);
}
if(ChartGetInteger(0,CHART_COLOR_CANDLE_BEAR)!=colorQote)
{
if(!ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,colorQote) ||
!ChartSetInteger(0,CHART_COLOR_CHART_DOWN,colorQote))
return(false);
}
return(true);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -5,7 +5,6 @@
//+------------------------------------------------------------------+
#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_chart_window
#property indicator_buffers 3
@@ -25,15 +24,10 @@ bool ExtDirectionLong;
double ExtSarStep;
double ExtSarMaximum;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -92,15 +86,42 @@ int OnCalculate(const int rates_total,
return(0);
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
//--- detect current position
Binary file not shown.
+245
View File
@@ -0,0 +1,245 @@
#property copyright "2017-2020, Artur Zas"
#property link "http://www.az-invest.eu"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots 5
#property indicator_label1 "Volume"
#property indicator_type1 DRAW_HISTOGRAM // volume
#property indicator_color1 Gray
#property indicator_style1 0
#property indicator_width1 2
#property indicator_label2 "Buy volume"
#property indicator_type2 DRAW_HISTOGRAM // buy volume
#property indicator_color2 clrDarkGreen
#property indicator_style2 0
#property indicator_width2 2
#property indicator_label3 "Sell volume"
#property indicator_type3 DRAW_HISTOGRAM // sell volume
#property indicator_color3 clrFireBrick
#property indicator_style3 0
#property indicator_width3 2
#property indicator_label4 "Bar volume delta"
#property indicator_type4 DRAW_COLOR_HISTOGRAM // bar delta
#property indicator_color4 Lime,Red,clrNONE
#property indicator_style4 0
#property indicator_width4 5
#property indicator_label5 "Cumulative volume delta"
#property indicator_type5 DRAW_COLOR_LINE // cumulative delta
#property indicator_color5 Green, Red, clrNONE
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//--- input data
static ENUM_APPLIED_VOLUME InpVolumeType= (SymbolInfoInteger(_Symbol,SYMBOL_VOLUME) <= 0) ? VOLUME_TICK : VOLUME_REAL; // Volumes
input bool InpShowVolume = true; // Show volume histogram
input bool InpShowBuySellVolume = true; // Show bar's buy/sell volume breakdown
input bool InpShowBarDelta = true; // Show bar's buy/sell volume delta
input bool InpShowCumulativeDelta = false; // Show cumulative volume delta
input int InpCumulativeDeltaScale = 1; // Scale down cumulative volume 1:x
//---- indicator buffers
double ExtBarDeltaBuffer[];
double ExtBarDeltaColorsBuffer[];
double ExtBuyVolumeBuffer[];
double ExtSellVolumeBuffer[];
double ExtVolumeBuffer[];
double ExtCumulativeVolumeBuffer[];
double ExtCumulativeVolumeColorBuffer[];
double cumulativeDelta = 0;
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- buffers
SetIndexBuffer(0,ExtVolumeBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtBuyVolumeBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtSellVolumeBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtBarDeltaBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtBarDeltaColorsBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(5,ExtCumulativeVolumeBuffer,INDICATOR_DATA);
SetIndexBuffer(6,ExtCumulativeVolumeColorBuffer,INDICATOR_COLOR_INDEX);
//---- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Pro Volume");
//---- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
customChartIndicator.SetGetTimeFlag();
customChartIndicator.SetGetVolumesFlag();
customChartIndicator.SetGetVolumeBreakdownFlag();
//----
}
//+------------------------------------------------------------------+
//| Volumes |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---check for rates total
if(rates_total<2)
return(0);
//
// Process data through MedianRenko indicator
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
//
// Make the following modifications in the code below:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
//--- starting work
int start=_prev_calculated-1;
//--- correct position
// if(start<1) start=1;
if(start<0) start=0;
//--- main cycle
CalculateData(start,rates_total);
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CalculateData(const int nPosition,
const int nRatesCount)
{
double volume,buyVolume,sellVolume,barDelta;
for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
{
//--- calculate indicator
volume = (InpVolumeType == VOLUME_TICK) ? (double)customChartIndicator.Tick_volume[i] : (double)customChartIndicator.Real_volume[i];
buyVolume = customChartIndicator.Buy_volume[i];
sellVolume = customChartIndicator.Sell_volume[i];
barDelta = buyVolume - sellVolume;
//
if(InpShowVolume)
ExtVolumeBuffer[i] = volume;
else
ExtVolumeBuffer[i] = 0;
if(InpShowBuySellVolume)
{
ExtBuyVolumeBuffer[i] = buyVolume;
ExtSellVolumeBuffer[i] = sellVolume * (-1);
}
else
{
ExtBuyVolumeBuffer[i] = 0;
ExtSellVolumeBuffer[i] = 0;
}
if(InpShowBarDelta)
{
ExtBarDeltaBuffer[i] = barDelta;
ExtBarDeltaColorsBuffer[i] = ( ExtBarDeltaBuffer[i] < 0 ) ? 1 : (( ExtBarDeltaBuffer[i] == 0 ) ? 2 : 0 );
}
else
{
ExtBarDeltaBuffer[i] = 0;
ExtBarDeltaColorsBuffer[i] = 2;
}
if(InpShowCumulativeDelta)
{
if((i != (nRatesCount-1)) && (i>0))
{
if(IsNewDay(customChartIndicator.Time[i-1], customChartIndicator.Time[i]))
cumulativeDelta = 0; // reset cumulative volme
cumulativeDelta += barDelta;
ExtCumulativeVolumeBuffer[i] = cumulativeDelta / InpCumulativeDeltaScale;
ExtCumulativeVolumeColorBuffer[i] = ( ExtCumulativeVolumeBuffer[i] < 0 ) ? 1 : (( ExtCumulativeVolumeBuffer[i] == 0 ) ? 2 : 0 );
}
else
{
ExtCumulativeVolumeBuffer[i] = (cumulativeDelta + barDelta) / InpCumulativeDeltaScale;
ExtCumulativeVolumeColorBuffer[i] = ( ExtCumulativeVolumeBuffer[i] < 0 ) ? 1 : (( ExtCumulativeVolumeBuffer[i] == 0 ) ? 2 : 0 );
}
}
else
{
ExtCumulativeVolumeBuffer[i] = 0;
ExtCumulativeVolumeColorBuffer[i] = 2;
}
}
}
//+------------------------------------------------------------------+
bool IsNewDay(datetime prevTime,datetime currTime)
{
MqlDateTime prev;
MqlDateTime curr;
TimeToStruct(prevTime,prev);
TimeToStruct(currTime,curr);
if(prev.day_of_week != curr.day_of_week)
return true;
else
return false;
}
Binary file not shown.
+187
View File
@@ -0,0 +1,187 @@
//+------------------------------------------------------------------
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property description "QQE"
//+------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 3
#property indicator_label1 "QQE fast"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkGray
#property indicator_style1 STYLE_DOT
#property indicator_label2 "QQE slow"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDarkGray
#property indicator_label3 "QQE"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrDarkGray,clrDeepSkyBlue,clrLightSalmon
#property indicator_width3 2
//--- input parameters
input int inpRsiPeriod = 14; // RSI period
input int inpRsiSmoothingFactor = 5; // RSI smoothing factor
input double inpWPFast = 2.618; // Fast period
input double inpWPSlow = 4.236; // Slow period
input ENUM_APPLIED_PRICE inpPrice=PRICE_CLOSE; // Price
//--- buffers declarations
double val[],valc[],levs[],levf[];
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,levf,INDICATOR_DATA);
SetIndexBuffer(1,levs,INDICATOR_DATA);
SetIndexBuffer(2,val,INDICATOR_DATA);
SetIndexBuffer(3,valc,INDICATOR_COLOR_INDEX);
//--- indicator short name assignment
IndicatorSetString(INDICATOR_SHORTNAME,"QQE ("+(string)inpRsiPeriod+","+(string)inpRsiSmoothingFactor+")");
//---
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator de-initialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
///
if(Bars(_Symbol,_Period)<rates_total) return(_prev_calculated);
int i=(int)MathMax(_prev_calculated-1,0); for(; i<rates_total && !_StopFlag; i++)
{
val[i]=iEma(iRsi(getPrice(inpPrice,customChartIndicator.Open,customChartIndicator.Close,customChartIndicator.High,customChartIndicator.Low,i,rates_total),inpRsiPeriod,i,rates_total),inpRsiSmoothingFactor,i,rates_total,0);
double _iEma = iEma((i>0 ? MathAbs(val[i-1]-val[i]) : 0),inpRsiPeriod,i,rates_total,1);
double _iEmm = iEma( _iEma,inpRsiPeriod,i,rates_total,2);
double _iEmf = _iEmm*inpWPFast;
double _iEms = _iEmm*inpWPSlow;
//
//---
//
{
double tr = (i>0) ? levs[i-1] : 0;
double dv = tr;
if(val[i] < tr) { tr = val[i] + _iEms; if((i>0 && val[i-1] < dv) && (tr > dv)) tr = dv; }
if(val[i] > tr) { tr = val[i] - _iEms; if((i>0 && val[i-1] > dv) && (tr < dv)) tr = dv; }
levs[i]=tr;
}
{
double tr = (i>0) ? levf[i-1] : 0;
double dv = tr;
if(val[i] < tr) { tr = val[i] + _iEmf; if((i>0 && val[i-1] < dv) && (tr > dv)) tr = dv; }
if(val[i] > tr) { tr = val[i] - _iEmf; if((i>0 && val[i-1] > dv) && (tr < dv)) tr = dv; }
levf[i]=tr;
}
valc[i]=(val[i]>levf[i] && val[i]>levs[i]) ? 1 :(val[i]<levf[i] && val[i]<levs[i]) ? 2 :(i>0) ? valc[i-1]: 0;
}
return (i);
}
//+------------------------------------------------------------------+
//| Custom functions |
//+------------------------------------------------------------------+
#define rsiInstances 1
#define rsiInstancesSize 3
double workRsi[][rsiInstances*rsiInstancesSize];
#define _price 0
#define _change 1
#define _changa 2
//
//---
//
double iRsi(double price,double period,int r,int bars,int instanceNo=0)
{
if(ArrayRange(workRsi,0)!=bars) ArrayResize(workRsi,bars);
int z=instanceNo*rsiInstancesSize;
//
//
//
//
//
workRsi[r][z+_price]=price;
if(r<period)
{
int k; double sum=0; for(k=0; k<period && (r-k-1)>=0; k++) sum+=MathAbs(workRsi[r-k][z+_price]-workRsi[r-k-1][z+_price]);
workRsi[r][z+_change] = (workRsi[r][z+_price]-workRsi[0][z+_price])/MathMax(k,1);
workRsi[r][z+_changa] = sum/MathMax(k,1);
}
else
{
double alpha=1.0/MathMax(period,1);
double change=workRsi[r][z+_price]-workRsi[r-1][z+_price];
workRsi[r][z+_change] = workRsi[r-1][z+_change] + alpha*( change - workRsi[r-1][z+_change]);
workRsi[r][z+_changa] = workRsi[r-1][z+_changa] + alpha*(MathAbs(change) - workRsi[r-1][z+_changa]);
}
return(50.0*(workRsi[r][z+_change]/MathMax(workRsi[r][z+_changa],DBL_MIN)+1));
}
//
//---
//
double workEma[][3];
//
//---
//
double iEma(double price,double period,int r,int bars,int instanceNo=0)
{
if(ArrayRange(workEma,0)!=bars) ArrayResize(workEma,bars);
//
//---
//
workEma[r][instanceNo]=price;
if(r>0 && period>1)
workEma[r][instanceNo]=workEma[r-1][instanceNo]+2.0/(1.0+period)*(price-workEma[r-1][instanceNo]);
return(workEma[r][instanceNo]);
}
//
//---
//
double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars)
{
switch(tprice)
{
case PRICE_CLOSE: return(close[i]);
case PRICE_OPEN: return(open[i]);
case PRICE_HIGH: return(high[i]);
case PRICE_LOW: return(low[i]);
case PRICE_MEDIAN: return((high[i]+low[i])/2.0);
case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0);
case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0);
}
return(0);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -19,15 +19,10 @@ double ExtRocBuffer[];
//--- global variable
int ExtRocPeriod;
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -80,13 +75,38 @@ int OnCalculate(const int rates_total,const int prev_calculated,
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
Binary file not shown.
@@ -25,15 +25,10 @@ double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -78,15 +73,42 @@ int OnCalculate(const int rates_total,const int prev_calculated,
const int &Spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
int i,pos;
Binary file not shown.
+119
View File
@@ -0,0 +1,119 @@
//+------------------------------------------------------------------+
//| RVI.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Relative Vigor Index"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_label1 "RVI"
#property indicator_label2 "Signal"
//--- input parameters
input int InpRVIPeriod=10; // Period
//--- indicator buffers
double ExtRVIBuffer[];
double ExtSignalBuffer[];
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//---
#define TRIANGLE_PERIOD 3
#define AVERAGE_PERIOD (TRIANGLE_PERIOD*2)
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRVIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
IndicatorSetInteger(INDICATOR_DIGITS,3);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+TRIANGLE_PERIOD);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+AVERAGE_PERIOD);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"RVI("+string(InpRVIPeriod)+")");
PlotIndexSetString(0,PLOT_LABEL,"RVI("+string(InpRVIPeriod)+")");
PlotIndexSetString(1,PLOT_LABEL,"Signal("+string(InpRVIPeriod)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| Relative Vigor Index |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i,j,nLimit;
double dValueUp,dValueDown,dNum,dDeNum;
//--- check for bars count
if(rates_total<=InpRVIPeriod+AVERAGE_PERIOD+2) return(0); // exit with zero result
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
//--- check for possible errors
if(_prev_calculated<0) return(0); // exit with zero result
//--- last counted bar will be recounted
nLimit=InpRVIPeriod+2;
if(_prev_calculated>InpRVIPeriod+TRIANGLE_PERIOD+2)
nLimit=prev_calculated-1;
//--- set empty value for uncalculated bars
if(_prev_calculated==0)
{
for(i=0;i<InpRVIPeriod+TRIANGLE_PERIOD;i++) ExtRVIBuffer[i]=0.0;
for(i=0;i<InpRVIPeriod+AVERAGE_PERIOD;i++) ExtSignalBuffer[i]=0.0;
}
//--- RVI counted in the 1-st buffer
for(i=nLimit;i<rates_total && !IsStopped();i++)
{
dNum=0.0;
dDeNum=0.0;
for(j=i;j>i-InpRVIPeriod;j--)
{
dValueUp=customChartIndicator.Close[j]-customChartIndicator.Open[j]+2*(customChartIndicator.Close[j-1]-customChartIndicator.Open[j-1])+2*(customChartIndicator.Close[j-2]-customChartIndicator.Open[j-2])+customChartIndicator.Close[j-3]-customChartIndicator.Open[j-3];
dValueDown=customChartIndicator.High[j]-customChartIndicator.Low[j]+2*(customChartIndicator.High[j-1]-customChartIndicator.Low[j-1])+2*(customChartIndicator.High[j-2]-customChartIndicator.Low[j-2])+customChartIndicator.High[j-3]-customChartIndicator.Low[j-3];
dNum+=dValueUp;
dDeNum+=dValueDown;
}
if(dDeNum!=0.0)
ExtRVIBuffer[i]=dNum/dDeNum;
else
ExtRVIBuffer[i]=dNum;
}
//--- signal line counted in the 2-nd buffer
nLimit=InpRVIPeriod+TRIANGLE_PERIOD+2;
if(_prev_calculated>InpRVIPeriod+AVERAGE_PERIOD+2)
nLimit=prev_calculated-1;
for(i=nLimit;i<rates_total && !IsStopped();i++) ExtSignalBuffer[i]=(ExtRVIBuffer[i]+2*ExtRVIBuffer[i-1]+2*ExtRVIBuffer[i-2]+ExtRVIBuffer[i-3])/AVERAGE_PERIOD;
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -26,8 +26,7 @@ double ExtMABuffer[];
int ExtStdDevPeriod,ExtStdDevShift;
#include <MovingAverages.mqh>
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
Binary file not shown.
@@ -5,7 +5,6 @@
//+------------------------------------------------------------------+
#property copyright "2009, 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 4
@@ -26,15 +25,10 @@ double ExtSignalBuffer[];
double ExtHighesBuffer[];
double ExtLowesBuffer[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//+------------------------------------------------------------------+
@@ -78,22 +72,44 @@ int OnCalculate(const int rates_total,const int prev_calculated,
const long &Volume[],
const int &Spread[])
{
//
// Process data through MedianRenko indicator
//
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
//
int i,k,start;
//--- check for bars count
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+301
View File
@@ -0,0 +1,301 @@
//------------------------------------------------------------------
#property copyright "mladen"
#property link "www.forex-tsd.com"
// Inserted by Ale: rebound arrows and TMA angle caution
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots 6
#property indicator_label1 "Centered TMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLightSkyBlue,clrPink
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_label2 "Centered TMA upper band"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLightSkyBlue
#property indicator_style2 STYLE_DOT
#property indicator_label3 "Centered TMA lower band"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrPink
#property indicator_style3 STYLE_DOT
// ** inserted code:
#property indicator_label4 "Rebound down"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrPink
#property indicator_width4 2
#property indicator_label5 "Rebound up"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrLightSkyBlue
#property indicator_width5 2
#property indicator_label6 "Centered TMA angle caution"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrGold
#property indicator_width6 3
// **
//
//
//
//
//
enum enPrices
{
pr_close, // Close
pr_open, // Open
pr_high, // High
pr_low, // Low
pr_median, // Median
pr_typical, // Typical
pr_weighted, // Weighted
pr_average, // Average (high+low+oprn+close)/4
pr_haclose, // Heiken ashi close
pr_haopen , // Heiken ashi open
pr_hahigh, // Heiken ashi high
pr_halow, // Heiken ashi low
pr_hamedian, // Heiken ashi median
pr_hatypical, // Heiken ashi typical
pr_haweighted, // Heiken ashi weighted
pr_haaverage // Heiken ashi average
};
//
//
//
//
//
input int HalfLength = 12; // Centered TMA half period
input enPrices Price = pr_weighted; // Price to use
input int AtrPeriod = 100; // Average true range period
input double AtrMultiplier = 2; // Average true range multiplier
// ** inserted code:
input int TMAangle = 4; // Centered TMA angle caution. In pips
// **
//
//
//
//
//
double tmac[];
double tmau[];
double tmad[];
double colorBuffer[];
// ** inserted code:
double
ReboundD[], ReboundU[],
Caution[]
;
// **
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int OnInit()
{
SetIndexBuffer(0,tmac,INDICATOR_DATA);
SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,tmau,INDICATOR_DATA);
SetIndexBuffer(3,tmad,INDICATOR_DATA);
// ** inserted code:
SetIndexBuffer(4,ReboundD,INDICATOR_DATA); PlotIndexSetInteger(3, PLOT_ARROW, 226);
SetIndexBuffer(5,ReboundU,INDICATOR_DATA); PlotIndexSetInteger(4, PLOT_ARROW, 225);
SetIndexBuffer(6,Caution,INDICATOR_DATA); PlotIndexSetInteger(5, PLOT_ARROW, 251);
// **
//
//
//
//
//
IndicatorSetString(INDICATOR_SHORTNAME," TMA centered ("+string(HalfLength)+")");
return(0);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
double prices[];
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();
//
//
//
if (ArraySize(prices)!=rates_total) ArrayResize(prices,rates_total);
for (int i=(int)MathMax(_prev_calculated-1, 0); i<rates_total; i++) prices[i] = getPrice(Price,customChartIndicator.Open,customChartIndicator.Close,customChartIndicator.High,customChartIndicator.Low,i,rates_total);
for (int i=(int)MathMax(_prev_calculated-HalfLength,0); i<rates_total; i++)
{
double atr = 0;
for (int j=0; j<AtrPeriod && (i-j-11)>=0; j++) atr += MathMax(customChartIndicator.High[i-j-10],customChartIndicator.Close[i-j-11])-MathMin(customChartIndicator.Low[i-j-10],customChartIndicator.Close[i-j-11]);
atr /= AtrPeriod;
double sum = (HalfLength+1)*prices[i];
double sumw = (HalfLength+1);
for(int j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
if ((i-j)>=0)
{
sum += k*prices[i-j];
sumw += k;
}
if ((i+j)<rates_total)
{
sum += k*prices[i+j];
sumw += k;
}
}
tmac[i] = sum/sumw;
if (i>0)
{
colorBuffer[i] = colorBuffer[i-1];
if (tmac[i] > tmac[i-1]) colorBuffer[i]= 0;
if (tmac[i] < tmac[i-1]) colorBuffer[i]= 1;
}
tmau[i] = tmac[i]+AtrMultiplier*atr;
tmad[i] = tmac[i]-AtrMultiplier*atr;
// ** inserted code:
ReboundD[i] = ReboundU[i] = Caution[i] = EMPTY_VALUE;
if(i > 0) {
if(customChartIndicator.High[i-1] > tmau[i-1] && customChartIndicator.Close[i-1] > customChartIndicator.Open[i-1] && customChartIndicator.Close[i] < customChartIndicator.Open[i]) {
ReboundD[i] = customChartIndicator.High[i] + AtrMultiplier*atr/2;
if(tmac[i] - tmac[i-1] > TMAangle*_Point) Caution[i] = ReboundD[i] + 10*_Point;
}
if(low[i-1] < tmad[i-1] && customChartIndicator.Close[i-1] < customChartIndicator.Open[i-1] && customChartIndicator.Close[i] > customChartIndicator.Open[i]) {
ReboundU[i] = customChartIndicator.Low[i] - AtrMultiplier*atr/2;
if(tmac[i-1] - tmac[i] > TMAangle*_Point) Caution[i] = ReboundU[i] - 10*_Point;
}
}
// **
}
return(rates_total);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
double workHa[][4];
double getPrice(enPrices price, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars)
{
if (price>=pr_haclose && price<=pr_haaverage)
{
if (ArrayRange(workHa,0)!= bars) ArrayResize(workHa,bars);
//
//
//
//
//
double haOpen;
if (i>0)
haOpen = (workHa[i-1][2] + workHa[i-1][3])/2.0;
else haOpen = open[i]+close[i];
double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0;
double haHigh = MathMax(high[i], MathMax(haOpen,haClose));
double haLow = MathMin(low[i] , MathMin(haOpen,haClose));
if(haOpen <haClose) { workHa[i][0] = haLow; workHa[i][1] = haHigh; }
else { workHa[i][0] = haHigh; workHa[i][1] = haLow; }
workHa[i][2] = haOpen;
workHa[i][3] = haClose;
//
//
//
//
//
switch (price)
{
case pr_haclose: return(haClose);
case pr_haopen: return(haOpen);
case pr_hahigh: return(haHigh);
case pr_halow: return(haLow);
case pr_hamedian: return((haHigh+haLow)/2.0);
case pr_hatypical: return((haHigh+haLow+haClose)/3.0);
case pr_haweighted: return((haHigh+haLow+haClose+haClose)/4.0);
case pr_haaverage: return((haHigh+haLow+haClose+haOpen)/4.0);
}
}
//
//
//
//
//
switch (price)
{
case pr_close: return(close[i]);
case pr_open: return(open[i]);
case pr_high: return(high[i]);
case pr_low: return(low[i]);
case pr_median: return((high[i]+low[i])/2.0);
case pr_typical: return((high[i]+low[i]+close[i])/3.0);
case pr_weighted: return((high[i]+low[i]+close[i]+close[i])/4.0);
case pr_average: return((high[i]+low[i]+close[i]+open[i])/4.0);
}
return(0);
}
Binary file not shown.
+138
View File
@@ -0,0 +1,138 @@
//+------------------------------------------------------------------+
//| TRIX.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Triple Exponential Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
#property indicator_width1 1
#property indicator_label1 "TRIX"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int InpPeriodEMA=14; // EMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double TRIX_Buffer[];
double EMA[];
double SecondEMA[];
double ThirdEMA[];
//
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,TRIX_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,EMA,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,SecondEMA,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ThirdEMA,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3);
//--- name for index label
PlotIndexSetString(0,PLOT_LABEL,"TRIX("+string(InpPeriodEMA)+")");
//--- name for indicator label
IndicatorSetString(INDICATOR_SHORTNAME,"TRIX("+string(InpPeriodEMA)+")");
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,5);
//--- initialization done
customChartIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
}
//+------------------------------------------------------------------+
//| Triple Exponential Average |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- check for data
if(rates_total<3*InpPeriodEMA-3)
return(0);
//---
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
int limit;
if(_prev_calculated==0)
{
limit=3*(InpPeriodEMA-1);
for(int i=0;i<limit;i++)
TRIX_Buffer[i]=EMPTY_VALUE;
}
else limit=_prev_calculated-1;
//--- calculate EMA
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpPeriodEMA,customChartIndicator.Price,EMA);
//--- calculate EMA on EMA array
ExponentialMAOnBuffer(rates_total,_prev_calculated,InpPeriodEMA-1,InpPeriodEMA,EMA,SecondEMA);
//--- calculate EMA on EMA array on EMA array
ExponentialMAOnBuffer(rates_total,_prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,SecondEMA,ThirdEMA);
//--- calculate TRIX
for(int i=limit;i<rates_total && !IsStopped();i++)
{
if(ThirdEMA[i-1]!=0.0)
TRIX_Buffer[i]=(ThirdEMA[i]-ThirdEMA[i-1])/ThirdEMA[i-1];
else
TRIX_Buffer[i]=0.0;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
Binary file not shown.
@@ -1,12 +1,11 @@
#property copyright "Copyright 2018-2020, Level Up Software"
#property copyright "Copyright 2018-2021, 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 description "A timescale indicator for use on the custom chart."
#property version "1.04"
#property indicator_separate_window
#property indicator_plots 0
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
#define PREFIX_SEED "6D4E6"
@@ -19,7 +18,7 @@ enum ENUM_DISPLAY_FORMAT
DisplayFormat2, // 25.01 10:55
};
input color InpTextColor = clrBlack; // Font color
input color InpTextColor = clrWhiteSmoke; // Font color
input int InpFontSize = 9; // Font size
input int InpSpacing = 3; // Date/Time spacing factor
input ENUM_DISPLAY_FORMAT InpDispFormat = DisplayFormat1; // Display format
@@ -251,4 +250,4 @@ bool TextCreate(const long chart_ID=0, // chart's ID
return(true);
}
Binary file not shown.
@@ -62,17 +62,11 @@ double ADX[];
double ADXR[];
double Level[];
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
//
//
//
//------------------------------------------------------------------
//
//------------------------------------------------------------------
@@ -136,15 +130,42 @@ int OnCalculate(const int rates_total,
const int& spread[])
{
//
// Process data through MedianRenko indicator
//
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:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
//
//
if (ArrayRange(averages,0)!=rates_total) ArrayResize(averages,rates_total);
Binary file not shown.
@@ -56,19 +56,14 @@ enum PRICE_TYPE
//+------------------------------------------------------------------+
//
//
//
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
RangeBarIndicator customChartIndicator;
#include <AZ-INVEST/CustomBarConfig.mqh>
#define VWAP_Daily "cc__VWAP_Daily"
#define VWAP_Weekly "cc__VWAP_Weekly"
#define VWAP_Monthly "cc__VWAP_Monthly"
//
//
//
datetime CreateDateTime(DATE_TYPE nReturnType=DAILY,datetime dtDay=D'2000.01.01 00:00:00',int pHour=0,int pMinute=0,int pSecond=0)
@@ -199,7 +194,7 @@ int OnCalculate(const int rates_total,
{
//
// Process data through Tick Chat indicator
// Process data through MedianRenko indicator
//
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
@@ -208,6 +203,29 @@ int OnCalculate(const int rates_total,
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
//
// Make the following modifications in the code below:
//
// customChartIndicator.GetPrevCalculated() should be used instead of prev_calculated
//
// 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[]
//
// customChartIndicator.IsNewBar (true/false) informs you if a renko brick completed
//
// 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
//
// 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
//
// 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 = customChartIndicator.GetPrevCalculated();
//
@@ -220,7 +238,7 @@ int OnCalculate(const int rates_total,
LastTimePeriod=PERIOD_CURRENT;
}
if(rates_total>_prev_calculated || bIsFirstRun || Calc_Every_Tick || (_prev_calculated == 0) ||customChartIndicator.IsNewBar)
if(rates_total>_prev_calculated || bIsFirstRun || Calc_Every_Tick || (_prev_calculated == 0) || customChartIndicator.IsNewBar)
{
nIdxDaily = 0;
nIdxWeekly = 0;
Binary file not shown.
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More