gpt-4o-2024-05-13· OpenAI
WildChat-4.8M (AI2)
нужен индикатор на mql5 который считает ATR с периодом 10 свечей
- User
нужен индикатор на mql5 который считает ATR с периодом 10 свечей
- Assistant
нужен индикатор на mql5 который считает ATR с периодом 10 свечей
Конечно! Вот пример простого индикатора на MQL5 для платформы MetaTrader 5, который рассчитывает ATR (Average True Range) с периодом 10 свечей:
File -> New -> Indicator.ATR_10) и остальные параметры по умолчанию.//+------------------------------------------------------------------+
//| ATR_10.mq5 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| |
//+------------------------------------------------------------------+
#property copyright "2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrDodgerBlue
//--- input parameters
input int InpAtrPeriod = 10; // ATR period
//--- indicator buffers
double AtrBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorShortName("ATR (" + IntegerToString(InpAtrPeriod) + ")");
SetIndexBuffer(0, AtrBuffer);
SetIndexLabel(0, "ATR");
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(rates_total < InpAtrPeriod)
return(0);
int limit = rates_total - prev_calculated;
if(limit > InpAtrPeriod)
limit = InpAtrPeriod;
for(int i = rates_total - limit; i < rates_total; i++)
{
double true_range = 0;
if(i == 0)
true_range = high[i] - low[i];
else
true_range = MathMax(high[i] - low[i], MathMax(MathAbs(high[i] - close[i - 1]), MathAbs(low[i] - close[i - 1])));
if(i == 0)
AtrBuffer[i] = true_range;
else
AtrBuffer[i] = ((AtrBuffer[i - 1] * (InpAtrPeriod - 1)) + true_range) / InpAtrPeriod;
}
return(rates_total);
}
//+------------------------------------------------------------------+
Этот код создает пользовательский индикатор, который рассчитывает средний истинный диапазон (ATR) с периодом 10. Вы можете изменить параметры индикатора, изменив значение переменной InpAtrPeriod на любое другое значение.
Not yet included in a published release.