Der schnellste GD den ich gefunden habe und auch verwende.
Ist halt für den MT5, aber gibt's sicher auch für MT4.
Code:
//+------------------------------------------------------------------+
//| ZeroLag_MA_Mono.mq5 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
//| Formula: |
//| ZeroLAG MA(i) = 2*MA(Price, P1, i) - MA(MA( Price, P1, i), P2, i)|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property description "An attempt to create the moving average with zero lag"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_label1 "ZeroLag_MA_Mono"
#include <SmoothAlgorithms.mqh>
CXMA XMA1,XMA2;
input Smooth_Method MA_Method1=MODE_EMA_;
input int Length1=5;
input int Phase1=5;
input Smooth_Method MA_Method2=MODE_EMA_;
input int Length2=5;
input int Phase2=5;
input Applied_price_ IPC=PRICE_TYPICAL_; // Anwenden auf Preis
input int Shift=0;
input int PriceShift=0;
double ZeroLAG_MA[];
double dPriceShift;
int min_rates_total, min_rates_1, min_rates_2;
void OnInit()
{
min_rates_1=XMA1.GetStartBars(MA_Method1, Length1, Phase1);
min_rates_2=XMA2.GetStartBars(MA_Method2, Length2, Phase2);
min_rates_total=min_rates_1+min_rates_2+1;
XMA1.XMALengthCheck("Length1", Length1);
XMA2.XMALengthCheck("Length2", Length2);
XMA1.XMAPhaseCheck("Phase1", Phase1, MA_Method1);
XMA2.XMAPhaseCheck("Phase2", Phase2, MA_Method2);
dPriceShift=_Point*PriceShift;
SetIndexBuffer(0,ZeroLAG_MA,INDICATOR_DATA);
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
PlotIndexSetDouble (0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
string shortname;
string Smooth1=XMA1.GetString_MA_Method(MA_Method1);
string Smooth2=XMA1.GetString_MA_Method(MA_Method2);
StringConcatenate(shortname,"ZeroLag_MA_Mono(",Length1,", ",Length2,", ",Smooth1,", ",Smooth2,")");
IndicatorSetString (INDICATOR_SHORTNAME,shortname);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
}
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<min_rates_total) return(0);
double price,x1xma,x2xma;
int first,bar;
if(prev_calculated>rates_total || prev_calculated<=0)
first=0;
else
first=prev_calculated-1;
for(bar=first; bar<rates_total && !IsStopped(); bar++)
{
price=PriceSeries(IPC,bar,open,low,high,close);
x1xma=XMA1.XMASeries(0 ,prev_calculated,rates_total,MA_Method1,Phase1,Length1,price,bar,false);
x2xma=XMA2.XMASeries(min_rates_1,prev_calculated,rates_total,MA_Method2,Phase2,Length2,x1xma,bar,false);
ZeroLAG_MA[bar]=2*x1xma-x2xma+dPriceShift;
}
return(rates_total);
}