Irgendwas funktioniert da bei den Anhängen nicht, also kopiere ich den Code hierher.
Code:
//+------------------------------------------------------------------+
//| Buffers.mqh |
//| Copyright © 2016 Ing. Otto Pauser |
//| Ein Auszug aus meiner Bibliothek |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization of buffers as function |
//+------------------------------------------------------------------+
bool InitIndi(double &Buffer[], // the buffer
ENUM_INDEXBUFFER_TYPE BufType, // INDICATOR_DATA / INDICATOR_COLOR_INDEX / INDICATOR_CALCULATIONS
ENUM_DRAW_TYPE DrwType =DRAW_NONE, // DRAW_NONE .. DRAW_COLOR_CANDLES
ENUM_LINE_STYLE LineStyle=STYLE_SOLID, // STYLE_SOLID .. STYLE_DASHDOTDOT
int LineWidth=1, // PLOT_LINE_WIDTH - 1 ........
int LineColor=clrRed, // PLOT_LINE_COLOR - clr.......
int aIntValue=0, // for SMA,EMA,WMA the period / for Max/Min lookback / for ArrowCode
string PlotLabel="", // PLOT_LABEL - "Any String"
int PlotShift=0) // PLOT_SHIFT
{
static int BufIdx; // counter for bufferindex
SetIndexBuffer (BufIdx,Buffer, BufType );
PlotIndexSetInteger(BufIdx,PLOT_DRAW_TYPE, DrwType );
PlotIndexSetInteger(BufIdx,PLOT_LINE_STYLE, LineStyle);
PlotIndexSetInteger(BufIdx,PLOT_LINE_WIDTH, LineWidth);
PlotIndexSetString (BufIdx,PLOT_LABEL, PlotLabel);
PlotIndexSetDouble (BufIdx,PLOT_EMPTY_VALUE,NULL );
PlotIndexSetInteger(BufIdx,PLOT_SHIFT, PlotShift);
if(DrwType==DRAW_ARROW)
PlotIndexSetInteger(BufIdx,PLOT_ARROW, aIntValue);
if(LineColor==0)
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,aIntValue+1);
else
PlotIndexSetInteger(BufIdx,PLOT_LINE_COLOR, LineColor);
BufIdx++; // increment bufferindex for next Init()
return(true);
}
//+------------------------------------------------------------------+
//| Alert enhanced |
//+------------------------------------------------------------------+
ENUM_INIT_RETCODE MyAlert(string aMsg)
{
Alert(aMsg);
return(INIT_FAILED);
}
int MyAlert(string aMsg, int aRetVal)
{
Alert(aMsg);
return(aRetVal);
}
//+------------------------------------------------------------------+
//| Working with buffers |
//+------------------------------------------------------------------+
double GetAverage(const double &Buf1[], const double &Buf2[], int idx, int count)
{
int start=idx-count;
int limit=start+count;
if(start<0) start=0;
double sum=0;
for(int i=start;i<limit;i++)
sum=sum+MathAbs(Buf1[i]-Buf2[i]);
return(sum/count);
}
bool IsCrossingUp(const double &Buf1[], const double &Buf2[], int idx)
{
if(idx<1) return false;
return(((Buf1[idx-1]<=Buf2[idx-1]) && (Buf1[idx]> Buf2[idx])) ||
((Buf1[idx-1]< Buf2[idx-1]) && (Buf1[idx]>=Buf2[idx])));
}
bool IsCrossingDn(const double &Buf1[], const double &Buf2[], int idx)
{
if(idx<1) return false;
return(((Buf1[idx-1]>=Buf2[idx-1]) && (Buf1[idx]< Buf2[idx])) ||
((Buf1[idx-1]> Buf2[idx-1]) && (Buf1[idx]<=Buf2[idx])));
}
Code:
//+------------------------------------------------------------------+
//| LWMA_Crossover_Signal.mq5 |
//| Copyright © 2016 Ing. Otto Pauser |
//| Original code LWMA-Crossover_Signal.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading) |
//| http://www.jnrtading.co.uk |
//+------------------------------------------------------------------+
//| Allows you to enter two lwma periods and it will then show you at|
//| which point they crossed over. It is more usful on the shorter |
//| periods that get obscured by the bars / candlesticks and when |
//| the zoom level is out. Also allows you then to remove the emas |
//| from the chart. (lwmas are initially set at 5 and 6) |
//+------------------------------------------------------------------+
#include <Buffers.mqh>
#property copyright "Copyright © 2016 Ing. Otto Pauser"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
input int inp_PeriodFast = 5; // MA Period fast
input int inp_PeriodSlow = 6; // MA Period slow
input bool inp_Realtime = true; // Realtime
input bool inp_ShowMAs = true; // Show MAs
input int inp_LineWidth = 1; // MA Linewidth
input int inp_ArrowSize = 1; // Arrowsize
double MA_fast[], // buffer for fast MA
MA_slow[], // buffer for slow MA
CrossUp[], // buffer for signal UP
CrossDn[]; // buffer for signal DN
int haFastMA, // handle for fast MA
haSlowMA; // handle for slow MA
int idxStart; // startindex for calculation
int OnInit() // Custom indicator initialization function
{ // initialize the plotbuffers
InitIndi(CrossUp,INDICATOR_DATA,DRAW_ARROW,STYLE_SOLID,inp_ArrowSize,clrLime,233,"Signal UP");
InitIndi(CrossDn,INDICATOR_DATA,DRAW_ARROW,STYLE_SOLID,inp_ArrowSize,clrRed ,234,"Signal DN");
ENUM_DRAW_TYPE Draw_Type = DRAW_NONE;
if(inp_ShowMAs) Draw_Type = DRAW_LINE;
InitIndi(MA_fast,INDICATOR_DATA,Draw_Type ,STYLE_SOLID,inp_LineWidth,clrLime);
InitIndi(MA_slow,INDICATOR_DATA,Draw_Type ,STYLE_SOLID,inp_LineWidth,clrRed );
haFastMA = iMA(NULL, 0, inp_PeriodFast, 0, MODE_LWMA, PRICE_CLOSE);
haSlowMA = iMA(NULL, 0, inp_PeriodSlow, 0, MODE_LWMA, PRICE_CLOSE);
if((haFastMA==INVALID_HANDLE) || (haSlowMA==INVALID_HANDLE))
return(MyAlert("Invalid handle for iMA"));
return(INIT_SUCCEEDED);
}
// Custom indicator iteration function
int OnCalculate (const int rates_total, // size of input time series
const int prev_calculated, // bars handled in previous call
const datetime& time[], // Time
const double& open[], // Open
const double& high[], // High
const double& low[], // Low
const double& close[], // Close
const long& tick_volume[], // Tick Volume
const long& volume[], // Real Volume
const int& spread[]) // Spread
{
if(prev_calculated==0) // first call of OnCalculate
{
ArrayInitialize(CrossUp,NULL);
ArrayInitialize(CrossDn,NULL);
ArrayInitialize(MA_fast,NULL);
ArrayInitialize(MA_slow,NULL);
idxStart=0;
}
else
idxStart=prev_calculated-1;
if(BarsCalculated(haFastMA)<rates_total) return(0); // check if all data calculated, try again next call
if(BarsCalculated(haSlowMA)<rates_total) return(0); // check if all data calculated, try again next call
if(!inp_Realtime) // no Realtime, only new candles
if(prev_calculated==rates_total)
return(rates_total);
int to_copy; // calculate wow much to copy
if(prev_calculated>rates_total || prev_calculated<=0)
to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated; // last value is always copied
to_copy++;
}
if(CopyBuffer(haFastMA,0,0,to_copy,MA_fast)<=0) return(MyAlert("Error CopyBuffer fastMA",0)); // try to copy and check
if(CopyBuffer(haSlowMA,0,0,to_copy,MA_slow)<=0) return(MyAlert("Error CopyBuffer slowMA",0)); // try to copy and check
for(int i=idxStart;i<rates_total;i++) // calculate the signals
{
double Range=GetAverage(high, low, i, 9);
if(IsCrossingUp(MA_fast, MA_slow, i)) CrossUp[i] = low [i]-Range*0.5; else
if(IsCrossingDn(MA_fast, MA_slow, i)) CrossDn[i] = high[i]+Range*0.5;
}
return(rates_total);
}
Ist zwar einwenig mühsam, aber es funktioniert wenigstens.
|