84 linhas
5,8 KiB
MQL5
84 linhas
5,8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| L1VolatilityAbsolute.mq5 |
|
|
//| Copyright 2000-2026, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2000-2026, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
#property indicator_separate_window
|
|
#property indicator_buffers 1
|
|
#property indicator_plots 1
|
|
//---
|
|
#property indicator_label1 "L1VolatilityAbsolute"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrOrange
|
|
#property indicator_width1 2
|
|
//---
|
|
input int BarsToShow = 1000; // Number of bars to calculate L1
|
|
input double CoefLambda = 0.015; // Lambda in lambda_max units
|
|
//---
|
|
double Vol[];
|
|
//+------------------------------------------------------------------+
|
|
//| Indicator initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
SetIndexBuffer(0,Vol,INDICATOR_DATA);
|
|
ArrayInitialize(Vol,EMPTY_VALUE);
|
|
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
|
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
|
//---
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| 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 bool warned=false;
|
|
if(rates_total < BarsToShow)
|
|
{
|
|
if(!warned)
|
|
{
|
|
Print("Waiting bars ",BarsToShow);
|
|
warned=true;
|
|
}
|
|
ArrayInitialize(Vol,EMPTY_VALUE);
|
|
return 0;
|
|
}
|
|
static datetime last_bar=0;
|
|
bool new_bar=(time[0]!=last_bar);
|
|
//---
|
|
if(!(prev_calculated==0 || new_bar || rates_total!=prev_calculated))
|
|
return prev_calculated;
|
|
//---
|
|
last_bar=time[0];
|
|
int start=rates_total-BarsToShow;
|
|
int N=BarsToShow;
|
|
for(int i=0;i<start;i++)
|
|
Vol[i]=EMPTY_VALUE;
|
|
//---
|
|
vector<double> price;
|
|
price.Resize(N);
|
|
for(int i=0;i<N;i++)
|
|
price[i]=close[start+i];
|
|
vector<double> l1;
|
|
l1.Resize(N);
|
|
price.L1TrendFilter(l1,CoefLambda,true);
|
|
for(int i=0;i<N;i++)
|
|
Vol[start+i]=MathAbs(close[start+i]-l1[i]);
|
|
//---
|
|
return rates_total;
|
|
}
|
|
//+------------------------------------------------------------------+
|