24.10.23
|
|
Premium Mitglied
|
|
Registriert seit: May 2020
Ort: Bielefeld
Beiträge: 345
|
|
Hier, den hatte ich mal modifiziert:
Code:
//+------------------------------------------------------------------+
//| Fractals.mq5 |
//| Copyright 2009-2020, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2020, MetaQuotes Software Corp."
#property link "http://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 Gray
#property indicator_color2 Gray
#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;
input uint Before_Number = 3;
input uint After_Number = 3;
bool UpperCriteriaOK,LowerCriteriaOK;
//+------------------------------------------------------------------+
//| 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);
uint start;
//--- clean up arrays
if(prev_calculated < 7)
{
start = Before_Number;
ArrayInitialize(ExtUpperBuffer, EMPTY_VALUE);
ArrayInitialize(ExtLowerBuffer, EMPTY_VALUE);
}
else
start = rates_total -(1 + Before_Number + After_Number);
//--- main cycle of calculations
for(uint i = start; i < rates_total - After_Number && !IsStopped(); i++)
{
//--- Upper Fractal
UpperCriteriaOK= true;
for(uint k = 0 ; k < Before_Number && UpperCriteriaOK ; k++)
{
if(high[i] < high[i - k])
UpperCriteriaOK=false;
}
for(uint k = 0 ; k < After_Number && UpperCriteriaOK ; k++)
{
if(high[i] < high[i + k])
UpperCriteriaOK=false;
}
if(UpperCriteriaOK)
ExtUpperBuffer[i] = high[i];
else
ExtUpperBuffer[i] = EMPTY_VALUE;
LowerCriteriaOK= true;
for(uint k = 0 ; k < Before_Number && LowerCriteriaOK ; k++)
{
if(low[i] > low[i - k])
LowerCriteriaOK=false;
}
for(uint k = 0 ; k < After_Number && LowerCriteriaOK ; k++)
{
if(low[i] > low[i + k])
LowerCriteriaOK=false;
}
if(LowerCriteriaOK)
ExtLowerBuffer[i] = low[i];
else
ExtLowerBuffer[i] = EMPTY_VALUE;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
|