//+------------------------------------------------------------------+
//| MTF_Fractals.mq4 |
//| Copyright 2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
//---- indicator parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // 時間足
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexStyle(0,DRAW_ARROW);
SetIndexBuffer(0,ExtUpperBuffer);
SetIndexArrow(0, 236);
ArraySetAsSeries(ExtUpperBuffer, true);
SetIndexLabel(0,"Fractals Upper");
SetIndexStyle(1,DRAW_ARROW);
SetIndexBuffer(1,ExtLowerBuffer);
SetIndexArrow(1, 236);
ArraySetAsSeries(ExtLowerBuffer, true);
SetIndexLabel(1,"Fractals Lower");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if (_Period > TimeFrame && TimeFrame != PERIOD_CURRENT) return -1;
int limit = rates_total-prev_calculated-1;
for (int i=limit; i>=0; i--)
{
int bar = iBarShift(NULL, TimeFrame, Time[i], false);
if (bar == -1) continue;
double upper = iFractals(NULL,TimeFrame,MODE_UPPER,bar);
double lower = iFractals(NULL,TimeFrame,MODE_LOWER,bar);
ExtUpperBuffer[i]=upper;
ExtLowerBuffer[i]=lower;
}
return(rates_total);
}
コメント