Init mql5 project
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,90 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| AD.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accumulation/Distribution"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_label1 "A/D"
|
||||
//--- input params
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volume type
|
||||
//--- indicator buffer
|
||||
double ExtADbuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//--- indicator short name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"A/D");
|
||||
//--- index buffer
|
||||
SetIndexBuffer(0,ExtADbuffer);
|
||||
//--- set index draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accumulation/Distribution |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- check for bars count
|
||||
if(rates_total<2)
|
||||
return(0); //exit with zero result
|
||||
//--- get current position
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<0)
|
||||
pos=0;
|
||||
//--- calculate with appropriate volumes
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
Calculate(rates_total,pos,high,low,close,tick_volume);
|
||||
else
|
||||
Calculate(rates_total,pos,high,low,close,volume);
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculating with selected volume |
|
||||
//+------------------------------------------------------------------+
|
||||
void Calculate(const int rates_total,const int pos,
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &volume[])
|
||||
{
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data from arrays
|
||||
double hi=high[i];
|
||||
double lo=low[i];
|
||||
double cl=close[i];
|
||||
//--- calculate new AD
|
||||
double sum=(cl-lo)-(hi-cl);
|
||||
if(hi==lo)
|
||||
sum=0.0;
|
||||
else
|
||||
sum=(sum/(hi-lo))*volume[i];
|
||||
if(i>0)
|
||||
sum+=ExtADbuffer[i-1];
|
||||
ExtADbuffer[i]=sum;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,155 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ADX.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average Directional Movement Index"
|
||||
#include <MovingAverages.mqh>
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellowGreen
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrWheat
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
#property indicator_label1 "ADX"
|
||||
#property indicator_label2 "+DI"
|
||||
#property indicator_label3 "-DI"
|
||||
//--- input parameters
|
||||
input int InpPeriodADX=14; // Period ADX
|
||||
//--- indicator buffers
|
||||
double ExtADXBuffer[];
|
||||
double ExtPDIBuffer[];
|
||||
double ExtNDIBuffer[];
|
||||
double ExtPDBuffer[];
|
||||
double ExtNDBuffer[];
|
||||
double ExtTmpBuffer[];
|
||||
|
||||
int ExtADXPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input parameters
|
||||
if(InpPeriodADX>=100 || InpPeriodADX<=0)
|
||||
{
|
||||
ExtADXPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable Period_ADX=%d. Indicator will use value=%d for calculations.",InpPeriodADX,ExtADXPeriod);
|
||||
}
|
||||
else
|
||||
ExtADXPeriod=InpPeriodADX;
|
||||
//--- indicator buffers
|
||||
SetIndexBuffer(0,ExtADXBuffer);
|
||||
SetIndexBuffer(1,ExtPDIBuffer);
|
||||
SetIndexBuffer(2,ExtNDIBuffer);
|
||||
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtTmpBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXPeriod<<1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXPeriod);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXPeriod);
|
||||
//--- indicator short name
|
||||
string short_name="ADX("+string(ExtADXPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- checking for bars count
|
||||
if(rates_total<ExtADXPeriod)
|
||||
return(0);
|
||||
//--- detect start position
|
||||
int start;
|
||||
if(prev_calculated>1)
|
||||
start=prev_calculated-1;
|
||||
else
|
||||
{
|
||||
start=1;
|
||||
ExtPDIBuffer[0]=0.0;
|
||||
ExtNDIBuffer[0]=0.0;
|
||||
ExtADXBuffer[0]=0.0;
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double high_price=high[i];
|
||||
double prev_high =high[i-1];
|
||||
double low_price =low[i];
|
||||
double prev_low =low[i-1];
|
||||
double prev_close=close[i-1];
|
||||
//--- fill main positive and main negative buffers
|
||||
double tmp_pos=high_price-prev_high;
|
||||
double tmp_neg=prev_low-low_price;
|
||||
if(tmp_pos<0.0)
|
||||
tmp_pos=0.0;
|
||||
if(tmp_neg<0.0)
|
||||
tmp_neg=0.0;
|
||||
if(tmp_pos>tmp_neg)
|
||||
tmp_neg=0.0;
|
||||
else
|
||||
{
|
||||
if(tmp_pos<tmp_neg)
|
||||
tmp_pos=0.0;
|
||||
else
|
||||
{
|
||||
tmp_pos=0.0;
|
||||
tmp_neg=0.0;
|
||||
}
|
||||
}
|
||||
//--- define TR
|
||||
double tr=MathMax(MathMax(MathAbs(high_price-low_price),MathAbs(high_price-prev_close)),MathAbs(low_price-prev_close));
|
||||
if(tr!=0.0)
|
||||
{
|
||||
ExtPDBuffer[i]=100.0*tmp_pos/tr;
|
||||
ExtNDBuffer[i]=100.0*tmp_neg/tr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtPDBuffer[i]=0.0;
|
||||
ExtNDBuffer[i]=0.0;
|
||||
}
|
||||
//--- fill smoothed positive and negative buffers
|
||||
ExtPDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtPDIBuffer[i-1],ExtPDBuffer);
|
||||
ExtNDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtNDIBuffer[i-1],ExtNDBuffer);
|
||||
//--- fill ADXTmp buffer
|
||||
double tmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
|
||||
if(tmp!=0.0)
|
||||
tmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/tmp);
|
||||
else
|
||||
tmp=0.0;
|
||||
ExtTmpBuffer[i]=tmp;
|
||||
//--- fill smoothed ADX buffer
|
||||
ExtADXBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtADXBuffer[i-1],ExtTmpBuffer);
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,189 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ADXW.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average Directional Movement Index"
|
||||
#property description "by Welles Wilder"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
#property indicator_color2 clrYellowGreen
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
#property indicator_color3 clrWheat
|
||||
#property indicator_label1 "ADX Wilder"
|
||||
#property indicator_label2 "+DI"
|
||||
#property indicator_label3 "-DI"
|
||||
//--- input parameters
|
||||
input int InpPeriodADXW=14; // Period ADX
|
||||
//--- indicator buffers
|
||||
double ExtADXWBuffer[];
|
||||
double ExtPDIBuffer[];
|
||||
double ExtNDIBuffer[];
|
||||
double ExtPDSBuffer[];
|
||||
double ExtNDSBuffer[];
|
||||
double ExtPDBuffer[];
|
||||
double ExtNDBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
double ExtATRBuffer[];
|
||||
double ExtDXBuffer[];
|
||||
|
||||
int ExtADXWPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input parameters
|
||||
if(InpPeriodADXW>=100 || InpPeriodADXW<=0)
|
||||
{
|
||||
ExtADXWPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable InpPeriodADXW=%d. Indicator will use value=%d for calculations.",InpPeriodADXW,ExtADXWPeriod);
|
||||
}
|
||||
else
|
||||
ExtADXWPeriod=InpPeriodADXW;
|
||||
//--- indicator buffers
|
||||
SetIndexBuffer(0,ExtADXWBuffer);
|
||||
SetIndexBuffer(1,ExtPDIBuffer);
|
||||
SetIndexBuffer(2,ExtNDIBuffer);
|
||||
//--- calculation buffers
|
||||
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtDXBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(7,ExtATRBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(8,ExtPDSBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(9,ExtNDSBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXWPeriod<<1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
|
||||
//--- indicator short name
|
||||
string short_name="ADX Wilder("+string(ExtADXWPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- checking for bars count
|
||||
if(rates_total<ExtADXWPeriod)
|
||||
return(0);
|
||||
//--- detect start position
|
||||
int start;
|
||||
if(prev_calculated>1)
|
||||
start=prev_calculated-1;
|
||||
else
|
||||
{
|
||||
start=1;
|
||||
for(int i=0; i<ExtADXWPeriod; i++)
|
||||
{
|
||||
ExtADXWBuffer[i]=0;
|
||||
ExtPDIBuffer[i]=0;
|
||||
ExtNDIBuffer[i]=0;
|
||||
ExtPDSBuffer[i]=0;
|
||||
ExtNDSBuffer[i]=0;
|
||||
ExtPDBuffer[i]=0;
|
||||
ExtNDBuffer[i]=0;
|
||||
ExtTRBuffer[i]=0;
|
||||
ExtATRBuffer[i]=0;
|
||||
ExtDXBuffer[i]=0;
|
||||
}
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double high_price=high[i];
|
||||
double prev_high =high[i-1];
|
||||
double low_price =low[i];
|
||||
double prev_low =low[i-1];
|
||||
double prev_close=close[i-1];
|
||||
//--- fill main positive and main negative buffers
|
||||
double tmp_pos=high_price-prev_high;
|
||||
double tmp_neg=prev_low-low_price;
|
||||
if(tmp_pos<0.0)
|
||||
tmp_pos=0.0;
|
||||
if(tmp_neg<0.0)
|
||||
tmp_neg=0.0;
|
||||
if(tmp_neg==tmp_pos)
|
||||
{
|
||||
tmp_neg=0.0;
|
||||
tmp_pos=0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tmp_pos<tmp_neg)
|
||||
tmp_pos=0.0;
|
||||
else
|
||||
tmp_neg=0.0;
|
||||
}
|
||||
ExtPDBuffer[i]=tmp_pos;
|
||||
ExtNDBuffer[i]=tmp_neg;
|
||||
//--- define TR
|
||||
double tr=MathMax(MathMax(MathAbs(high_price-low_price),MathAbs(high_price-prev_close)),MathAbs(low_price-prev_close));
|
||||
ExtTRBuffer[i]=tr; // write down TR to TR buffer
|
||||
//--- fill smoothed positive and negative buffers and TR buffer
|
||||
if(i<ExtADXWPeriod)
|
||||
{
|
||||
ExtATRBuffer[i]=0.0;
|
||||
ExtPDIBuffer[i]=0.0;
|
||||
ExtNDIBuffer[i]=0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtATRBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtATRBuffer[i-1],ExtTRBuffer);
|
||||
ExtPDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtPDSBuffer[i-1],ExtPDBuffer);
|
||||
ExtNDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtNDSBuffer[i-1],ExtNDBuffer);
|
||||
}
|
||||
//--- calculate PDI and NDI buffers
|
||||
if(ExtATRBuffer[i]!=0.0)
|
||||
{
|
||||
ExtPDIBuffer[i]=100.0*ExtPDSBuffer[i]/ExtATRBuffer[i];
|
||||
ExtNDIBuffer[i]=100.0*ExtNDSBuffer[i]/ExtATRBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtPDIBuffer[i]=0.0;
|
||||
ExtNDIBuffer[i]=0.0;
|
||||
}
|
||||
//--- Calculate DX buffer
|
||||
double dTmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
|
||||
if(dTmp!=0.0)
|
||||
dTmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/dTmp);
|
||||
else
|
||||
dTmp=0.0;
|
||||
ExtDXBuffer[i]=dTmp;
|
||||
//--- fill ADXW buffer as smoothed DX buffer
|
||||
ExtADXWBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtADXWBuffer[i-1],ExtDXBuffer);
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property description "Adaptive Moving Average"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot ExtAMABuffer
|
||||
#property indicator_label1 "AMA"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- default applied price
|
||||
#property indicator_applied_price PRICE_OPEN
|
||||
//--- input parameters
|
||||
input int InpPeriodAMA=10; // AMA period
|
||||
input int InpFastPeriodEMA=2; // Fast EMA period
|
||||
input int InpSlowPeriodEMA=30; // Slow EMA period
|
||||
input int InpShiftAMA=0; // AMA shift
|
||||
//--- indicator buffer
|
||||
double ExtAMABuffer[];
|
||||
|
||||
double ExtFastSC;
|
||||
double ExtSlowSC;
|
||||
int ExtPeriodAMA;
|
||||
int ExtSlowPeriodEMA;
|
||||
int ExtFastPeriodEMA;
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpPeriodAMA<=0)
|
||||
{
|
||||
ExtPeriodAMA=10;
|
||||
PrintFormat("Input parameter InpPeriodAMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpPeriodAMA,ExtPeriodAMA);
|
||||
}
|
||||
else
|
||||
ExtPeriodAMA=InpPeriodAMA;
|
||||
if(InpSlowPeriodEMA<=0)
|
||||
{
|
||||
ExtSlowPeriodEMA=30;
|
||||
PrintFormat("Input parameter InpSlowPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpSlowPeriodEMA,ExtSlowPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtSlowPeriodEMA=InpSlowPeriodEMA;
|
||||
if(InpFastPeriodEMA<=0)
|
||||
{
|
||||
ExtFastPeriodEMA=2;
|
||||
PrintFormat("Input parameter InpFastPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpFastPeriodEMA,ExtFastPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtFastPeriodEMA=InpFastPeriodEMA;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtAMABuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA);
|
||||
//--- set index shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpShiftAMA);
|
||||
//--- set shortname and change label
|
||||
string short_name=StringFormat("AMA(%d,%d,%d)",ExtPeriodAMA,ExtFastPeriodEMA,ExtSlowPeriodEMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- calculate ExtFastSC & ExtSlowSC
|
||||
ExtFastSC=2.0/(ExtFastPeriodEMA+1.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int i;
|
||||
//--- check for rates count
|
||||
if(rates_total<ExtPeriodAMA+begin)
|
||||
return(0);
|
||||
//--- draw begin may be corrected
|
||||
if(begin!=0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);
|
||||
//--- detect position
|
||||
int pos=prev_calculated-1;
|
||||
//--- first calculations
|
||||
if(pos<ExtPeriodAMA+begin)
|
||||
{
|
||||
pos=ExtPeriodAMA+begin;
|
||||
for(i=0; i<pos-1; i++)
|
||||
ExtAMABuffer[i]=0.0;
|
||||
ExtAMABuffer[pos-1]=price[pos-1];
|
||||
}
|
||||
//--- main cycle
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- calculate SSC
|
||||
double currentSSC=(CalculateER(i,price)*(ExtFastSC-ExtSlowSC))+ExtSlowSC;
|
||||
//--- calculate AMA
|
||||
double prevAMA=ExtAMABuffer[i-1];
|
||||
ExtAMABuffer[i]=MathPow(currentSSC,2)*(price[i]-prevAMA)+prevAMA;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate ER value |
|
||||
//+------------------------------------------------------------------+
|
||||
double CalculateER(const int pos,const double& price[])
|
||||
{
|
||||
double signal=MathAbs(price[pos]-price[pos-ExtPeriodAMA]);
|
||||
double noise=0.0;
|
||||
for(int delta=0; delta<ExtPeriodAMA; delta++)
|
||||
noise+=MathAbs(price[pos-delta]-price[pos-delta-1]);
|
||||
if(noise!=0.0)
|
||||
return(signal/noise);
|
||||
return(0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,112 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ASI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accumulation Swing Index"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_style1 0
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "ASI"
|
||||
//--- input parameter
|
||||
input double InpT=300.0; // T (maximum price changing)
|
||||
//--- indicator buffers
|
||||
double ExtASIBuffer[];
|
||||
double ExtSIBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
|
||||
double ExtTpoints,ExtT;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(MathAbs(InpT)>1e-7)
|
||||
ExtT=InpT;
|
||||
else
|
||||
{
|
||||
ExtT=300.0;
|
||||
PrintFormat("Input parameter T has wrong value. Indicator will use T = %f.",ExtT);
|
||||
}
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtASIBuffer);
|
||||
SetIndexBuffer(1,ExtSIBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- draw begin settings
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- calculate ExtTpoints value
|
||||
if(_Point>1e-7)
|
||||
ExtTpoints=ExtT*_Point;
|
||||
else
|
||||
ExtTpoints=ExtT*MathPow(10,-_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<2)
|
||||
return(0);
|
||||
//--- start calculation
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position, when it's first iteration
|
||||
if(pos<=0)
|
||||
{
|
||||
pos=1;
|
||||
ExtASIBuffer[0]=0.0;
|
||||
ExtSIBuffer[0]=0.0;
|
||||
ExtTRBuffer[0]=high[0]-low[0];
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double dPrevClose=close[i-1];
|
||||
double dPrevOpen=open[i-1];
|
||||
double dClose=close[i];
|
||||
double dHigh=high[i];
|
||||
double dLow=low[i];
|
||||
//--- fill TR buffer
|
||||
ExtTRBuffer[i]=MathMax(dHigh,dPrevClose)-MathMin(dLow,dPrevClose);
|
||||
double ER=0.0;
|
||||
if(!(dPrevClose>=dLow && dPrevClose<=dHigh))
|
||||
{
|
||||
if(dPrevClose>dHigh)
|
||||
ER=MathAbs(dHigh-dPrevClose);
|
||||
if(dPrevClose<dLow)
|
||||
ER=MathAbs(dLow-dPrevClose);
|
||||
}
|
||||
double K=MathMax(MathAbs(dHigh-dPrevClose),MathAbs(dLow-dPrevClose));
|
||||
double SH=MathAbs(dPrevClose-dPrevOpen);
|
||||
double R=ExtTRBuffer[i]-0.5*ER+0.25*SH;
|
||||
//--- calculate SI value
|
||||
if(R==0.0 || ExtTpoints==0.0)
|
||||
ExtSIBuffer[i]=0.0;
|
||||
else
|
||||
ExtSIBuffer[i]=50*(dClose-dPrevClose+0.5*(dClose-open[i])+0.25*(dPrevClose-dPrevOpen))*(K/ExtTpoints)/R;
|
||||
//--- write down ASI buffer value
|
||||
ExtASIBuffer[i]=ExtASIBuffer[i-1]+ExtSIBuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average True Range"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_label1 "ATR"
|
||||
//--- input parameters
|
||||
input int InpAtrPeriod=14; // ATR period
|
||||
//--- indicator buffers
|
||||
double ExtATRBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
|
||||
int ExtPeriodATR;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpAtrPeriod<=0)
|
||||
{
|
||||
ExtPeriodATR=14;
|
||||
PrintFormat("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
|
||||
}
|
||||
else
|
||||
ExtPeriodATR=InpAtrPeriod;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("ATR(%d)",ExtPeriodATR);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<=ExtPeriodATR)
|
||||
return(0);
|
||||
|
||||
int i,start;
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ExtTRBuffer[0]=0.0;
|
||||
ExtATRBuffer[0]=0.0;
|
||||
//--- filling out the array of True Range values for each period
|
||||
for(i=1; i<rates_total && !IsStopped(); i++)
|
||||
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
|
||||
//--- first AtrPeriod values of the indicator are not calculated
|
||||
double firstValue=0.0;
|
||||
for(i=1; i<=ExtPeriodATR; i++)
|
||||
{
|
||||
ExtATRBuffer[i]=0.0;
|
||||
firstValue+=ExtTRBuffer[i];
|
||||
}
|
||||
//--- calculating the first value of the indicator
|
||||
firstValue/=ExtPeriodATR;
|
||||
ExtATRBuffer[ExtPeriodATR]=firstValue;
|
||||
start=ExtPeriodATR+1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
|
||||
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,147 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accelerator.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accelerator/Decelerator"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrGreen,clrRed
|
||||
#property indicator_width1 2
|
||||
#property indicator_label1 "AC"
|
||||
//--- indicator buffers
|
||||
double ExtACBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtFastBuffer[];
|
||||
double ExtSlowBuffer[];
|
||||
double ExtAOBuffer[];
|
||||
double ExtSMABuffer[];
|
||||
//--- handles for MAs
|
||||
int ExtFastSMAHandle;
|
||||
int ExtSlowSMAHandle;
|
||||
//--- bars minimum for calculation
|
||||
#define DATA_LIMIT 37 // FAST_PERIOD-1 + SLOW_PERIOD-1
|
||||
//--- MA periods
|
||||
#define FAST_PERIOD 5
|
||||
#define SLOW_PERIOD 34
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtACBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtAOBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtSMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
|
||||
//--- name for DataWindow
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"AC");
|
||||
//--- get handles
|
||||
ExtFastSMAHandle=iMA(NULL,0,FAST_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
ExtSlowSMAHandle=iMA(NULL,0,SLOW_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accelerator/Decelerator Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get FastSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- calculations
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated<SLOW_PERIOD)
|
||||
{
|
||||
for(i=0; i<SLOW_PERIOD-1; i++)
|
||||
{
|
||||
ExtACBuffer[i]=0.0;
|
||||
ExtAOBuffer[i]=0.0;
|
||||
}
|
||||
start=SLOW_PERIOD-1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop of calculations
|
||||
for(i=start; i<DATA_LIMIT; i++)
|
||||
{
|
||||
ExtACBuffer[i]=0.0;
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
}
|
||||
for(; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
double sumAO=0.0;
|
||||
for(int j=0; j<FAST_PERIOD; j++)
|
||||
sumAO+=ExtAOBuffer[i-j];
|
||||
ExtSMABuffer[i]=sumAO/FAST_PERIOD;
|
||||
ExtACBuffer[i]=ExtAOBuffer[i]-ExtSMABuffer[i];
|
||||
if(ExtACBuffer[i]>=ExtACBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0; // set color Green
|
||||
else
|
||||
ExtColorBuffer[i]=1.0; // set color Red
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,148 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Alligator.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color1 clrBlue
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_width1 1
|
||||
#property indicator_width2 1
|
||||
#property indicator_width3 1
|
||||
#property indicator_label1 "Jaws"
|
||||
#property indicator_label2 "Teeth"
|
||||
#property indicator_label3 "Lips"
|
||||
//--- input parameters
|
||||
input int InpJawsPeriod=13; // Jaws period
|
||||
input int InpJawsShift=8; // Jaws shift
|
||||
input int InpTeethPeriod=8; // Teeth period
|
||||
input int InpTeethShift=5; // Teeth shift
|
||||
input int InpLipsPeriod=5; // Lips period
|
||||
input int InpLipsShift=3; // Lips shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtJaws[];
|
||||
double ExtTeeth[];
|
||||
double ExtLips[];
|
||||
//--- handles for moving averages
|
||||
int ExtJawsHandle;
|
||||
int ExtTeethHandle;
|
||||
int ExtLipsHandle;
|
||||
//--- bars minimum for calculation
|
||||
int ExtBarsMinimum;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtJaws,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTeeth,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLips,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpTeethPeriod-1);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpLipsPeriod-1);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpJawsShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,InpTeethShift);
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,InpLipsShift);
|
||||
//--- name for DataWindow
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Jaws("+string(InpJawsPeriod)+")");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Teeth("+string(InpTeethPeriod)+")");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Lips("+string(InpLipsPeriod)+")");
|
||||
//--- get MA's handles
|
||||
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
//--- bars minimum for calculation
|
||||
ExtBarsMinimum=InpJawsPeriod+InpJawsShift;
|
||||
if(ExtBarsMinimum<(InpTeethPeriod+InpTeethShift))
|
||||
ExtBarsMinimum=InpTeethPeriod+InpTeethShift;
|
||||
if(ExtBarsMinimum<(InpLipsPeriod+InpLipsPeriod))
|
||||
ExtBarsMinimum=InpLipsPeriod+InpLipsPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Alligator OnCalculate function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<ExtBarsMinimum)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtJawsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtJawsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtTeethHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtTeethHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtLipsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtLipsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJaws)<=0)
|
||||
{
|
||||
Print("getting ExtJawsHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeeth)<=0)
|
||||
{
|
||||
Print("getting ExtTeethHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLips)<=0)
|
||||
{
|
||||
Print("getting ExtLipsHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,127 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Awesome_Oscillator.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrGreen,clrRed
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "AO"
|
||||
//--- indicator buffers
|
||||
double ExtAOBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtFastBuffer[];
|
||||
double ExtSlowBuffer[];
|
||||
//--- handles for MAs
|
||||
int ExtFastSMAHandle;
|
||||
int ExtSlowSMAHandle;
|
||||
|
||||
#define DATA_LIMIT 33
|
||||
#define FAST_PERIOD 5
|
||||
#define SLOW_PERIOD 34
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtAOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,33);
|
||||
//--- name for DataWindow
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"AO");
|
||||
//--- get handles
|
||||
ExtFastSMAHandle=iMA(NULL,0,FAST_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
ExtSlowSMAHandle=iMA(NULL,0,SLOW_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Awesome Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<=DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get FastSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int i,start;
|
||||
if(prev_calculated<=DATA_LIMIT)
|
||||
{
|
||||
for(i=0; i<DATA_LIMIT; i++)
|
||||
ExtAOBuffer[i]=0.0;
|
||||
start=DATA_LIMIT;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop of calculations
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
if(ExtAOBuffer[i]>ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0; // set color Green
|
||||
else
|
||||
ExtColorBuffer[i]=1.0; // set color Red
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,141 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BB.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bollinger Bands"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrLightSeaGreen
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrLightSeaGreen
|
||||
#property indicator_label1 "Bands middle"
|
||||
#property indicator_label2 "Bands upper"
|
||||
#property indicator_label3 "Bands lower"
|
||||
//--- input parametrs
|
||||
input int InpBandsPeriod=20; // Period
|
||||
input int InpBandsShift=0; // Shift
|
||||
input double InpBandsDeviations=2.0; // Deviation
|
||||
//--- global variables
|
||||
int ExtBandsPeriod,ExtBandsShift;
|
||||
double ExtBandsDeviations;
|
||||
int ExtPlotBegin=0;
|
||||
//--- indicator buffer
|
||||
double ExtMLBuffer[];
|
||||
double ExtTLBuffer[];
|
||||
double ExtBLBuffer[];
|
||||
double ExtStdDevBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpBandsPeriod<2)
|
||||
{
|
||||
ExtBandsPeriod=20;
|
||||
PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
|
||||
}
|
||||
else
|
||||
ExtBandsPeriod=InpBandsPeriod;
|
||||
if(InpBandsShift<0)
|
||||
{
|
||||
ExtBandsShift=0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
|
||||
}
|
||||
else
|
||||
ExtBandsShift=InpBandsShift;
|
||||
if(InpBandsDeviations==0.0)
|
||||
{
|
||||
ExtBandsDeviations=2.0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
|
||||
}
|
||||
else
|
||||
ExtBandsDeviations=InpBandsDeviations;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtMLBuffer);
|
||||
SetIndexBuffer(1,ExtTLBuffer);
|
||||
SetIndexBuffer(2,ExtBLBuffer);
|
||||
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set index labels
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
|
||||
//--- indicator name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
|
||||
//--- indexes draw begin settings
|
||||
ExtPlotBegin=ExtBandsPeriod-1;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
//--- indexes shift settings
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bollinger Bands |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<ExtPlotBegin)
|
||||
return(0);
|
||||
//--- indexes draw begin settings, when we've recieved previous begin
|
||||
if(ExtPlotBegin!=ExtBandsPeriod+begin)
|
||||
{
|
||||
ExtPlotBegin=ExtBandsPeriod+begin;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
}
|
||||
//--- starting calculation
|
||||
int pos;
|
||||
if(prev_calculated>1)
|
||||
pos=prev_calculated-1;
|
||||
else
|
||||
pos=0;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- middle line
|
||||
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,price);
|
||||
//--- calculate and write down StdDev
|
||||
ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod);
|
||||
//--- upper line
|
||||
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
//--- lower line
|
||||
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Standard Deviation |
|
||||
//+------------------------------------------------------------------+
|
||||
double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period)
|
||||
{
|
||||
double std_dev=0.0;
|
||||
//--- calcualte StdDev
|
||||
if(position>=period)
|
||||
{
|
||||
for(int i=0; i<period; i++)
|
||||
std_dev+=MathPow(price[position-i]-ma_price[position],2.0);
|
||||
std_dev=MathSqrt(std_dev/period);
|
||||
}
|
||||
//--- return calculated value
|
||||
return(std_dev);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,134 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BW-ZoneTrade.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 clrGreen,clrRed,clrGray
|
||||
#property indicator_width1 3
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOBuffer[];
|
||||
double ExtHBuffer[];
|
||||
double ExtLBuffer[];
|
||||
double ExtCBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtAOBuffer[];
|
||||
double ExtACBuffer[];
|
||||
//--- handles of indicators
|
||||
int ExtACHandle;
|
||||
int ExtAOHandle;
|
||||
//--- bars minimum for calculation
|
||||
#define DATA_LIMIT 38
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(5,ExtACBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtAOBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"BW ZoneTrade");
|
||||
//--- don't show indicator data in DataWindow
|
||||
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
|
||||
//--- sets first candle from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
|
||||
//--- get handles
|
||||
ExtACHandle=iAC(NULL,0);
|
||||
ExtAOHandle=iAO(NULL,0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Trade zone by Bill Williams |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtACHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtACHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtAOHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtAOHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get AC buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtACHandle,0,0,to_copy,ExtACBuffer)<=0)
|
||||
{
|
||||
Print("Getting iAC is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get AO buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtAOHandle,0,0,to_copy,ExtAOBuffer)<=0)
|
||||
{
|
||||
Print("Getting iAO is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- set first bar from what calculation will start
|
||||
int start;
|
||||
if(prev_calculated<DATA_LIMIT)
|
||||
start=DATA_LIMIT;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtOBuffer[i]=open[i];
|
||||
ExtHBuffer[i]=high[i];
|
||||
ExtLBuffer[i]=low[i];
|
||||
ExtCBuffer[i]=close[i];
|
||||
//--- set color for candle
|
||||
ExtColorBuffer[i]=2.0; // set gray Color
|
||||
//--- check for Green Zone and set Color Green
|
||||
if(ExtACBuffer[i]>ExtACBuffer[i-1] && ExtAOBuffer[i]>ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0;
|
||||
//--- check for Red Zone and set Color Red
|
||||
if(ExtACBuffer[i]<ExtACBuffer[i-1] && ExtAOBuffer[i]<ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=1.0;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bears.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bears Power"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrSilver
|
||||
#property indicator_width1 2
|
||||
//--- input parameters
|
||||
input int InpBearsPeriod=13; // Period
|
||||
//--- indicator buffers
|
||||
double ExtBearsBuffer[];
|
||||
double ExtTempBuffer[];
|
||||
//--- handle of EMA
|
||||
int ExtEmaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtBearsBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBearsPeriod-1);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Bears(%d)",InpBearsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get MA handle
|
||||
ExtEmaHandle=iMA(_Symbol,_Period,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpBearsPeriod)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtEmaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtEmaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtEmaHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int start;
|
||||
if(prev_calculated<InpBearsPeriod)
|
||||
start=InpBearsPeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtBearsBuffer[i]=low[i]-ExtTempBuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bulls.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bulls Power"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrSilver
|
||||
#property indicator_width1 2
|
||||
//--- input parameters
|
||||
input int InpBullsPeriod=13; // Period
|
||||
//--- indicator buffers
|
||||
double ExtBullsBuffer[];
|
||||
double ExtTempBuffer[];
|
||||
//--- MA handle
|
||||
int ExtEmaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtBullsBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBullsPeriod-1);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Bulls(%d)",InpBullsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get handle for MA
|
||||
ExtEmaHandle=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpBullsPeriod)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtEmaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtEmaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtEmaHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int start;
|
||||
if(prev_calculated<InpBullsPeriod)
|
||||
start=InpBullsPeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CCI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Commodity Channel Index"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_level1 -100.0
|
||||
#property indicator_level2 100.0
|
||||
#property indicator_applied_price PRICE_TYPICAL
|
||||
//--- input parametrs
|
||||
input int InpCCIPeriod=14; // Period
|
||||
//--- indicator buffers
|
||||
double ExtSPBuffer[];
|
||||
double ExtDBuffer[];
|
||||
double ExtMBuffer[];
|
||||
double ExtCCIBuffer[];
|
||||
|
||||
int ExtCCIPeriod;
|
||||
double ExtMultiplyer;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value of period
|
||||
if(InpCCIPeriod<=0)
|
||||
{
|
||||
ExtCCIPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable InpCCIPeriod=%d. Indicator will use value=%d for calculations.",InpCCIPeriod,ExtCCIPeriod);
|
||||
}
|
||||
else
|
||||
ExtCCIPeriod=InpCCIPeriod;
|
||||
ExtMultiplyer=0.015/ExtCCIPeriod;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtCCIBuffer);
|
||||
SetIndexBuffer(1,ExtDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtMBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSPBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- indicator name
|
||||
string short_name=StringFormat("CCI(%d)",ExtCCIPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- indexes draw begin settings
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtCCIPeriod-1);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int start=(ExtCCIPeriod-1)+begin;
|
||||
if(rates_total<start)
|
||||
return(0);
|
||||
//--- correct draw begin
|
||||
if(begin>0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,start+(ExtCCIPeriod-1));
|
||||
//--- calculate position
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<start)
|
||||
pos=start;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtSPBuffer[i]=SimpleMA(i,ExtCCIPeriod,price);
|
||||
//--- calculate D
|
||||
double tmp_d=0.0;
|
||||
for(int j=0; j<ExtCCIPeriod; j++)
|
||||
tmp_d+=MathAbs(price[i-j]-ExtSPBuffer[i]);
|
||||
ExtDBuffer[i]=tmp_d*ExtMultiplyer;
|
||||
//--- calculate M
|
||||
ExtMBuffer[i]=price[i]-ExtSPBuffer[i];
|
||||
//--- calculate CCI
|
||||
if(ExtDBuffer[i]!=0.0)
|
||||
ExtCCIBuffer[i]=ExtMBuffer[i]/ExtDBuffer[i];
|
||||
else
|
||||
ExtCCIBuffer[i]=0.0;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CHO.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Chaikin Oscillator"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
//--- input parameters
|
||||
input int InpFastMA=3; // Fast MA period
|
||||
input int InpSlowMA=10; // Slow MA period
|
||||
input ENUM_MA_METHOD InpSmoothMethod=MODE_EMA; // MA method
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffers
|
||||
double ExtCHOBuffer[];
|
||||
double ExtFastEMABuffer[];
|
||||
double ExtSlowEMABuffer[];
|
||||
double ExtADBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtCHOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtFastEMABuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtSlowEMABuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtADBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowMA);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("CHO(%d,%d)",InpSlowMA,InpFastMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Chaikin Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpSlowMA)
|
||||
return(0);
|
||||
//--- preliminary calculations
|
||||
int i,start;
|
||||
if(prev_calculated<2)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-2;
|
||||
//--- calculate AD buffer
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtADBuffer[i]=AD(high[i],low[i],close[i],tick_volume[i]);
|
||||
if(i>0)
|
||||
ExtADBuffer[i]+=ExtADBuffer[i-1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtADBuffer[i]=AD(high[i],low[i],close[i],volume[i]);
|
||||
if(i>0)
|
||||
ExtADBuffer[i]+=ExtADBuffer[i-1];
|
||||
}
|
||||
}
|
||||
//--- calculate EMA on array ExtADBuffer
|
||||
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpFastMA,ExtADBuffer,ExtFastEMABuffer);
|
||||
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpSlowMA,ExtADBuffer,ExtSlowEMABuffer);
|
||||
//--- calculate chaikin oscillator
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtCHOBuffer[i]=ExtFastEMABuffer[i]-ExtSlowEMABuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| calculate AD |
|
||||
//+------------------------------------------------------------------+
|
||||
double AD(double high,double low,double close,long volume)
|
||||
{
|
||||
double res=0.0;
|
||||
//---
|
||||
double sum=(close-low)-(high-close);
|
||||
if(sum!=0.0)
|
||||
{
|
||||
if(high!=low)
|
||||
res=(sum/(high-low))*volume;
|
||||
}
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| calculate average on array |
|
||||
//+------------------------------------------------------------------+
|
||||
void AverageOnArray(const int mode,const int rates_total,const int prev_calculated,const int begin,
|
||||
const int period,const double& source[],double& destination[])
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case MODE_EMA:
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
case MODE_SMMA:
|
||||
SmoothedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
case MODE_LWMA:
|
||||
LinearWeightedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
default:
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,118 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CHV.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://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 clrDodgerBlue
|
||||
//--- 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
|
||||
//--- indicator buffers
|
||||
double ExtCHVBuffer[];
|
||||
double ExtHLBuffer[];
|
||||
double ExtSHLBuffer[];
|
||||
|
||||
int ExtSmoothPeriod,ExtCHVPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
string ma_name=EnumToString(InpSmoothType);
|
||||
//--- check inputs
|
||||
if(InpSmoothPeriod<=0)
|
||||
{
|
||||
ExtSmoothPeriod=10;
|
||||
PrintFormat("Incorrect value for input variable InpSmoothPeriod=%d. Indicator will use value=%d for calculations.",InpSmoothPeriod,ExtSmoothPeriod);
|
||||
}
|
||||
else
|
||||
ExtSmoothPeriod=InpSmoothPeriod;
|
||||
if(InpCHVPeriod<=0)
|
||||
{
|
||||
ExtCHVPeriod=10;
|
||||
PrintFormat("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 name and index label
|
||||
string params=StringFormat("(%d,%s)",ExtSmoothPeriod,ma_name);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Chaikin Volatility"+params);
|
||||
PlotIndexSetString(0,PLOT_LABEL,"CHV"+params);
|
||||
//--- round settings
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int i,pos,pos_chv;
|
||||
//--- check for rates total
|
||||
pos_chv=ExtCHVPeriod+ExtSmoothPeriod-2;
|
||||
if(rates_total<pos_chv)
|
||||
return(0);
|
||||
//--- start working
|
||||
if(prev_calculated<1)
|
||||
pos=0;
|
||||
else
|
||||
pos=prev_calculated-1;
|
||||
//--- fill H-L(i) buffer
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
ExtHLBuffer[i]=high[i]-low[i];
|
||||
//--- calculate smoothed H-L(i) buffer
|
||||
if(pos<ExtSmoothPeriod-1)
|
||||
{
|
||||
pos=ExtSmoothPeriod-1;
|
||||
for(i=0; i<pos; i++)
|
||||
ExtSHLBuffer[i]=0.0;
|
||||
}
|
||||
if(InpSmoothType==SMA)
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
|
||||
else
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
|
||||
//--- correct calc position
|
||||
if(pos<pos_chv)
|
||||
pos=pos_chv;
|
||||
//--- 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.
@@ -0,0 +1,73 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| FlameChart.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#include <Canvas\FlameCanvas.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Indicator properties |
|
||||
//+------------------------------------------------------------------+
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
//+------------------------------------------------------------------+
|
||||
//| Input parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
input int InpFuturefBars =50;
|
||||
//+------------------------------------------------------------------+
|
||||
//| global variables |
|
||||
//+------------------------------------------------------------------+
|
||||
CFlameCanvas ExtCanvas;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
if(!ExtCanvas.FlameCreate("FlameChart",TimeCurrent(),InpFuturefBars,0))
|
||||
return(INIT_FAILED);
|
||||
//--- succeed
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
datetime xb1=time[rates_total-1];
|
||||
double yb1=high[rates_total-1];
|
||||
datetime xe1=xb1+InpFuturefBars*PeriodSeconds();
|
||||
double ye1=ChartGetDouble(0,CHART_PRICE_MAX);
|
||||
datetime xb2=xb1;
|
||||
double yb2=low[rates_total-1];
|
||||
datetime xe2=xe1;
|
||||
double ye2=ChartGetDouble(0,CHART_PRICE_MIN);
|
||||
//--- "nozzle" is defined using two lines: ((xb1,yb1),(xe1,ye1)) and ((xb2,yb2),(xe2,ye2))
|
||||
ExtCanvas.FlameSet(xb1,yb1,xe1,ye1,xb2,yb2,xe2,ye2);
|
||||
//--- result
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator chart's event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
|
||||
{
|
||||
ExtCanvas.ChartEventHandler(id,lparam,dparam,sparam);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,82 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorBars.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorBars
|
||||
#property indicator_label1 "ColorBars"
|
||||
#property indicator_type1 DRAW_COLOR_BARS
|
||||
#property indicator_color1 clrGreen,clrRed
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOpenBuffer[];
|
||||
double ExtHighBuffer[];
|
||||
double ExtLowBuffer[];
|
||||
double ExtCloseBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicators
|
||||
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- don't show indicator data in DataWindow
|
||||
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int i=0;
|
||||
bool vol_up=true;
|
||||
//--- set position for beginning
|
||||
if(i<prev_calculated)
|
||||
i=prev_calculated-1;
|
||||
//--- start calculations
|
||||
while(i<rates_total && !IsStopped())
|
||||
{
|
||||
ExtOpenBuffer[i]=open[i];
|
||||
ExtHighBuffer[i]=high[i];
|
||||
ExtLowBuffer[i]=low[i];
|
||||
ExtCloseBuffer[i]=close[i];
|
||||
//--- determine volume change
|
||||
if(i>0)
|
||||
{
|
||||
if(tick_volume[i]>tick_volume[i-1])
|
||||
vol_up=true;
|
||||
if(tick_volume[i]<tick_volume[i-1])
|
||||
vol_up=false;
|
||||
}
|
||||
if(vol_up)
|
||||
ExtColorsBuffer[i]=0.0;
|
||||
else
|
||||
ExtColorsBuffer[i]=1.0;
|
||||
i++;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,78 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorCandlesDaily.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorCandles
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOpenBuffer[];
|
||||
double ExtHighBuffer[];
|
||||
double ExtLowBuffer[];
|
||||
double ExtCloseBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
//---
|
||||
color ExtColorOfDay[6]= {clrNONE,clrMediumSlateBlue,clrDarkGoldenrod,clrForestGreen,clrBlueViolet,clrRed};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- set number of colors in color buffer
|
||||
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,6);
|
||||
//--- set colors for color buffer
|
||||
for(int i=1; i<6; i++)
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,i,ExtColorOfDay[i]);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
PrintFormat("We have %i colors of days",PlotIndexGetInteger(0,PLOT_COLOR_INDEXES));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int pos;
|
||||
MqlDateTime tstruct;
|
||||
//---
|
||||
if(prev_calculated<1)
|
||||
pos=0;
|
||||
else
|
||||
pos=prev_calculated-1;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtOpenBuffer[i]=open[i];
|
||||
ExtHighBuffer[i]=high[i];
|
||||
ExtLowBuffer[i]=low[i];
|
||||
ExtCloseBuffer[i]=close[i];
|
||||
//--- set color for every candle
|
||||
TimeToStruct(time[i],tstruct);
|
||||
ExtColorsBuffer[i]=tstruct.day_of_week;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,133 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorLine.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorLine
|
||||
#property indicator_label1 "ColorLine"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrRed,clrGreen,clrBlue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 3
|
||||
//--- indicator buffers
|
||||
double ExtColorLineBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
|
||||
int ExtMAHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtColorLineBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- get MA handle
|
||||
ExtMAHandle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
static int ticks=0,modified=0;
|
||||
//--- check data
|
||||
int calculated=BarsCalculated(ExtMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
//--- copy values of MA into indicator buffer ExtColorLineBuffer
|
||||
if(CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer)<=0)
|
||||
return(0);
|
||||
//--- now set line color for every bar
|
||||
for(int i=0; i<rates_total && !IsStopped(); i++)
|
||||
ExtColorsBuffer[i]=getIndexOfColor(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- copy values of MA into indicator buffer ExtColorLineBuffer
|
||||
int copied=CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer);
|
||||
if(copied<=0)
|
||||
return(0);
|
||||
|
||||
ticks++; // ticks counting
|
||||
if(ticks>=5) //it's time to change color scheme
|
||||
{
|
||||
ticks=0; // reset counter
|
||||
modified++; // counter of color changes
|
||||
if(modified>=3)
|
||||
modified=0;// reset counter
|
||||
ResetLastError();
|
||||
switch(modified)
|
||||
{
|
||||
case 0: // first color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen);
|
||||
break;
|
||||
case 1: // second color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray);
|
||||
break;
|
||||
default: // third color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- set start position
|
||||
int start=prev_calculated-1;
|
||||
//--- now we set line color for every bar
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtColorsBuffer[i]=getIndexOfColor(i);
|
||||
}
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get color index |
|
||||
//+------------------------------------------------------------------+
|
||||
int getIndexOfColor(const int i)
|
||||
{
|
||||
int j=i%300;
|
||||
if(j<100) // first index
|
||||
return(0);
|
||||
if(j<200) // second index
|
||||
return(1);
|
||||
return(2); // third index
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,199 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom Moving Average.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
//--- input parameters
|
||||
input int InpMAPeriod=13; // Period
|
||||
input int InpMAShift=0; // Shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Method
|
||||
//--- indicator buffer
|
||||
double ExtLineBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- set first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
|
||||
//--- name for DataWindow
|
||||
string short_name;
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA :
|
||||
short_name="EMA";
|
||||
break;
|
||||
case MODE_LWMA :
|
||||
short_name="LWMA";
|
||||
break;
|
||||
case MODE_SMA :
|
||||
short_name="SMA";
|
||||
break;
|
||||
case MODE_SMMA :
|
||||
short_name="SMMA";
|
||||
break;
|
||||
default :
|
||||
short_name="unknown ma";
|
||||
}
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")");
|
||||
//--- set drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<InpMAPeriod-1+begin)
|
||||
return(0);
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ArrayInitialize(ExtLineBuffer,0);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1+begin);
|
||||
}
|
||||
//--- calculation
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA:
|
||||
CalculateEMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_LWMA:
|
||||
CalculateLWMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_SMMA:
|
||||
CalculateSmoothedMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_SMA:
|
||||
CalculateSimpleMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| simple moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateSimpleMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start-1; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
//--- calculate first visible value
|
||||
double first_value=0;
|
||||
for(i=begin; i<start; i++)
|
||||
first_value+=price[i];
|
||||
first_value/=InpMAPeriod;
|
||||
ExtLineBuffer[start-1]=first_value;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=ExtLineBuffer[i-1]+(price[i]-price[i-InpMAPeriod])/InpMAPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| exponential moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateEMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
double SmoothFactor=2.0/(1.0+InpMAPeriod);
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
ExtLineBuffer[begin]=price[begin];
|
||||
for(i=begin+1; i<start; i++)
|
||||
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| linear weighted moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateLWMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int weight=0;
|
||||
int i,l,start;
|
||||
double sum=0.0,lsum=0.0;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated<=InpMAPeriod+begin+2)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
|
||||
for(i=start-InpMAPeriod,l=1; i<start; i++,l++)
|
||||
{
|
||||
sum +=price[i]*l;
|
||||
lsum +=price[i];
|
||||
weight+=l;
|
||||
}
|
||||
ExtLineBuffer[start-1]=sum/weight;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
sum =sum-lsum+price[i]*InpMAPeriod;
|
||||
lsum =lsum-price[i-InpMAPeriod]+price[i];
|
||||
ExtLineBuffer[i]=sum/weight;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| smoothed moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateSmoothedMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start-1; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
//--- calculate first visible value
|
||||
double first_value=0;
|
||||
for(i=begin; i<start; i++)
|
||||
first_value+=price[i];
|
||||
first_value/=InpMAPeriod;
|
||||
ExtLineBuffer[start-1]=first_value;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=(ExtLineBuffer[i-1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| DEMA.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Double Exponential Moving Average"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDarkBlue
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "DEMA"
|
||||
#property indicator_applied_price PRICE_CLOSE
|
||||
//--- input parameters
|
||||
input int InpPeriodEMA=14; // EMA period
|
||||
input int InpShift=0; // Indicator's shift
|
||||
//--- indicator buffers
|
||||
double DemaBuffer[];
|
||||
double Ema[];
|
||||
double EmaOfEma[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,DemaBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodEMA-2);
|
||||
//--- sets indicator shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
|
||||
//--- name of label
|
||||
string short_name=StringFormat("DEMA(%d)",InpPeriodEMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Double Exponential Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<2*InpPeriodEMA-2)
|
||||
return(0);
|
||||
//---
|
||||
int start;
|
||||
if(prev_calculated==0)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- calculate EMA
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema);
|
||||
//--- calculate EMA on EMA array
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma);
|
||||
//--- calculate DEMA
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
DemaBuffer[i]=2.0*Ema[i]-EmaOfEma[i];
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,69 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| DPO.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Detrended Price Oscillator"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parameters
|
||||
input int InpDetrendPeriod=12; // Period
|
||||
//--- indicator buffers
|
||||
double ExtDPOBuffer[];
|
||||
double ExtMABuffer[];
|
||||
|
||||
int ExtMAPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- get length of cycle for smoothing
|
||||
ExtMAPeriod=InpDetrendPeriod/2+1;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtDPOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- set first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMAPeriod-1);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("DPO(%d)",InpDetrendPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Detrended Price Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int start;
|
||||
int first_index=begin+ExtMAPeriod-1;
|
||||
//--- preliminary filling
|
||||
if(prev_calculated<first_index)
|
||||
{
|
||||
ArrayInitialize(ExtDPOBuffer,0.0);
|
||||
start=first_index;
|
||||
if(begin>0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,first_index);
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- calculate simple moving average
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,begin,ExtMAPeriod,price,ExtMABuffer);
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtDPOBuffer[i]=price[i]-ExtMABuffer[i];
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,111 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| DeMarker.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_level1 0.3
|
||||
#property indicator_level2 0.7
|
||||
//--- input parameters
|
||||
input int InpDeMarkerPeriod=14; // Period
|
||||
//--- indicator buffers
|
||||
double ExtDeMarkerBuffer[];
|
||||
double ExtDeMaxBuffer[];
|
||||
double ExtDeMinBuffer[];
|
||||
double ExtAvgDeMaxBuffer[];
|
||||
double ExtAvgDeMinBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtDeMarkerBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtDeMaxBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtDeMinBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtAvgDeMaxBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtAvgDeMinBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,3);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpDeMarkerPeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("DeM(%d)",InpDeMarkerPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| DeMarker |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpDeMarkerPeriod)
|
||||
return(0);
|
||||
|
||||
int i,start;
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ExtDeMaxBuffer[0]=0.0;
|
||||
ExtDeMinBuffer[0]=0.0;
|
||||
//--- filling out the array of True Range values for each period
|
||||
for(i=1; i<InpDeMarkerPeriod; i++)
|
||||
{
|
||||
if(high[i]>high[i-1])
|
||||
ExtDeMaxBuffer[i]=high[i]-high[i-1];
|
||||
else
|
||||
ExtDeMaxBuffer[i]=0.0;
|
||||
|
||||
if(low[i-1]>low[i])
|
||||
ExtDeMinBuffer[i]=low[i-1]-low[i];
|
||||
else
|
||||
ExtDeMinBuffer[i]=0.0;
|
||||
}
|
||||
for(i=0; i<InpDeMarkerPeriod; i++)
|
||||
ExtDeMarkerBuffer[i]=0.0;
|
||||
start=InpDeMarkerPeriod-1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(high[i]>high[i-1])
|
||||
ExtDeMaxBuffer[i]=high[i]-high[i-1];
|
||||
else
|
||||
ExtDeMaxBuffer[i]=0.0;
|
||||
|
||||
if(low[i-1]>low[i])
|
||||
ExtDeMinBuffer[i]=low[i-1]-low[i];
|
||||
else
|
||||
ExtDeMinBuffer[i]=0.0;
|
||||
|
||||
ExtAvgDeMaxBuffer[i]=SimpleMA(i,InpDeMarkerPeriod,ExtDeMaxBuffer);
|
||||
ExtAvgDeMinBuffer[i]=SimpleMA(i,InpDeMarkerPeriod,ExtDeMinBuffer);
|
||||
|
||||
double dnum=ExtAvgDeMaxBuffer[i]+ExtAvgDeMinBuffer[i];
|
||||
if(dnum!=0)
|
||||
ExtDeMarkerBuffer[i]=ExtAvgDeMaxBuffer[i]/dnum;
|
||||
else
|
||||
ExtDeMarkerBuffer[i]=0.0;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,108 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Envelopes.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://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 clrBlue
|
||||
#property indicator_color2 clrRed
|
||||
#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 ExtMAHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtUpBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtDownBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtMABuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1);
|
||||
//--- name for DataWindow
|
||||
string short_name=StringFormat("Env(%d)",InpMAPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name+" Upper");
|
||||
PlotIndexSetString(1,PLOT_LABEL,short_name+" Lower");
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,InpMAShift);
|
||||
//---
|
||||
ExtMAHandle=iMA(NULL,0,InpMAPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Envelopes |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpMAPeriod)
|
||||
return(0);
|
||||
|
||||
int calculated=BarsCalculated(ExtMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
|
||||
{
|
||||
Print("Getting MA data is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- preliminary calculations
|
||||
int start=prev_calculated-1;
|
||||
if(start<InpMAPeriod)
|
||||
start=InpMAPeriod;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtUpBuffer[i]=(1+InpDeviation/100.0)*ExtMABuffer[i];
|
||||
ExtDownBuffer[i]=(1-InpDeviation/100.0)*ExtMABuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,101 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Force_Index.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parameters
|
||||
input int InpForcePeriod=13; // Period
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // MA method
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
|
||||
input ENUM_APPLIED_VOLUME InpAppliedVolume=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffers
|
||||
double ExtForceBuffer[];
|
||||
double ExtMABuffer[];
|
||||
|
||||
int ExtMAHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtForceBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpForcePeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Force(%d)",InpForcePeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get MA handle
|
||||
ExtMAHandle=iMA(NULL,0,InpForcePeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Force Index |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpForcePeriod)
|
||||
return(0);
|
||||
|
||||
int calculated=BarsCalculated(ExtMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
|
||||
{
|
||||
Print("Getting MA data is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- preliminary calculations
|
||||
int i,start;
|
||||
if(prev_calculated<InpForcePeriod)
|
||||
start=InpForcePeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
if(InpAppliedVolume==VOLUME_TICK)
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtForceBuffer[i]=tick_volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtForceBuffer[i]=volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| FrAMA.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Fractal Adaptive Moving Average"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDarkBlue
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "FrAMA"
|
||||
#property indicator_applied_price PRICE_CLOSE
|
||||
//--- input parameters
|
||||
input int InpPeriodFrAMA=14; // FrAMA period
|
||||
input int InpShift=0; // Indicator's shift
|
||||
//--- indicator buffer
|
||||
double FrAmaBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,FrAmaBuffer,INDICATOR_DATA);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodFrAMA-1);
|
||||
//--- sets indicator shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
|
||||
//--- name for labels
|
||||
string short_name=StringFormat("FrAMA(%d)",InpPeriodFrAMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fractal Adaptive Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<2*InpPeriodFrAMA)
|
||||
return(0);
|
||||
|
||||
int start;
|
||||
//--- start calculations
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=2*InpPeriodFrAMA-1;
|
||||
for(int i=0; i<=start; i++)
|
||||
FrAmaBuffer[i]=price[i];
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main cycle
|
||||
double math_log_2=MathLog(2.0);
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double hi1=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,InpPeriodFrAMA,rates_total-i-1));
|
||||
double lo1=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,InpPeriodFrAMA,rates_total-i-1));
|
||||
double hi2=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,InpPeriodFrAMA,rates_total-i+InpPeriodFrAMA-1));
|
||||
double lo2=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,InpPeriodFrAMA,rates_total-i+InpPeriodFrAMA-1));
|
||||
double hi3=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,2*InpPeriodFrAMA,rates_total-i-1));
|
||||
double lo3=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,2*InpPeriodFrAMA,rates_total-i-1));
|
||||
double n1=(hi1-lo1)/InpPeriodFrAMA;
|
||||
double n2=(hi2-lo2)/InpPeriodFrAMA;
|
||||
double n3=(hi3-lo3)/(2*InpPeriodFrAMA);
|
||||
double d=(MathLog(n1+n2)-MathLog(n3))/math_log_2;
|
||||
double alfa=MathExp(-4.6*(d-1.0));
|
||||
//---
|
||||
FrAmaBuffer[i]=alfa*price[i]+(1-alfa)*FrAmaBuffer[i-1];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,88 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fractals.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color1 clrGray
|
||||
#property indicator_color2 clrGray
|
||||
#property indicator_label1 "Fractal Up"
|
||||
#property indicator_label2 "Fractal Down"
|
||||
//--- indicator buffers
|
||||
double ExtUpperBuffer[];
|
||||
double ExtLowerBuffer[];
|
||||
//--- 10 pixels upper from high price
|
||||
int ExtArrowShift=-10;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,217);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW,218);
|
||||
//--- arrow shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
|
||||
//--- sets drawing line empty value--
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fractals on 5 bars |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<5)
|
||||
return(0);
|
||||
|
||||
int start;
|
||||
//--- clean up arrays
|
||||
if(prev_calculated<7)
|
||||
{
|
||||
start=2;
|
||||
ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
|
||||
ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
|
||||
}
|
||||
else
|
||||
start=rates_total-5;
|
||||
//--- main cycle of calculations
|
||||
for(int i=start; i<rates_total-3 && !IsStopped(); i++)
|
||||
{
|
||||
//--- Upper Fractal
|
||||
if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>=high[i-1] && high[i]>=high[i-2])
|
||||
ExtUpperBuffer[i]=high[i];
|
||||
else
|
||||
ExtUpperBuffer[i]=EMPTY_VALUE;
|
||||
|
||||
//--- Lower Fractal
|
||||
if(low[i]<low[i+1] && low[i]<low[i+2] && low[i]<=low[i-1] && low[i]<=low[i-2])
|
||||
ExtLowerBuffer[i]=low[i];
|
||||
else
|
||||
ExtLowerBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,264 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Gator.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Gator Oscillator"
|
||||
#property description "based on 3 non-shifted moving averages"
|
||||
//********************************************************************
|
||||
// Attention! Following correlations must be obeyed:
|
||||
// 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod;
|
||||
// 2.InpJawsShift>InpTeethShift>InpLipsShift;
|
||||
// 3.InpJawsPeriod>InpJawsShift;
|
||||
// 4.InpTeethPeriod>InpTeethShift;
|
||||
// 5.InpLipsPeriod>InpLipsShift.
|
||||
//********************************************************************
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrGreen,clrRed
|
||||
#property indicator_color2 clrGreen,clrRed
|
||||
#property indicator_width1 2
|
||||
#property indicator_width2 2
|
||||
#property indicator_label1 "Gator Upper"
|
||||
#property indicator_label2 "Gator Lower"
|
||||
//--- input parameters
|
||||
input int InpJawsPeriod=13; // Jaws period
|
||||
input int InpJawsShift=8; // Jaws shift
|
||||
input int InpTeethPeriod=8; // Teeth period
|
||||
input int InpTeethShift=5; // Teeth shift
|
||||
input int InpLipsPeriod=5; // Lips period
|
||||
input int InpLipsShift=3; // Lips shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtUpperBuffer[];
|
||||
double ExtUpColorsBuffer[];
|
||||
double ExtLowerBuffer[];
|
||||
double ExtLoColorsBuffer[];
|
||||
double ExtJawsBuffer[];
|
||||
double ExtTeethBuffer[];
|
||||
double ExtLipsBuffer[];
|
||||
|
||||
int ExtJawsHandle;
|
||||
int ExtTeethHandle;
|
||||
int ExtLipsHandle;
|
||||
int ExtUpperShift;
|
||||
int ExtLowerShift;
|
||||
bool ExtFlag;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtUpColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtLowerBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtLoColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- MAs
|
||||
SetIndexBuffer(4,ExtJawsBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtTeethBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtLipsBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- get handles
|
||||
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTeethShift+InpTeethPeriod);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpLipsShift+InpLipsPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpTeethShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,InpLipsShift);
|
||||
//--- name for indicator subwindow label
|
||||
string short_name=StringFormat("Gator(%d,%d,%d)",InpJawsPeriod,InpTeethPeriod,InpLipsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- sets drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
|
||||
//--- calculate global variables values
|
||||
ExtUpperShift=InpJawsShift-InpTeethShift;
|
||||
ExtLowerShift=InpTeethShift-InpLipsShift;
|
||||
//--- check for input parameters
|
||||
ExtFlag=CheckForInput();
|
||||
if(!ExtFlag)
|
||||
Print("Wrong input parameters. Indicator won't work.");
|
||||
//--- initialization done. 0 returned if ExtFlag is true
|
||||
return(!ExtFlag);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Gator Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int shift;
|
||||
//--- check for rules and bars count
|
||||
if(ExtUpperShift>ExtLowerShift)
|
||||
shift=ExtUpperShift;
|
||||
else
|
||||
shift=ExtLowerShift;
|
||||
if(!ExtFlag || shift>rates_total)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtJawsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtJawsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtTeethHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtTeethHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtLipsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtLipsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJawsBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtJawsHandle is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeethBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtTeethHandle is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLipsBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtLipsHandle is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- last 2 counted bars will be recounted
|
||||
int pos=prev_calculated-2;
|
||||
if(pos<shift)
|
||||
{
|
||||
for(int i=0; i<shift; i++)
|
||||
{
|
||||
ExtUpperBuffer[i]=0.0;
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
ExtLowerBuffer[i]=0.0;
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
pos=shift;
|
||||
}
|
||||
//--- main cycle
|
||||
double cur_value,prev_value;
|
||||
int lower_limit=ExtLowerShift+InpLipsShift+InpLipsPeriod;
|
||||
int upper_limit=ExtUpperShift+InpTeethShift+InpTeethPeriod;
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(i>=lower_limit)
|
||||
{
|
||||
//--- calculate down buffer value
|
||||
cur_value=-MathAbs(ExtTeethBuffer[i-ExtLowerShift]-ExtLipsBuffer[i]);
|
||||
prev_value=ExtLowerBuffer[i-1];
|
||||
ExtLowerBuffer[i]=cur_value;
|
||||
//--- set down buffer color
|
||||
if(prev_value==cur_value)
|
||||
ExtLoColorsBuffer[i]=ExtLoColorsBuffer[i-1];
|
||||
else
|
||||
{
|
||||
if(prev_value<cur_value)
|
||||
ExtLoColorsBuffer[i]=1.0;
|
||||
else
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtLowerBuffer[i]=0.0;
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
if(i>=upper_limit)
|
||||
{
|
||||
//--- calculate up buffer value
|
||||
cur_value=MathAbs(ExtJawsBuffer[i-ExtUpperShift]-ExtTeethBuffer[i]);
|
||||
ExtUpperBuffer[i]=cur_value;
|
||||
prev_value=ExtUpperBuffer[i-1];
|
||||
//--- set up buffer color
|
||||
if(prev_value==cur_value)
|
||||
ExtUpColorsBuffer[i]=ExtUpColorsBuffer[i-1];
|
||||
else
|
||||
{
|
||||
if(prev_value<cur_value)
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
else
|
||||
ExtUpColorsBuffer[i]=1.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtUpperBuffer[i]=0.0;
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Check for rules |
|
||||
//| 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod; |
|
||||
//| 2.InpJawsShift>InpTeethShift>InpLipsShift; |
|
||||
//| 3.InpJawsPeriod>InpJawsShift; |
|
||||
//| 4.InpTeethPeriod>InpTeethShift; |
|
||||
//| 5.InpLipsPeriod>InpLipsShift. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CheckForInput()
|
||||
{
|
||||
//--- 1
|
||||
if(InpJawsPeriod<=InpTeethPeriod || InpTeethPeriod<=InpLipsPeriod)
|
||||
return(false);
|
||||
//--- 2
|
||||
if(InpJawsShift<=InpTeethShift || InpTeethShift<=InpLipsShift)
|
||||
return(false);
|
||||
//--- 3
|
||||
if(InpJawsPeriod<=InpJawsShift)
|
||||
return(false);
|
||||
//--- 4
|
||||
if(InpTeethPeriod<=InpTeethShift)
|
||||
return(false);
|
||||
//--- 5
|
||||
if(InpLipsPeriod<=InpLipsShift)
|
||||
return(false);
|
||||
//--- all right
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,252 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Gator.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Gator Oscillator"
|
||||
#property description "based on shifted Alligator buffers"
|
||||
//********************************************************************
|
||||
// Attention! Following correlations must be obeyed:
|
||||
// 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod;
|
||||
// 2.InpJawsShift>InpTeethShift>InpLipsShift;
|
||||
// 3.InpJawsPeriod>InpJawsShift;
|
||||
// 4.InpTeethPeriod>InpTeethShift;
|
||||
// 5.InpLipsPeriod>InpLipsShift.
|
||||
//********************************************************************
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrGreen,clrRed
|
||||
#property indicator_color2 clrGreen,clrRed
|
||||
#property indicator_width1 2
|
||||
#property indicator_width2 2
|
||||
#property indicator_label1 "Gator Upper"
|
||||
#property indicator_label2 "Gator Lower"
|
||||
//--- input parameters
|
||||
input int InpJawsPeriod=13; // Jaws period
|
||||
input int InpJawsShift=8; // Jaws shift
|
||||
input int InpTeethPeriod=8; // Teeth period
|
||||
input int InpTeethShift=5; // Teeth shift
|
||||
input int InpLipsPeriod=5; // Lips period
|
||||
input int InpLipsShift=3; // Lips shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtUpperBuffer[];
|
||||
double ExtUpColorsBuffer[];
|
||||
double ExtLowerBuffer[];
|
||||
double ExtLoColorsBuffer[];
|
||||
double ExtJawsBuffer[];
|
||||
double ExtTeethBuffer[];
|
||||
double ExtLipsBuffer[];
|
||||
|
||||
int ExtAlligatorHandle;
|
||||
int ExtUpperShift;
|
||||
int ExtLowerShift;
|
||||
bool ExtFlag;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtUpColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtLowerBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtLoColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- MAs
|
||||
SetIndexBuffer(4,ExtJawsBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtTeethBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtLipsBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- get handles
|
||||
ExtAlligatorHandle=iAlligator(NULL,0,
|
||||
InpJawsPeriod,0,
|
||||
InpTeethPeriod,0,
|
||||
InpLipsPeriod,0,
|
||||
InpMAMethod,InpAppliedPrice);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTeethShift+InpTeethPeriod);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpLipsShift+InpLipsPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpTeethShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,InpLipsShift);
|
||||
//--- name for indicator subwindow label
|
||||
string short_name=StringFormat("Gator(%d,%d,%d)",InpJawsPeriod,InpTeethPeriod,InpLipsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- sets drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
|
||||
//--- calculate global variables values
|
||||
ExtUpperShift=InpJawsShift-InpTeethShift;
|
||||
ExtLowerShift=InpTeethShift-InpLipsShift;
|
||||
//--- check for input parameters
|
||||
ExtFlag=CheckForInput();
|
||||
if(!ExtFlag)
|
||||
Print("Wrong input parameters. Indicator won't work.");
|
||||
//--- initialization done. 0 returned if ExtFlag is true
|
||||
return(ExtFlag?0:1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Gator Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int shift;
|
||||
//--- check for rules and bars count
|
||||
if(ExtUpperShift>ExtLowerShift)
|
||||
shift=ExtUpperShift;
|
||||
else
|
||||
shift=ExtLowerShift;
|
||||
if(!ExtFlag || shift>rates_total)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtAlligatorHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtAlligatorHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get alligator buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtAlligatorHandle,0,0,to_copy,ExtJawsBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtAlligatorHandle buffer 0 is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtAlligatorHandle,1,0,to_copy,ExtTeethBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtAlligatorHandle buffer 1 is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtAlligatorHandle,2,0,to_copy,ExtLipsBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtAlligatorHandle buffer 2 is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- last counted bar will be recounted
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<shift)
|
||||
{
|
||||
for(int i=0; i<shift; i++)
|
||||
{
|
||||
ExtUpperBuffer[i]=0.0;
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
ExtLowerBuffer[i]=0.0;
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
pos=shift;
|
||||
}
|
||||
//--- main cycle
|
||||
double cur_value,prev_value;
|
||||
int lower_limit=ExtLowerShift+InpLipsShift+InpLipsPeriod;
|
||||
int upper_limit=ExtUpperShift+InpTeethShift+InpTeethPeriod;
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(i>=lower_limit)
|
||||
{
|
||||
//--- calculate down buffer value
|
||||
cur_value=-fabs(ExtTeethBuffer[i-ExtLowerShift]-ExtLipsBuffer[i]);
|
||||
prev_value=ExtLowerBuffer[i-1];
|
||||
ExtLowerBuffer[i]=cur_value;
|
||||
//--- set down buffer color
|
||||
if(prev_value==cur_value)
|
||||
ExtLoColorsBuffer[i]=ExtLoColorsBuffer[i-1];
|
||||
else
|
||||
{
|
||||
if(prev_value<cur_value)
|
||||
ExtLoColorsBuffer[i]=1.0;
|
||||
else
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtLowerBuffer[i]=0.0;
|
||||
ExtLoColorsBuffer[i]=0.0;
|
||||
}
|
||||
if(i>=upper_limit)
|
||||
{
|
||||
//--- calculate up buffer value
|
||||
cur_value=fabs(ExtJawsBuffer[i-ExtUpperShift]-ExtTeethBuffer[i]);
|
||||
ExtUpperBuffer[i]=cur_value;
|
||||
prev_value=ExtUpperBuffer[i-1];
|
||||
//--- set up buffer color
|
||||
if(prev_value==cur_value)
|
||||
ExtUpColorsBuffer[i]=ExtUpColorsBuffer[i-1];
|
||||
else
|
||||
{
|
||||
if(prev_value<cur_value)
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
else
|
||||
ExtUpColorsBuffer[i]=1.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtUpperBuffer[i]=0.0;
|
||||
ExtUpColorsBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Check for rules |
|
||||
//| 1.InpJawsPeriod>InpTeethPeriod>InpLipsPeriod; |
|
||||
//| 2.InpJawsShift>InpTeethShift>InpLipsShift; |
|
||||
//| 3.InpJawsPeriod>InpJawsShift; |
|
||||
//| 4.InpTeethPeriod>InpTeethShift; |
|
||||
//| 5.InpLipsPeriod>InpLipsShift. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CheckForInput()
|
||||
{
|
||||
//--- 1
|
||||
if(InpJawsPeriod<=InpTeethPeriod || InpTeethPeriod<=InpLipsPeriod)
|
||||
return(false);
|
||||
//--- 2
|
||||
if(InpJawsShift<=InpTeethShift || InpTeethShift<=InpLipsShift)
|
||||
return(false);
|
||||
//--- 3
|
||||
if(InpJawsPeriod<=InpJawsShift)
|
||||
return(false);
|
||||
//--- 4
|
||||
if(InpTeethPeriod<=InpTeethShift)
|
||||
return(false);
|
||||
//--- 5
|
||||
if(InpLipsPeriod<=InpLipsShift)
|
||||
return(false);
|
||||
//--- all right
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ProjectName |
|
||||
//| Copyright 2020, CompanyName |
|
||||
//| http://www.companyname.net |
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Heiken_Ashi.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 clrDodgerBlue,clrRed
|
||||
#property indicator_label1 "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"
|
||||
//--- indicator buffers
|
||||
double ExtOBuffer[];
|
||||
double ExtHBuffer[];
|
||||
double ExtLBuffer[];
|
||||
double ExtCBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Heiken Ashi");
|
||||
//--- sets drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Heiken Ashi |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int start;
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ExtLBuffer[0]=low[0];
|
||||
ExtHBuffer[0]=high[0];
|
||||
ExtOBuffer[0]=open[0];
|
||||
ExtCBuffer[0]=close[0];
|
||||
start=1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double ha_open =(ExtOBuffer[i-1]+ExtCBuffer[i-1])/2;
|
||||
double ha_close=(open[i]+high[i]+low[i]+close[i])/4;
|
||||
double ha_high =MathMax(high[i],MathMax(ha_open,ha_close));
|
||||
double ha_low =MathMin(low[i],MathMin(ha_open,ha_close));
|
||||
|
||||
ExtLBuffer[i]=ha_low;
|
||||
ExtHBuffer[i]=ha_high;
|
||||
ExtOBuffer[i]=ha_open;
|
||||
ExtCBuffer[i]=ha_close;
|
||||
|
||||
//--- set candle color
|
||||
if(ha_open<ha_close)
|
||||
ExtColorBuffer[i]=0.0; // set color DodgerBlue
|
||||
else
|
||||
ExtColorBuffer[i]=1.0; // set color Red
|
||||
}
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ichimoku.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Ichimoku Kinko Hyo"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 4
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_type3 DRAW_FILLING
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_color3 clrSandyBrown,clrThistle
|
||||
#property indicator_color4 clrLime
|
||||
#property indicator_label1 "Tenkan-sen"
|
||||
#property indicator_label2 "Kijun-sen"
|
||||
#property indicator_label3 "Senkou Span A;Senkou Span B"
|
||||
#property indicator_label4 "Chikou Span"
|
||||
//--- input parameters
|
||||
input int InpTenkan=9; // Tenkan-sen
|
||||
input int InpKijun=26; // Kijun-sen
|
||||
input int InpSenkou=52; // Senkou Span B
|
||||
//--- indicator buffers
|
||||
double ExtTenkanBuffer[];
|
||||
double ExtKijunBuffer[];
|
||||
double ExtSpanABuffer[];
|
||||
double ExtSpanBBuffer[];
|
||||
double ExtChikouBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtSpanABuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtSpanBBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtChikouBuffer,INDICATOR_DATA);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTenkan);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKijun);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSenkou-1);
|
||||
//--- lines shifts when drawing
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,InpKijun);
|
||||
PlotIndexSetInteger(3,PLOT_SHIFT,-InpKijun);
|
||||
//--- change labels for DataWindow
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Senkou Span A;Senkou Span B("+string(InpSenkou)+")");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ichimoku Kinko Hyo |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int start;
|
||||
//---
|
||||
if(prev_calculated==0)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtChikouBuffer[i]=close[i];
|
||||
//--- tenkan sen
|
||||
double price_max=Highest(high,InpTenkan,i);
|
||||
double price_min=Lowest(low,InpTenkan,i);
|
||||
ExtTenkanBuffer[i]=(price_max+price_min)/2.0;
|
||||
//--- kijun sen
|
||||
price_max=Highest(high,InpKijun,i);
|
||||
price_min=Lowest(low,InpKijun,i);
|
||||
ExtKijunBuffer[i]=(price_max+price_min)/2.0;
|
||||
//--- senkou span a
|
||||
ExtSpanABuffer[i]=(ExtTenkanBuffer[i]+ExtKijunBuffer[i])/2.0;
|
||||
//--- senkou span b
|
||||
price_max=Highest(high,InpSenkou,i);
|
||||
price_min=Lowest(low,InpSenkou,i);
|
||||
ExtSpanBBuffer[i]=(price_max+price_min)/2.0;
|
||||
}
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get price_max value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Highest(const double& array[],const int range,int from_index)
|
||||
{
|
||||
double res=0;
|
||||
//---
|
||||
res=array[from_index];
|
||||
for(int i=from_index; i>from_index-range && i>=0; i--)
|
||||
if(res<array[i])
|
||||
res=array[i];
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get price_min value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Lowest(const double& array[],const int range,int from_index)
|
||||
{
|
||||
double res=0;
|
||||
//---
|
||||
res=array[from_index];
|
||||
for(int i=from_index; i>from_index-range && i>=0; i--)
|
||||
if(res>array[i])
|
||||
res=array[i];
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,123 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MACD.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Moving Average Convergence/Divergence"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color1 clrSilver
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_width1 2
|
||||
#property indicator_width2 1
|
||||
#property indicator_label1 "MACD"
|
||||
#property indicator_label2 "Signal"
|
||||
//--- input parameters
|
||||
input int InpFastEMA=12; // Fast EMA period
|
||||
input int InpSlowEMA=26; // Slow EMA period
|
||||
input int InpSignalSMA=9; // Signal SMA period
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtMacdBuffer[];
|
||||
double ExtSignalBuffer[];
|
||||
double ExtFastMaBuffer[];
|
||||
double ExtSlowMaBuffer[];
|
||||
|
||||
int ExtFastMaHandle;
|
||||
int ExtSlowMaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
|
||||
//--- name for indicator subwindow label
|
||||
string short_name=StringFormat("MACD(%d,%d,%d)",InpFastEMA,InpSlowEMA,InpSignalSMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get MA handles
|
||||
ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
|
||||
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Averages Convergence/Divergence |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpSignalSMA)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastMaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastMaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowMaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowMaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get Fast EMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast EMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//---
|
||||
int start;
|
||||
if(prev_calculated==0)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- calculate MACD
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
//--- calculate Signal
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,120 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MFI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Money Flow Index"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_maximum 100.0
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_level1 20.0
|
||||
#property indicator_level2 80.0
|
||||
#property indicator_levelcolor clrSilver
|
||||
#property indicator_levelstyle 2
|
||||
#property indicator_levelwidth 1
|
||||
//--- input parameters
|
||||
input int InpMFIPeriod=14; // Period
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffer
|
||||
double ExtMFIBuffer[];
|
||||
|
||||
int ExtMFIPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Money Flow Index initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpMFIPeriod<=0)
|
||||
{
|
||||
ExtMFIPeriod=14;
|
||||
Print("Parameter InpMFIPeriod has wrong value. Indicator will use value ",ExtMFIPeriod);
|
||||
}
|
||||
else
|
||||
ExtMFIPeriod=InpMFIPeriod;
|
||||
//--- indicator buffer
|
||||
SetIndexBuffer(0,ExtMFIBuffer);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"MFI("+string(ExtMFIPeriod)+")");
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMFIPeriod);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Money Flow Index |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<ExtMFIPeriod)
|
||||
return(0);
|
||||
|
||||
int start_position;
|
||||
//--- start working
|
||||
if(prev_calculated<ExtMFIPeriod)
|
||||
start_position=ExtMFIPeriod;
|
||||
else
|
||||
start_position=prev_calculated-1;
|
||||
//--- calculate MFI by volume
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateMFI(start_position,rates_total,high,low,close,tick_volume);
|
||||
else
|
||||
CalculateMFI(start_position,rates_total,high,low,close,volume);
|
||||
//--- OnCalculate done. Return new prev_calculated
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate MFI by volume from argument |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateMFI(const int start_position,
|
||||
const int rates_total,
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &volume[])
|
||||
{
|
||||
for(int i=start_position; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double positive=0.0;
|
||||
double negative=0.0;
|
||||
double current_tp=TypicalPrice(high[i],low[i],close[i]);
|
||||
for(int j=1; j<=ExtMFIPeriod; j++)
|
||||
{
|
||||
int index=i-j;
|
||||
double previous_tp=TypicalPrice(high[index],low[index],close[index]);
|
||||
if(current_tp>previous_tp)
|
||||
positive+=volume[index+1]*current_tp;
|
||||
if(current_tp<previous_tp)
|
||||
negative+=volume[index+1]*current_tp;
|
||||
current_tp=previous_tp;
|
||||
}
|
||||
if(negative!=0.0)
|
||||
ExtMFIBuffer[i]=100.0-100.0/(1+positive/negative);
|
||||
else
|
||||
ExtMFIBuffer[i]=100.0;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate typical price |
|
||||
//+------------------------------------------------------------------+
|
||||
double TypicalPrice(const double high_price,const double low_price,const double close_price)
|
||||
{
|
||||
return((high_price+low_price+close_price)/3.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,122 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Mass Index"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_level1 27
|
||||
#property indicator_level2 26.5
|
||||
#property indicator_levelcolor clrDarkGray
|
||||
//--- input parametrs
|
||||
input int InpPeriodEMA=9; // First EMA period
|
||||
input int InpSecondPeriodEMA=9; // Second EMA period
|
||||
input int InpSumPeriod=25; // Mass period
|
||||
//--- indicator buffers
|
||||
double ExtHLBuffer[];
|
||||
double ExtEHLBuffer[];
|
||||
double ExtEEHLBuffer[];
|
||||
double ExtMIBuffer[];
|
||||
|
||||
int ExtPeriodEMA;
|
||||
int ExtSecondPeriodEMA;
|
||||
int ExtSumPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| MI initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check input variables
|
||||
if(InpPeriodEMA<=0)
|
||||
{
|
||||
ExtPeriodEMA=9;
|
||||
PrintFormat("Incorrect value for input variable InpPeriodEMA=%d. Indicator will use value=%d for calculations.",
|
||||
InpPeriodEMA,ExtPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtPeriodEMA=InpPeriodEMA;
|
||||
if(InpSecondPeriodEMA<=0)
|
||||
{
|
||||
ExtSecondPeriodEMA=9;
|
||||
PrintFormat("Incorrect value for input variable InpSecondPeriodEMA=%d. Indicator will use value=%d for calculations.",
|
||||
InpSecondPeriodEMA,ExtSecondPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtSecondPeriodEMA=InpSecondPeriodEMA;
|
||||
if(InpSumPeriod<=0)
|
||||
{
|
||||
ExtSumPeriod=25;
|
||||
PrintFormat("Incorrect value for input variable PeriodSum=%d. Indicator will use value=%d for calculations.",
|
||||
InpSumPeriod,ExtSumPeriod);
|
||||
}
|
||||
else
|
||||
ExtSumPeriod=InpSumPeriod;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtMIBuffer);
|
||||
SetIndexBuffer(1,ExtEHLBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtEEHLBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtHLBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Mass Index("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")");
|
||||
PlotIndexSetString(0,PLOT_LABEL,"MI("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")");
|
||||
//--- indexes draw begin settings
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodEMA+ExtSecondPeriodEMA+ExtSumPeriod-3);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Mass Index |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int pos_mi=ExtSumPeriod+ExtPeriodEMA+ExtSecondPeriodEMA-3;
|
||||
if(rates_total<pos_mi)
|
||||
return(0);
|
||||
//--- start working
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position
|
||||
if(pos<1)
|
||||
{
|
||||
ExtHLBuffer[0]=high[0]-low[0];
|
||||
pos=1;
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- fill main data buffer
|
||||
ExtHLBuffer[i]=high[i]-low[i];
|
||||
//--- calculate EMA values
|
||||
ExtEHLBuffer[i]=ExponentialMA(i,ExtPeriodEMA,ExtEHLBuffer[i-1],ExtHLBuffer);
|
||||
//--- calculate EMA on EMA values
|
||||
ExtEEHLBuffer[i]=ExponentialMA(i,ExtSecondPeriodEMA,ExtEEHLBuffer[i-1],ExtEHLBuffer);
|
||||
//--- calculate MI values
|
||||
double dtmp=0.0;
|
||||
if(i>=pos_mi)
|
||||
{
|
||||
for(int j=0; j<ExtSumPeriod; j++)
|
||||
if(ExtEEHLBuffer[i-j]!=0.0)
|
||||
dtmp+=ExtEHLBuffer[i-j]/ExtEEHLBuffer[i-j];
|
||||
}
|
||||
ExtMIBuffer[i]=dtmp;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,151 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MarketFacilitationIndex.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrLime,clrSaddleBrown,clrBlue,clrPink
|
||||
#property indicator_width1 2
|
||||
//--- input parameter
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffers
|
||||
double ExtMFIBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtMFIBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- name for DataWindow
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"BWMFI");
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int start=0;
|
||||
//---
|
||||
if(start<prev_calculated)
|
||||
start=prev_calculated-1;
|
||||
//--- calculate with tick or real volumes
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateMFI(start,rates_total,high,low,tick_volume);
|
||||
else
|
||||
CalculateMFI(start,rates_total,high,low,volume);
|
||||
//--- normalize last mfi value
|
||||
if(rates_total>1)
|
||||
{
|
||||
datetime ctm=TimeTradeServer(),lasttm=time[rates_total-1],nexttm=lasttm+datetime(PeriodSeconds());
|
||||
if(ctm<nexttm && ctm>=lasttm && nexttm!=lasttm)
|
||||
{
|
||||
double correction_koef=double(1+ctm-lasttm)/double(nexttm-lasttm);
|
||||
ExtMFIBuffer[rates_total-1]*=correction_koef;
|
||||
}
|
||||
}
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateMFI(const int start,const int rates_total,
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const long &volume[])
|
||||
{
|
||||
int i=start;
|
||||
bool mfi_up=true,vol_up=true;
|
||||
//--- calculate first values of mfi_up and vol_up
|
||||
if(i>0)
|
||||
{
|
||||
int n=i;
|
||||
while(n>0)
|
||||
{
|
||||
if(ExtMFIBuffer[n]>ExtMFIBuffer[n-1])
|
||||
{
|
||||
mfi_up=true;
|
||||
break;
|
||||
}
|
||||
if(ExtMFIBuffer[n]<ExtMFIBuffer[n-1])
|
||||
{
|
||||
mfi_up=false;
|
||||
break;
|
||||
}
|
||||
//--- if mfi values are equal continue
|
||||
n--;
|
||||
}
|
||||
n=i;
|
||||
while(n>0)
|
||||
{
|
||||
if(volume[n]>volume[n-1])
|
||||
{
|
||||
vol_up=true;
|
||||
break;
|
||||
}
|
||||
if(volume[n]<volume[n-1])
|
||||
{
|
||||
vol_up=false;
|
||||
break;
|
||||
}
|
||||
//--- if volumes are equal continue
|
||||
n--;
|
||||
}
|
||||
}
|
||||
//---
|
||||
while(i<rates_total && !IsStopped())
|
||||
{
|
||||
if(volume[i]==0)
|
||||
{
|
||||
if(i>0)
|
||||
ExtMFIBuffer[i]=ExtMFIBuffer[i-1];
|
||||
else
|
||||
ExtMFIBuffer[i]=0;
|
||||
}
|
||||
else
|
||||
ExtMFIBuffer[i]=(high[i]-low[i])/_Point/volume[i];
|
||||
//--- calculate changes
|
||||
if(i>0)
|
||||
{
|
||||
if(ExtMFIBuffer[i]>ExtMFIBuffer[i-1])
|
||||
mfi_up=true;
|
||||
if(ExtMFIBuffer[i]<ExtMFIBuffer[i-1])
|
||||
mfi_up=false;
|
||||
if(volume[i]>volume[i-1])
|
||||
vol_up=true;
|
||||
if(volume[i]<volume[i-1])
|
||||
vol_up=false;
|
||||
}
|
||||
//--- set colors
|
||||
if(mfi_up && vol_up)
|
||||
ExtColorBuffer[i]=0.0;
|
||||
if(!mfi_up && !vol_up)
|
||||
ExtColorBuffer[i]=1.0;
|
||||
if(mfi_up && !vol_up)
|
||||
ExtColorBuffer[i]=2.0;
|
||||
if(!mfi_up && vol_up)
|
||||
ExtColorBuffer[i]=3.0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,68 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Momentum.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parameters
|
||||
input int InpMomentumPeriod=14; // Period
|
||||
//--- indicator buffer
|
||||
double ExtMomentumBuffer[];
|
||||
|
||||
int ExtMomentumPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpMomentumPeriod<0)
|
||||
{
|
||||
ExtMomentumPeriod=14;
|
||||
Print("Input parameter InpMomentumPeriod has wrong value. Indicator will use value ",ExtMomentumPeriod);
|
||||
}
|
||||
else
|
||||
ExtMomentumPeriod=InpMomentumPeriod;
|
||||
//--- buffers
|
||||
SetIndexBuffer(0,ExtMomentumBuffer,INDICATOR_DATA);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Momentum("+string(ExtMomentumPeriod)+")");
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMomentumPeriod-1);
|
||||
//--- sets drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
//--- digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Momentum |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int start_position=(ExtMomentumPeriod-1)+begin;
|
||||
if(rates_total<start_position)
|
||||
return(0);
|
||||
//--- correct draw begin
|
||||
if(prev_calculated==0 && begin>0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,start_position+(ExtMomentumPeriod-1));
|
||||
//--- start working, detect position
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<start_position)
|
||||
pos=begin+ExtMomentumPeriod;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
ExtMomentumBuffer[i]=price[i]*100/price[i-ExtMomentumPeriod];
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,90 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| OBV.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "On Balance vol"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_label1 "OBV"
|
||||
//--- input parametrs
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffer
|
||||
double ExtOBVBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| On Balance vol initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- define indicator buffer
|
||||
SetIndexBuffer(0,ExtOBVBuffer);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| On Balance vol |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<2)
|
||||
return(0);
|
||||
//--- starting calculation
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position, when it's first iteration
|
||||
if(pos<1)
|
||||
{
|
||||
pos=1;
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
ExtOBVBuffer[0]=(double)tick_volume[0];
|
||||
else
|
||||
ExtOBVBuffer[0]=(double)volume[0];
|
||||
}
|
||||
//--- main cycle
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculateOBV(pos,rates_total,close,tick_volume);
|
||||
else
|
||||
CalculateOBV(pos,rates_total,close,volume);
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate OBV by volume argument |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateOBV(int start_pos,
|
||||
int rates_total,
|
||||
const double& close[],
|
||||
const long& volume[])
|
||||
{
|
||||
for(int i=start_pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double vol=(double)volume[i];
|
||||
double prev_close=close[i-1];
|
||||
double curr_close=close[i];
|
||||
//--- fill ExtOBVBuffer
|
||||
if(curr_close<prev_close)
|
||||
ExtOBVBuffer[i]=ExtOBVBuffer[i-1]-vol;
|
||||
else
|
||||
{
|
||||
if(curr_close>prev_close)
|
||||
ExtOBVBuffer[i]=ExtOBVBuffer[i-1]+vol;
|
||||
else
|
||||
ExtOBVBuffer[i]=ExtOBVBuffer[i-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,126 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| OsMA.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Moving Average of Oscillator"
|
||||
#property description "aka MACD histogram"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrSilver
|
||||
#property indicator_width1 2
|
||||
//--- input parameters
|
||||
input int InpFastEMAPeriod=12; // Fast EMA period
|
||||
input int InpSlowEMAPeriod=26; // Slow EMA period
|
||||
input int InpSignalSMAPeriod=9; // Signal SMA period
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtOsMABuffer[];
|
||||
double ExtMacdBuffer[];
|
||||
double ExtSignalBuffer[];
|
||||
double ExtFastMaBuffer[];
|
||||
double ExtSlowMaBuffer[];
|
||||
//--- MA handles
|
||||
int ExtFastMaHandle;
|
||||
int ExtSlowMaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOsMABuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtMacdBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtSignalBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowEMAPeriod+InpSignalSMAPeriod-2);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("OsMA(%d,%d,%d)",InpFastEMAPeriod,InpSlowEMAPeriod,InpSignalSMAPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,"OsMA");
|
||||
//--- get MAs handles
|
||||
ExtFastMaHandle=iMA(NULL,0,InpFastEMAPeriod,0,MODE_EMA,InpAppliedPrice);
|
||||
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMAPeriod,0,MODE_EMA,InpAppliedPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Average of Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpSignalSMAPeriod)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastMaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowMaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowMaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get Fast EMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast EMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//---
|
||||
int i,start;
|
||||
if(prev_calculated==0)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- calculate MACD
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
//--- calculate Signal
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMAPeriod,ExtMacdBuffer,ExtSignalBuffer);
|
||||
//--- calculate OsMA
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtOsMABuffer[i]=ExtMacdBuffer[i]-ExtSignalBuffer[i];
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| PVT.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Price and Volume Trend"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parametrs
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffer
|
||||
double ExtPVTBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| PVT initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- define indicator buffer
|
||||
SetIndexBuffer(0,ExtPVTBuffer);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- name for DataWindow and indicator label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"PVT");
|
||||
//--- set index empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
//--- set index draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| PVT iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<2)
|
||||
return(0);
|
||||
//--- start calculation
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position, when it's first iteration
|
||||
if(pos<0)
|
||||
{
|
||||
pos=1;
|
||||
ExtPVTBuffer[0]=0.0;
|
||||
}
|
||||
//--- main cycle
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
CalculatePVT(pos,rates_total,close,tick_volume);
|
||||
else
|
||||
CalculatePVT(pos,rates_total,close,volume);
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate PVT by volume argument |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculatePVT(const int pos,
|
||||
const int rates_total,
|
||||
const double& close[],
|
||||
const long& volume[])
|
||||
{
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double prev_close=close[i-1];
|
||||
//--- calculate PVT value
|
||||
if(prev_close!=0)
|
||||
ExtPVTBuffer[i]=((close[i]-prev_close)/prev_close)*volume[i]+ExtPVTBuffer[i-1];
|
||||
else
|
||||
ExtPVTBuffer[i]=ExtPVTBuffer[i-1];
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,64 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| PanelChart.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_plots 0
|
||||
#property indicator_buffers 0
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_maximum 0.0
|
||||
#include "PanelDialog.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Global Variables |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog ExtDialog;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit(void)
|
||||
{
|
||||
//--- create application dialog
|
||||
if(!ExtDialog.Create(0,"Chart Panel ",0,50,50,390,300))
|
||||
return(INIT_FAILED);
|
||||
//--- run application
|
||||
if(!ExtDialog.Run())
|
||||
return(INIT_FAILED);
|
||||
//--- succeed
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//--- destroy application dialog
|
||||
ExtDialog.Destroy(reason);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//---
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ChartEvent function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,375 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| PanelDialog.mqh |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Controls\Dialog.mqh>
|
||||
#include <Controls\ComboBox.mqh>
|
||||
#include <Controls\CheckBox.mqh>
|
||||
#include <Controls\Label.mqh>
|
||||
#include <Controls\SpinEdit.mqh>
|
||||
#include <ChartObjects\ChartObjectSubChart.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| defines |
|
||||
//+------------------------------------------------------------------+
|
||||
//--- indents and gaps
|
||||
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
|
||||
#define INDENT_TOP (11) // indent from top (with allowance for border width)
|
||||
#define INDENT_RIGHT (11) // indent from right (with allowance for border width)
|
||||
#define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width)
|
||||
#define CONTROLS_GAP_X (10) // gap by X coordinate
|
||||
#define CONTROLS_GAP_Y (10) // gap by Y coordinate
|
||||
//--- for combo boxes
|
||||
#define COMBOBOX_WIDTH (100) // size by X coordinate
|
||||
#define COMBOBOX_HEIGHT (20) // size by Y coordinate
|
||||
//--- for spin edit
|
||||
#define SPINEDIT_WIDTH (50) // size by X coordinate
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CPanelDialog |
|
||||
//| Usage: main dialog of the Controls application |
|
||||
//+------------------------------------------------------------------+
|
||||
class CPanelDialog : public CAppDialog
|
||||
{
|
||||
private:
|
||||
CChartObjectSubChart m_subchart; // the sub-chart object
|
||||
CComboBox m_symbols; // the symbols combo box object
|
||||
CComboBox m_periods; // the timeframes combo box object
|
||||
CCheckBox m_time; // the time scale management object
|
||||
CCheckBox m_price; // the price scale management object
|
||||
CLabel m_label; // the label object
|
||||
CSpinEdit m_scale; // the scale management object
|
||||
|
||||
public:
|
||||
CPanelDialog(void);
|
||||
~CPanelDialog(void);
|
||||
//--- create
|
||||
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
|
||||
//--- chart event handler
|
||||
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
|
||||
|
||||
protected:
|
||||
//--- create dependent controls
|
||||
bool CreateSubchart(void);
|
||||
bool CreateSymbols(void);
|
||||
bool CreatePeriods(void);
|
||||
bool CreateTime(void);
|
||||
bool CreatePrice(void);
|
||||
bool CreateLabel(void);
|
||||
bool CreateScale(void);
|
||||
//--- fill dependent controls
|
||||
bool FillSymbols(void);
|
||||
bool FillPeriods(void);
|
||||
//--- internal event handlers
|
||||
virtual bool OnResize(void);
|
||||
//--- handlers of the dependent controls events
|
||||
void OnChangeSymbols(void);
|
||||
void OnChangePeriods(void);
|
||||
void OnChangeTime(void);
|
||||
void OnChangePrice(void);
|
||||
void OnChangeScale(void);
|
||||
//--- change dialog title
|
||||
void SetCaption(void);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event Handling |
|
||||
//+------------------------------------------------------------------+
|
||||
EVENT_MAP_BEGIN(CPanelDialog)
|
||||
ON_EVENT(ON_CHANGE,m_symbols,OnChangeSymbols)
|
||||
ON_EVENT(ON_CHANGE,m_periods,OnChangePeriods)
|
||||
ON_EVENT(ON_CHANGE,m_time,OnChangeTime)
|
||||
ON_EVENT(ON_CHANGE,m_price,OnChangePrice)
|
||||
ON_EVENT(ON_CHANGE,m_scale,OnChangeScale)
|
||||
EVENT_MAP_END(CAppDialog)
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog::CPanelDialog(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog::~CPanelDialog(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
|
||||
{
|
||||
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
//--- create dependent controls
|
||||
if(!CreateSubchart())
|
||||
return(false);
|
||||
if(!CreateTime())
|
||||
return(false);
|
||||
if(!CreatePrice())
|
||||
return(false);
|
||||
if(!CreateLabel())
|
||||
return(false);
|
||||
if(!CreateScale())
|
||||
return(false);
|
||||
if(!CreatePeriods())
|
||||
return(false);
|
||||
if(!CreateSymbols())
|
||||
return(false);
|
||||
//--- change dialog title
|
||||
SetCaption();
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Chart of Chart" object |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateSubchart(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x=ClientAreaLeft()+INDENT_LEFT;
|
||||
int y=ClientAreaTop()+INDENT_TOP;
|
||||
int w=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH+CONTROLS_GAP_X+INDENT_LEFT);
|
||||
int h=ClientAreaHeight()-(INDENT_BOTTOM+INDENT_TOP);
|
||||
//--- create
|
||||
if(!m_subchart.Create(m_chart_id,m_name,m_subwin,x,y,w,h))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Symbols" combo box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateSymbols(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
|
||||
int y1=INDENT_TOP;
|
||||
int x2=x1+COMBOBOX_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_symbols.Create(m_chart_id,m_name+"Symbols",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_symbols))
|
||||
return(false);
|
||||
m_symbols.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- fill
|
||||
if(!FillSymbols())
|
||||
return(false);
|
||||
//--- select
|
||||
m_symbols.SelectByText(Symbol());
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Timeframes" combo box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreatePeriods(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
|
||||
int y1=INDENT_TOP+COMBOBOX_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+COMBOBOX_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_periods.Create(m_chart_id,m_name+"Periods",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_periods))
|
||||
return(false);
|
||||
m_periods.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- fill
|
||||
if(!FillPeriods())
|
||||
return(false);
|
||||
//--- select
|
||||
m_periods.SelectByValue(Period());
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Time scale" check box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateTime(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
|
||||
int y1=INDENT_TOP+2*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
|
||||
int x2=x1+COMBOBOX_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_time.Create(m_chart_id,m_name+"Time",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_time.Text(" dates scale"))
|
||||
return(false);
|
||||
if(!Add(m_time))
|
||||
return(false);
|
||||
m_time.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- state
|
||||
m_time.Checked(m_subchart.DateScale());
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Price scale" check box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreatePrice(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
|
||||
int y1=INDENT_TOP+3*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
|
||||
int x2=x1+COMBOBOX_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_price.Create(m_chart_id,m_name+"Price",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_price.Text(" prices scale"))
|
||||
return(false);
|
||||
if(!Add(m_price))
|
||||
return(false);
|
||||
m_price.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- state
|
||||
m_price.Checked(m_subchart.PriceScale());
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create label for the "Scale" spin edit |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateLabel(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH);
|
||||
int y1=INDENT_TOP+4*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
|
||||
int x2=x1+COMBOBOX_WIDTH-SPINEDIT_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_label.Create(m_chart_id,m_name+"Label",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_label.Text("Scale"))
|
||||
return(false);
|
||||
if(!Add(m_label))
|
||||
return(false);
|
||||
m_label.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT+SPINEDIT_WIDTH,0);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Scale" spin edit |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateScale(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+SPINEDIT_WIDTH);
|
||||
int y1=INDENT_TOP+4*(COMBOBOX_HEIGHT+CONTROLS_GAP_Y);
|
||||
int x2=x1+SPINEDIT_WIDTH;
|
||||
int y2=y1+COMBOBOX_HEIGHT;
|
||||
//--- create
|
||||
if(!m_scale.Create(m_chart_id,m_name+"Scale",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_scale))
|
||||
return(false);
|
||||
m_scale.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- set up
|
||||
m_scale.MinValue(0);
|
||||
m_scale.MaxValue(5);
|
||||
m_scale.Value(m_subchart.Scale());
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fill the "Symbols" combo box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::FillSymbols(void)
|
||||
{
|
||||
int total=SymbolsTotal(true);
|
||||
for(int i=0;i<total;i++)
|
||||
if(!m_symbols.ItemAdd(SymbolName(i,true)))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fill the "Timeframes" combo box |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::FillPeriods(void)
|
||||
{
|
||||
static string name[]=
|
||||
{
|
||||
"M1","M2","M3","M4","M5","M6","M10","M12","M15","M20","M30",
|
||||
"H1","H2","H3","H4","H6","H8","H12","Day","Week","Month"
|
||||
};
|
||||
static long value[]=
|
||||
{
|
||||
PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,
|
||||
PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,
|
||||
PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,
|
||||
PERIOD_D1,PERIOD_W1,PERIOD_MN1
|
||||
};
|
||||
//---
|
||||
int total=ArraySize(name);
|
||||
if(total>ArraySize(value))
|
||||
total=ArraySize(value);
|
||||
//---
|
||||
for(int i=0;i<total;i++)
|
||||
if(!m_periods.ItemAdd(name[i],value[i]))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Handler of resizing |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::OnResize(void)
|
||||
{
|
||||
//--- call method of parent class
|
||||
if(!CAppDialog::OnResize())
|
||||
return(false);
|
||||
//--- change width of sub-chart
|
||||
m_subchart.X_Size(ClientAreaWidth()-(INDENT_RIGHT+COMBOBOX_WIDTH+CONTROLS_GAP_X+INDENT_LEFT));
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Change dialog title |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::SetCaption(void)
|
||||
{
|
||||
Caption(ProgramName()+"("+m_symbols.Select()+","+m_periods.Select()+")");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeSymbols(void)
|
||||
{
|
||||
m_subchart.Symbol(m_symbols.Select());
|
||||
//--- change dialog title
|
||||
SetCaption();
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangePeriods(void)
|
||||
{
|
||||
m_subchart.Period((int)m_periods.Value());
|
||||
//--- change dialog title
|
||||
SetCaption();
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeTime(void)
|
||||
{
|
||||
m_subchart.DateScale(m_time.Checked());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangePrice(void)
|
||||
{
|
||||
m_subchart.PriceScale(m_price.Checked());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeScale(void)
|
||||
{
|
||||
m_subchart.Scale(m_scale.Value());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,346 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| PanelDialog.mqh |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Controls\Dialog.mqh>
|
||||
#include <Controls\Button.mqh>
|
||||
#include <Controls\Edit.mqh>
|
||||
#include <Controls\ListView.mqh>
|
||||
#include <Controls\ComboBox.mqh>
|
||||
#include <Controls\SpinEdit.mqh>
|
||||
#include <Controls\RadioGroup.mqh>
|
||||
#include <Controls\CheckGroup.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| defines |
|
||||
//+------------------------------------------------------------------+
|
||||
//--- indents and gaps
|
||||
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
|
||||
#define INDENT_TOP (11) // indent from top (with allowance for border width)
|
||||
#define INDENT_RIGHT (11) // indent from right (with allowance for border width)
|
||||
#define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width)
|
||||
#define CONTROLS_GAP_X (10) // gap by X coordinate
|
||||
#define CONTROLS_GAP_Y (10) // gap by Y coordinate
|
||||
//--- for buttons
|
||||
#define BUTTON_WIDTH (100) // size by X coordinate
|
||||
#define BUTTON_HEIGHT (20) // size by Y coordinate
|
||||
//--- for the indication area
|
||||
#define EDIT_HEIGHT (20) // size by Y coordinate
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CPanelDialog |
|
||||
//| Usage: main dialog of the SimplePanel application |
|
||||
//+------------------------------------------------------------------+
|
||||
class CPanelDialog : public CAppDialog
|
||||
{
|
||||
private:
|
||||
CEdit m_edit; // the display field object
|
||||
CButton m_button1; // the button object
|
||||
CButton m_button2; // the button object
|
||||
CButton m_button3; // the fixed button object
|
||||
CListView m_list_view; // the list object
|
||||
CRadioGroup m_radio_group; // the radio buttons group object
|
||||
CCheckGroup m_check_group; // the check box group object
|
||||
|
||||
public:
|
||||
CPanelDialog(void);
|
||||
~CPanelDialog(void);
|
||||
//--- create
|
||||
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
|
||||
//--- chart event handler
|
||||
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
|
||||
|
||||
protected:
|
||||
//--- create dependent controls
|
||||
bool CreateEdit(void);
|
||||
bool CreateButton1(void);
|
||||
bool CreateButton2(void);
|
||||
bool CreateButton3(void);
|
||||
bool CreateRadioGroup(void);
|
||||
bool CreateCheckGroup(void);
|
||||
bool CreateListView(void);
|
||||
//--- internal event handlers
|
||||
virtual bool OnResize(void);
|
||||
//--- handlers of the dependent controls events
|
||||
void OnClickButton1(void);
|
||||
void OnClickButton2(void);
|
||||
void OnClickButton3(void);
|
||||
void OnChangeRadioGroup(void);
|
||||
void OnChangeCheckGroup(void);
|
||||
void OnChangeListView(void);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event Handling |
|
||||
//+------------------------------------------------------------------+
|
||||
EVENT_MAP_BEGIN(CPanelDialog)
|
||||
ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
|
||||
ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
|
||||
ON_EVENT(ON_CLICK,m_button3,OnClickButton3)
|
||||
ON_EVENT(ON_CHANGE,m_radio_group,OnChangeRadioGroup)
|
||||
ON_EVENT(ON_CHANGE,m_check_group,OnChangeCheckGroup)
|
||||
ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView)
|
||||
EVENT_MAP_END(CAppDialog)
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog::CPanelDialog(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog::~CPanelDialog(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
|
||||
{
|
||||
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
//--- create dependent controls
|
||||
if(!CreateEdit())
|
||||
return(false);
|
||||
if(!CreateButton1())
|
||||
return(false);
|
||||
if(!CreateButton2())
|
||||
return(false);
|
||||
if(!CreateButton3())
|
||||
return(false);
|
||||
if(!CreateRadioGroup())
|
||||
return(false);
|
||||
if(!CreateCheckGroup())
|
||||
return(false);
|
||||
if(!CreateListView())
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the display field |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateEdit(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=INDENT_LEFT;
|
||||
int y1=INDENT_TOP;
|
||||
int x2=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
|
||||
int y2=y1+EDIT_HEIGHT;
|
||||
//--- create
|
||||
if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_edit.ReadOnly(true))
|
||||
return(false);
|
||||
if(!Add(m_edit))
|
||||
return(false);
|
||||
m_edit.Alignment(WND_ALIGN_WIDTH,INDENT_LEFT,0,INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X,0);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Button1" button |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateButton1(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
|
||||
int y1=INDENT_TOP;
|
||||
int x2=x1+BUTTON_WIDTH;
|
||||
int y2=y1+BUTTON_HEIGHT;
|
||||
//--- create
|
||||
if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_button1.Text("Button1"))
|
||||
return(false);
|
||||
if(!Add(m_button1))
|
||||
return(false);
|
||||
m_button1.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Button2" button |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateButton2(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
|
||||
int y1=INDENT_TOP+BUTTON_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+BUTTON_WIDTH;
|
||||
int y2=y1+BUTTON_HEIGHT;
|
||||
//--- create
|
||||
if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_button2.Text("Button2"))
|
||||
return(false);
|
||||
if(!Add(m_button2))
|
||||
return(false);
|
||||
m_button2.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Button3" fixed button |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateButton3(void)
|
||||
{
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
|
||||
int y1=ClientAreaHeight()-(INDENT_BOTTOM+BUTTON_HEIGHT);
|
||||
int x2=x1+BUTTON_WIDTH;
|
||||
int y2=y1+BUTTON_HEIGHT;
|
||||
//--- create
|
||||
if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!m_button3.Text("Locked"))
|
||||
return(false);
|
||||
if(!Add(m_button3))
|
||||
return(false);
|
||||
m_button3.Locking(true);
|
||||
m_button3.Alignment(WND_ALIGN_RIGHT|WND_ALIGN_BOTTOM,0,0,INDENT_RIGHT,INDENT_BOTTOM);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "RadioGroup" element |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateRadioGroup(void)
|
||||
{
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- coordinates
|
||||
int x1=INDENT_LEFT;
|
||||
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+sx;
|
||||
int y2=ClientAreaHeight()-INDENT_BOTTOM;
|
||||
//--- create
|
||||
if(!m_radio_group.Create(m_chart_id,m_name+"RadioGroup",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_radio_group))
|
||||
return(false);
|
||||
m_radio_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
|
||||
//--- fill out with strings
|
||||
for(int i=0;i<4;i++)
|
||||
if(!m_radio_group.AddItem("Item "+IntegerToString(i),1<<i))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "CheckGroup" element |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateCheckGroup(void)
|
||||
{
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- coordinates
|
||||
int x1=INDENT_LEFT+sx+CONTROLS_GAP_X;
|
||||
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+sx;
|
||||
int y2=ClientAreaHeight()-INDENT_BOTTOM;
|
||||
//--- create
|
||||
if(!m_check_group.Create(m_chart_id,m_name+"CheckGroup",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_check_group))
|
||||
return(false);
|
||||
m_check_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
|
||||
//--- fill out with strings
|
||||
for(int i=0;i<4;i++)
|
||||
if(!m_check_group.AddItem("Item "+IntegerToString(i),1<<i))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "ListView" element |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateListView(void)
|
||||
{
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
|
||||
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+sx;
|
||||
int y2=ClientAreaHeight()-INDENT_BOTTOM;
|
||||
//--- create
|
||||
if(!m_list_view.Create(m_chart_id,m_name+"ListView",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_list_view))
|
||||
return(false);
|
||||
m_list_view.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
|
||||
//--- fill out with strings
|
||||
for(int i=0;i<16;i++)
|
||||
if(!m_list_view.ItemAdd("Item "+IntegerToString(i)))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Handler of resizing |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::OnResize(void)
|
||||
{
|
||||
//--- call method of parent class
|
||||
if(!CAppDialog::OnResize()) return(false);
|
||||
//--- coordinates
|
||||
int x=ClientAreaLeft()+INDENT_LEFT;
|
||||
int y=m_radio_group.Top();
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- move and resize the "RadioGroup" element
|
||||
m_radio_group.Move(x,y);
|
||||
m_radio_group.Width(sx);
|
||||
//--- move and resize the "CheckGroup" element
|
||||
x=ClientAreaLeft()+INDENT_LEFT+sx+CONTROLS_GAP_X;
|
||||
m_check_group.Move(x,y);
|
||||
m_check_group.Width(sx);
|
||||
//--- move and resize the "ListView" element
|
||||
x=ClientAreaLeft()+ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
|
||||
m_list_view.Move(x,y);
|
||||
m_list_view.Width(sx);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton1(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton2(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton3(void)
|
||||
{
|
||||
if(m_button3.Pressed())
|
||||
m_edit.Text(__FUNCTION__+"On");
|
||||
else
|
||||
m_edit.Text(__FUNCTION__+"Off");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeListView(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" \""+m_list_view.Select()+"\"");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeRadioGroup(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeCheckGroup(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_check_group.Value()));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,64 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SimplePanel.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_plots 0
|
||||
#property indicator_buffers 0
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_maximum 0.0
|
||||
#include "PanelDialog.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Global Variables |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog ExtDialog;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit(void)
|
||||
{
|
||||
//--- create application dialog
|
||||
if(!ExtDialog.Create(0,"Simple Panel",0,50,50,390,200))
|
||||
return(INIT_FAILED);
|
||||
//--- run application
|
||||
if(!ExtDialog.Run())
|
||||
return(INIT_FAILED);
|
||||
//--- succeed
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//--- destroy application dialog
|
||||
ExtDialog.Destroy(reason);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//---
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ChartEvent function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,204 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ParabolicSAR.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parametrs
|
||||
input double InpSARStep=0.02; // Step
|
||||
input double InpSARMaximum=0.2; // Maximum
|
||||
//--- indicator buffers
|
||||
double ExtSARBuffer[];
|
||||
double ExtEPBuffer[];
|
||||
double ExtAFBuffer[];
|
||||
|
||||
int ExtLastRevPos;
|
||||
bool ExtDirectionLong;
|
||||
double ExtSarStep;
|
||||
double ExtSarMaximum;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- checking input data
|
||||
if(InpSARStep<0.0)
|
||||
{
|
||||
ExtSarStep=0.02;
|
||||
PrintFormat("Input parametr InpSARStep has incorrect value. Indicator will use value %d for calculations.",
|
||||
ExtSarStep);
|
||||
}
|
||||
else
|
||||
ExtSarStep=InpSARStep;
|
||||
if(InpSARMaximum<0.0)
|
||||
{
|
||||
ExtSarMaximum=0.2;
|
||||
PrintFormat("Input parametr InpSARMaximum has incorrect value. Indicator will use value %d for calculations.",
|
||||
ExtSarMaximum);
|
||||
}
|
||||
else
|
||||
ExtSarMaximum=InpSARMaximum;
|
||||
//--- indicator buffers
|
||||
SetIndexBuffer(0,ExtSARBuffer);
|
||||
SetIndexBuffer(1,ExtEPBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtAFBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set arrow symbol
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,159);
|
||||
//--- set indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- set label name
|
||||
string short_name=StringFormat("SAR(%.2f,%.2f)",ExtSarStep,ExtSarMaximum);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
|
||||
ExtLastRevPos=0;
|
||||
ExtDirectionLong=false;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<3)
|
||||
return(0);
|
||||
//--- detect current position
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position
|
||||
if(pos<1)
|
||||
{
|
||||
//--- first pass, set as SHORT
|
||||
pos=1;
|
||||
ExtAFBuffer[0]=ExtSarStep;
|
||||
ExtAFBuffer[1]=ExtSarStep;
|
||||
ExtSARBuffer[0]=high[0];
|
||||
ExtLastRevPos=0;
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[1]=GetHigh(pos,ExtLastRevPos,high);
|
||||
ExtEPBuffer[0]=low[pos];
|
||||
ExtEPBuffer[1]=low[pos];
|
||||
}
|
||||
//---main cycle
|
||||
for(int i=pos; i<rates_total-1 && !IsStopped(); i++)
|
||||
{
|
||||
//--- check for reverse
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
if(ExtSARBuffer[i]>low[i])
|
||||
{
|
||||
//--- switch to SHORT
|
||||
ExtDirectionLong=false;
|
||||
ExtSARBuffer[i]=GetHigh(i,ExtLastRevPos,high);
|
||||
ExtEPBuffer[i]=low[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ExtSARBuffer[i]<high[i])
|
||||
{
|
||||
//--- switch to LONG
|
||||
ExtDirectionLong=true;
|
||||
ExtSARBuffer[i]=GetLow(i,ExtLastRevPos,low);
|
||||
ExtEPBuffer[i]=high[i];
|
||||
ExtLastRevPos=i;
|
||||
ExtAFBuffer[i]=ExtSarStep;
|
||||
}
|
||||
}
|
||||
//--- continue calculations
|
||||
if(ExtDirectionLong)
|
||||
{
|
||||
//--- check for new High
|
||||
if(high[i]>ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=high[i];
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
|
||||
if(ExtAFBuffer[i]>ExtSarMaximum)
|
||||
ExtAFBuffer[i]=ExtSarMaximum;
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- when we haven't reversed
|
||||
if(i!=ExtLastRevPos)
|
||||
{
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1];
|
||||
ExtEPBuffer[i]=ExtEPBuffer[i-1];
|
||||
}
|
||||
}
|
||||
//--- calculate SAR for tomorrow
|
||||
ExtSARBuffer[i+1]=ExtSARBuffer[i]+ExtAFBuffer[i]*(ExtEPBuffer[i]-ExtSARBuffer[i]);
|
||||
//--- check for SAR
|
||||
if(ExtSARBuffer[i+1]>low[i] || ExtSARBuffer[i+1]>low[i-1])
|
||||
ExtSARBuffer[i+1]=MathMin(low[i],low[i-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- check for new Low
|
||||
if(low[i]<ExtEPBuffer[i-1] && i!=ExtLastRevPos)
|
||||
{
|
||||
ExtEPBuffer[i]=low[i];
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1]+ExtSarStep;
|
||||
if(ExtAFBuffer[i]>ExtSarMaximum)
|
||||
ExtAFBuffer[i]=ExtSarMaximum;
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- when we haven't reversed
|
||||
if(i!=ExtLastRevPos)
|
||||
{
|
||||
ExtAFBuffer[i]=ExtAFBuffer[i-1];
|
||||
ExtEPBuffer[i]=ExtEPBuffer[i-1];
|
||||
}
|
||||
}
|
||||
//--- calculate SAR for tomorrow
|
||||
ExtSARBuffer[i+1]=ExtSARBuffer[i]+ExtAFBuffer[i]*(ExtEPBuffer[i]-ExtSARBuffer[i]);
|
||||
//--- check for SAR
|
||||
if(ExtSARBuffer[i+1]<high[i] || ExtSARBuffer[i+1]<high[i-1])
|
||||
ExtSARBuffer[i+1]=MathMax(high[i],high[i-1]);
|
||||
}
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find highest price from start to current position |
|
||||
//+------------------------------------------------------------------+
|
||||
double GetHigh(int curr_pos,int start,const double& high[])
|
||||
{
|
||||
double result=high[start];
|
||||
//---
|
||||
for(int i=start+1; i<=curr_pos; i++)
|
||||
if(result<high[i])
|
||||
result=high[i];
|
||||
//---
|
||||
return(result);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find lowest price from start to current position |
|
||||
//+------------------------------------------------------------------+
|
||||
double GetLow(int curr_pos,int start,const double& low[])
|
||||
{
|
||||
double result=low[start];
|
||||
//---
|
||||
for(int i=start+1; i<=curr_pos; i++)
|
||||
if(result>low[i])
|
||||
result=low[i];
|
||||
//---
|
||||
return(result);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,106 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Price_Channell.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue,clrGray
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_label1 "Channel upper;Channel lower"
|
||||
#property indicator_label2 "Channel median"
|
||||
//--- input parameters
|
||||
input int InpChannelPeriod=22; // Period
|
||||
//--- indicator buffers
|
||||
double ExtHighBuffer[];
|
||||
double ExtLowBuffer[];
|
||||
double ExtMiddBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtHighBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtMiddBuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- set first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,1);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,1);
|
||||
//--- name for DataWindow and indicator label
|
||||
string short_name=StringFormat("Price Channel(%d)",InpChannelPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
short_name=StringFormat("Channel(%d) upper;Channel(%d) lower",InpChannelPeriod,InpChannelPeriod);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
short_name=StringFormat("Median(%d)",InpChannelPeriod);
|
||||
PlotIndexSetString(1,PLOT_LABEL,short_name);
|
||||
//--- set drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Price Channell |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpChannelPeriod)
|
||||
return(0);
|
||||
|
||||
int start;
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)
|
||||
start=InpChannelPeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtHighBuffer[i]=Highest(high,InpChannelPeriod,i);
|
||||
ExtLowBuffer[i]=Lowest(low,InpChannelPeriod,i);
|
||||
ExtMiddBuffer[i]=(ExtHighBuffer[i]+ExtLowBuffer[i])/2.0;;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get highest value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Highest(const double& array[],const int range,const int from_index)
|
||||
{
|
||||
double res=array[from_index];
|
||||
for(int i=from_index-1; i>from_index-range && i>=0; i--)
|
||||
if(res<array[i])
|
||||
res=array[i];
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get lowest value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Lowest(const double& array[],const int range,const int from_index)
|
||||
{
|
||||
double res=array[from_index];
|
||||
for(int i=from_index-1; i>from_index-range && i>=0; i--)
|
||||
if(res>array[i])
|
||||
res=array[i];
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,66 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ROC.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Rate of Change"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
//--- input parameters
|
||||
input int InpRocPeriod=12; // Period
|
||||
//--- indicator buffer
|
||||
double ExtRocBuffer[];
|
||||
|
||||
int ExtRocPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Rate of Change initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input
|
||||
if(InpRocPeriod<1)
|
||||
{
|
||||
ExtRocPeriod=12;
|
||||
PrintFormat("Incorrect value for input variable InpRocPeriod = %d. Indicator will use value %d for calculations.",
|
||||
InpRocPeriod,ExtRocPeriod);
|
||||
}
|
||||
else
|
||||
ExtRocPeriod=InpRocPeriod;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Rate of Change |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
|
||||
{
|
||||
if(rates_total<ExtRocPeriod)
|
||||
return(0);
|
||||
//--- preliminary calculations
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<ExtRocPeriod)
|
||||
pos=ExtRocPeriod;
|
||||
//--- the main loop of calculations
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(price[i]==0.0)
|
||||
ExtRocBuffer[i]=0.0;
|
||||
else
|
||||
ExtRocBuffer[i]=(price[i]-price[i-ExtRocPeriod])/price[i]*100;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RSI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Relative Strength Index"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
#property indicator_level1 30
|
||||
#property indicator_level2 70
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
//--- input parameters
|
||||
input int InpPeriodRSI=14; // Period
|
||||
//--- indicator buffers
|
||||
double ExtRSIBuffer[];
|
||||
double ExtPosBuffer[];
|
||||
double ExtNegBuffer[];
|
||||
|
||||
int ExtPeriodRSI;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input
|
||||
if(InpPeriodRSI<1)
|
||||
{
|
||||
ExtPeriodRSI=14;
|
||||
PrintFormat("Incorrect value for input variable InpPeriodRSI = %d. Indicator will use value %d for calculations.",
|
||||
InpPeriodRSI,ExtPeriodRSI);
|
||||
}
|
||||
else
|
||||
ExtPeriodRSI=InpPeriodRSI;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtRSIBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtPosBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtNegBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodRSI);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"RSI("+string(ExtPeriodRSI)+")");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Relative Strength Index |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<=ExtPeriodRSI)
|
||||
return(0);
|
||||
//--- preliminary calculations
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<=ExtPeriodRSI)
|
||||
{
|
||||
double sum_pos=0.0;
|
||||
double sum_neg=0.0;
|
||||
//--- first RSIPeriod values of the indicator are not calculated
|
||||
ExtRSIBuffer[0]=0.0;
|
||||
ExtPosBuffer[0]=0.0;
|
||||
ExtNegBuffer[0]=0.0;
|
||||
for(int i=1; i<=ExtPeriodRSI; i++)
|
||||
{
|
||||
ExtRSIBuffer[i]=0.0;
|
||||
ExtPosBuffer[i]=0.0;
|
||||
ExtNegBuffer[i]=0.0;
|
||||
double diff=price[i]-price[i-1];
|
||||
sum_pos+=(diff>0?diff:0);
|
||||
sum_neg+=(diff<0?-diff:0);
|
||||
}
|
||||
//--- calculate first visible value
|
||||
ExtPosBuffer[ExtPeriodRSI]=sum_pos/ExtPeriodRSI;
|
||||
ExtNegBuffer[ExtPeriodRSI]=sum_neg/ExtPeriodRSI;
|
||||
if(ExtNegBuffer[ExtPeriodRSI]!=0.0)
|
||||
ExtRSIBuffer[ExtPeriodRSI]=100.0-(100.0/(1.0+ExtPosBuffer[ExtPeriodRSI]/ExtNegBuffer[ExtPeriodRSI]));
|
||||
else
|
||||
{
|
||||
if(ExtPosBuffer[ExtPeriodRSI]!=0.0)
|
||||
ExtRSIBuffer[ExtPeriodRSI]=100.0;
|
||||
else
|
||||
ExtRSIBuffer[ExtPeriodRSI]=50.0;
|
||||
}
|
||||
//--- prepare the position value for main calculation
|
||||
pos=ExtPeriodRSI+1;
|
||||
}
|
||||
//--- the main loop of calculations
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double diff=price[i]-price[i-1];
|
||||
ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(ExtPeriodRSI-1)+(diff>0.0?diff:0.0))/ExtPeriodRSI;
|
||||
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(ExtPeriodRSI-1)+(diff<0.0?-diff:0.0))/ExtPeriodRSI;
|
||||
if(ExtNegBuffer[i]!=0.0)
|
||||
ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
|
||||
else
|
||||
{
|
||||
if(ExtPosBuffer[i]!=0.0)
|
||||
ExtRSIBuffer[i]=100.0;
|
||||
else
|
||||
ExtRSIBuffer[i]=50.0;
|
||||
}
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,102 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RVI.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://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 clrGreen
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_label1 "RVI"
|
||||
#property indicator_label2 "Signal"
|
||||
//--- input parameters
|
||||
input int InpRVIPeriod=10; // Period
|
||||
//--- indicator buffers
|
||||
double ExtRVIBuffer[];
|
||||
double ExtSignalBuffer[];
|
||||
|
||||
#define TRIANGLE_PERIOD 3
|
||||
#define AVERAGE_PERIOD (TRIANGLE_PERIOD*2)
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtRVIBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,3);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+TRIANGLE_PERIOD);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,(InpRVIPeriod-1)+AVERAGE_PERIOD);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("RVI(%d)",InpRVIPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Signal("+string(InpRVIPeriod)+")");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
if(rates_total<=InpRVIPeriod+AVERAGE_PERIOD+2)
|
||||
return(0);
|
||||
|
||||
int i,start;
|
||||
//--- last counted bar will be recounted
|
||||
start=InpRVIPeriod+2;
|
||||
if(prev_calculated>InpRVIPeriod+TRIANGLE_PERIOD+2)
|
||||
start=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=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double sum_up=0.0;
|
||||
double sum_down=0.0;
|
||||
for(int j=i; j>i-InpRVIPeriod; j--)
|
||||
{
|
||||
double value_up=close[j]-open[j]+2*(close[j-1]-open[j-1])+2*(close[j-2]-open[j-2])+close[j-3]-open[j-3];
|
||||
double value_down=high[j]-low[j]+2*(high[j-1]-low[j-1])+2*(high[j-2]-low[j-2])+high[j-3]-low[j-3];
|
||||
sum_up+=value_up;
|
||||
sum_down+=value_down;
|
||||
}
|
||||
if(sum_down!=0.0)
|
||||
ExtRVIBuffer[i]=sum_up/sum_down;
|
||||
else
|
||||
ExtRVIBuffer[i]=sum_up;
|
||||
}
|
||||
//--- signal line counted in the 2-nd buffer
|
||||
start=InpRVIPeriod+TRIANGLE_PERIOD+2;
|
||||
if(prev_calculated>InpRVIPeriod+AVERAGE_PERIOD+2)
|
||||
start=prev_calculated-1;
|
||||
for(i=start; 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.
@@ -0,0 +1,129 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| StdDev.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Standard Deviation"
|
||||
#include <MovingAverages.mqh>
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrMediumSeaGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
//--- input parametrs
|
||||
input int InpStdDevPeriod=20; // Period
|
||||
input int InpStdDevShift=0; // Shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method
|
||||
//--- indicator buffers
|
||||
double ExtStdDevBuffer[];
|
||||
double ExtMABuffer[];
|
||||
|
||||
int ExtStdDevPeriod,ExtStdDevShift;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpStdDevPeriod<=1)
|
||||
{
|
||||
ExtStdDevPeriod=20;
|
||||
PrintFormat("Incorrect value for input variable InpStdDevPeriod=%d. Indicator will use value %d for calculations.",
|
||||
InpStdDevPeriod,ExtStdDevPeriod);
|
||||
}
|
||||
else
|
||||
ExtStdDevPeriod=InpStdDevPeriod;
|
||||
if(InpStdDevShift<0)
|
||||
{
|
||||
ExtStdDevShift=0;
|
||||
PrintFormat("Incorrect value for input variable InpStdDevShift=%d. Indicator will use value %d for calculations.",
|
||||
InpStdDevShift,ExtStdDevShift);
|
||||
}
|
||||
else
|
||||
ExtStdDevShift=InpStdDevShift;
|
||||
//--- define indicator buffers as indexes
|
||||
SetIndexBuffer(0,ExtStdDevBuffer);
|
||||
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set indicator short name
|
||||
string short_name=StringFormat("StdDev(%d)",ExtStdDevPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- set index shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,ExtStdDevShift);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
|
||||
{
|
||||
if(rates_total<ExtStdDevPeriod)
|
||||
return(0);
|
||||
//--- starting work
|
||||
int start=prev_calculated-1;
|
||||
//--- correct position for first iteration
|
||||
if(start<ExtStdDevPeriod)
|
||||
{
|
||||
start=ExtStdDevPeriod-1;
|
||||
ArrayInitialize(ExtStdDevBuffer,0.0);
|
||||
ArrayInitialize(ExtMABuffer,0.0);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtStdDevPeriod-1+begin);
|
||||
}
|
||||
//--- main cycle
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA :
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(i==InpStdDevPeriod-1)
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
|
||||
else
|
||||
ExtMABuffer[i]=ExponentialMA(i,InpStdDevPeriod,ExtMABuffer[i-1],price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
case MODE_SMMA :
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(i==InpStdDevPeriod-1)
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
|
||||
else
|
||||
ExtMABuffer[i]=SmoothedMA(i,InpStdDevPeriod,ExtMABuffer[i-1],price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
case MODE_LWMA :
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtMABuffer[i]=LinearWeightedMA(i,InpStdDevPeriod,price);
|
||||
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
|
||||
}
|
||||
break;
|
||||
default :
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtMABuffer[i]=SimpleMA(i,InpStdDevPeriod,price);
|
||||
//--- Calculate StdDev
|
||||
ExtStdDevBuffer[i]=StdDevFunc(price,ExtMABuffer,i);
|
||||
}
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Standard Deviation |
|
||||
//+------------------------------------------------------------------+
|
||||
double StdDevFunc(const double &price[],const double &ma_price[],const int position)
|
||||
{
|
||||
double dev=0.0;
|
||||
for(int i=0; i<ExtStdDevPeriod; i++)
|
||||
dev+=MathPow(price[position-i]-ma_price[position],2.0);
|
||||
dev=MathSqrt(dev/ExtStdDevPeriod);
|
||||
return(dev);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,142 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Stochastic.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color1 clrLightSeaGreen
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
//--- input parameters
|
||||
input int InpKPeriod=5; // K period
|
||||
input int InpDPeriod=3; // D period
|
||||
input int InpSlowing=3; // Slowing
|
||||
//--- indicator buffers
|
||||
double ExtMainBuffer[];
|
||||
double ExtSignalBuffer[];
|
||||
double ExtHighesBuffer[];
|
||||
double ExtLowesBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtMainBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtHighesBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtLowesBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- set levels
|
||||
IndicatorSetInteger(INDICATOR_LEVELS,2);
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20);
|
||||
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,80);
|
||||
//--- set maximum and minimum for subwindow
|
||||
IndicatorSetDouble(INDICATOR_MINIMUM,0);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM,100);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Stoch(%d,%d,%d)",InpKPeriod,InpDPeriod,InpSlowing);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Main");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Signal");
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Stochastic Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int i,k,start;
|
||||
//--- check for bars count
|
||||
if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
|
||||
return(0);
|
||||
//---
|
||||
start=InpKPeriod-1;
|
||||
if(start+1<prev_calculated)
|
||||
start=prev_calculated-2;
|
||||
else
|
||||
{
|
||||
for(i=0; i<start; i++)
|
||||
{
|
||||
ExtLowesBuffer[i]=0.0;
|
||||
ExtHighesBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double dmin=1000000.0;
|
||||
double dmax=-1000000.0;
|
||||
for(k=i-InpKPeriod+1; k<=i; k++)
|
||||
{
|
||||
if(dmin>low[k])
|
||||
dmin=low[k];
|
||||
if(dmax<high[k])
|
||||
dmax=high[k];
|
||||
}
|
||||
ExtLowesBuffer[i]=dmin;
|
||||
ExtHighesBuffer[i]=dmax;
|
||||
}
|
||||
//--- %K
|
||||
start=InpKPeriod-1+InpSlowing-1;
|
||||
if(start+1<prev_calculated)
|
||||
start=prev_calculated-2;
|
||||
else
|
||||
{
|
||||
for(i=0; i<start; i++)
|
||||
ExtMainBuffer[i]=0.0;
|
||||
}
|
||||
//--- main cycle
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double sum_low=0.0;
|
||||
double sum_high=0.0;
|
||||
for(k=(i-InpSlowing+1); k<=i; k++)
|
||||
{
|
||||
sum_low +=(close[k]-ExtLowesBuffer[k]);
|
||||
sum_high+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
|
||||
}
|
||||
if(sum_high==0.0)
|
||||
ExtMainBuffer[i]=100.0;
|
||||
else
|
||||
ExtMainBuffer[i]=sum_low/sum_high*100;
|
||||
}
|
||||
//--- signal
|
||||
start=InpDPeriod-1;
|
||||
if(start+1<prev_calculated)
|
||||
start=prev_calculated-2;
|
||||
else
|
||||
{
|
||||
for(i=0; i<start; i++)
|
||||
ExtSignalBuffer[i]=0.0;
|
||||
}
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
double sum=0.0;
|
||||
for(k=0; k<InpDPeriod; k++)
|
||||
sum+=ExtMainBuffer[i-k];
|
||||
ExtSignalBuffer[i]=sum/InpDPeriod;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user