Article-20795-MQL5-GRI-Indi.../GRI.mq5

97 lignes
7,7 Kio
MQL5
Brut Lien permanent Vue normale Historique

2026-03-24 17:56:06 +07:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| GRI.mq5 |
//| 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 indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
//--- plot GRI
#property indicator_label1 "GRI"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDodgerBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input(name="ChaoticPeriod") int InpPeriod = 5; // 5@8>4 @0AGQB0
//--- indicator buffers
double BufferGRI[];
//--- global variables
int ExtPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,BufferGRI,INDICATOR_DATA);
ArraySetAsSeries(BufferGRI,true); // 1CD5@ :0: B09<A5@8O
//--- #AB0=02;8205< ?0@0<5B@K 8=48:0B>@0
ExtPeriod=(InpPeriod<2 ? 2 : InpPeriod); // :>@@5:B8@C5< ?5@8>4 @0AGQB0
string short_name=StringFormat("GRI(%d)",ExtPeriod); // >?@545;O5< :>@>B:>5 8<O
IndicatorSetString(INDICATOR_SHORTNAME,short_name); // CAB0=02;8205< :>@>B:>5 8<O
IndicatorSetInteger(INDICATOR_DIGITS,_Digits); // B>G=>ABL >B>1@065=8O
IndicatorSetDouble(INDICATOR_MINIMUM,0.0); // 8=8<0;L=>5 7=0G5=85 H:0;K
//--- AQ CA?5H=>
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int32_t rates_total,
const int32_t 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 int32_t &spread[])
{
//--- 0AA82 close - :0: B09<A5@8O
ArraySetAsSeries(close,true);
//--- @>25@:0 :>;8G5AB20 4>ABC?=KE 10@>2
if(rates_total<fmax(ExtPeriod,5))
return 0;
//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2
int limit=rates_total-prev_calculated;
//--- A;8 ?5@2K9 70?CA: 8;8 87<5=5=8O 8AB>@8G5A:8E 40==KE
if(limit>1)
{
limit=rates_total-ExtPeriod-1; // @0AGQB =0G8=05< >B =0G0;0 8AB>@8G5A:8E 40==KE
ArrayInitialize(BufferGRI,EMPTY_VALUE); // 8=8F80;878@C5< 1CD5@ 8=48:0B>@0 ?CABK< 7=0G5=85<
}
//--- A=>2=>9 F8:;
for(int i=limit;i>=0;i--)
{
//--- @0AAG8BK205< 480?07>= F5= 70:@KB8O 70 ExtPeriod 10@>2
int mx=ArrayMaximum(close,i,ExtPeriod);
int mn=ArrayMinimum(close,i,ExtPeriod);
if(mx==WRONG_VALUE || mn==WRONG_VALUE)
return 0;
//--- <0:A8<0;L=>5 8 <8=8<0;L=>5 7=0G5=8O Close 70 ?5@8>4 ExtPeriod
double max=close[mx];
double min=close[mn];
double range = max-min;
//--- @0AAG8B05< 8 70?8H5< 2 1CD5@ 7=0G5=85 "E0>B8G=>AB8" 70 ExtPeriod 10@>2
BufferGRI[i] = (MathLog(1.0 + range)/MathLog((double)ExtPeriod))/_Point; // 80?07>= 7=0G5=89 >B =C;O 8 2KH5
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+