MA Toolkit
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «ma_toolkit.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
MA Toolkit — пользовательский индикатор для MetaTrader 5, рассчитывающий два скользящих среднего (быстрое и медленное) с возможностью выбора типа: SMA, EMA или LWMA. Быстрое MA окрашивается по направлению наклона: растущее, падающее или плоское.
Индикатор отображает пересечения двух MA в виде стрелок (бычьи и медвежьих), а также поддерживает информационную панель с текущим состоянием и настройками цвета текста. Доступны уведомления о пересечении на закрытых свечах.
Параметры периодов и ценового типа настраиваются пользователем, а порог плоского наклона позволяет контролировать условие смены цвета линии. Все настройки доступны в диалоге свойств индикатора.
Настройки программы
| Настройка | Описание |
|---|---|
| InpFastType | Тип расчёта быстрой скользящей средней: SMA, EMA или LWMA. |
| InpFastPeriod | Период расчёта быстрой скользящей средней (должен быть не менее 2). |
| InpSlowType | Тип расчёта медленной скользящей средней: SMA, EMA или LWMA. |
| InpSlowPeriod | Период расчёта медленной скользящей средней (должен быть не менее 2). |
| InpPrice | Тип цены, используемой для расчёта скользящих средних: Open, High, Low, Median, Typical, Weighted или Close. |
| InpFlatThreshold | Порог плоского наклона в пунктах на бар. При изменении значения меньше этого порога линия окрашивается как плоская. |
| InpShowSlow | Включает или отключает отображение медленной скользящей средней. |
| InpShowCross | Включает или отключает отображение стрелок пересечения быстрой и медленной MA. |
| InpArrowOffset | Отступ стрелок пересечения от значения цены бара, измеряемый в пунктах. |
| InpShowPanel | Включает или отключает отображение информационной панели с состоянием и наклоном. |
| InpPanelColor | Цвет текста информационной панели. |
| InpAlertOnCross | Включает или отключает всплывающее уведомление при пересечении быстрой MA медленной MA на закрытой свече. |
Поиск по коду файла
#property version "1.00"
#property description "MA Toolkit: two moving averages (SMA, EMA, LWMA) calculated from scratch."
#property description "The fast MA is colored by slope; optional crossover arrows, alerts and info panel."
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots 4
#property indicator_label1 "Fast MA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDodgerBlue,clrOrangeRed,clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_label2 "Slow MA"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrGold
#property indicator_style2 STYLE_DASH
#property indicator_width2 1
#property indicator_label3 "Cross Up"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrLime
#property indicator_width3 1
#property indicator_label4 "Cross Down"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrRed
#property indicator_width4 1
enum ENUM_MA_KIND
{
MA_KIND_SMA, // Simple (SMA)
MA_KIND_EMA, // Exponential (EMA)
MA_KIND_LWMA // Linear weighted (LWMA)
};
input group "Fast moving average"
input ENUM_MA_KIND InpFastType = MA_KIND_EMA; // Fast MA: type
input int InpFastPeriod = 20; // Fast MA: period (2 or more)
input group "Slow moving average"
input ENUM_MA_KIND InpSlowType = MA_KIND_SMA; // Slow MA: type
input int InpSlowPeriod = 50; // Slow MA: period (2 or more)
input group "Price and slope"
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // Applied price
input double InpFlatThreshold = 0.0; // Flat-slope threshold (points per bar)
input group "Display"
input bool InpShowSlow = true; // Show the slow MA
input bool InpShowCross = true; // Show crossover arrows
input int InpArrowOffset = 20; // Arrow offset from the bar (points)
input bool InpShowPanel = true; // Show the info panel
input color InpPanelColor = clrSilver; // Info panel text color
input group "Alerts"
input bool InpAlertOnCross = false; // Pop-up alert on crossover (closed bar)
double FastBuffer[]; // fast MA values
double FastColor[]; // color index of the fast MA (0 = up, 1 = down, 2 = flat)
double SlowBuffer[]; // slow MA values
double BuyBuffer[]; // bullish crossover arrows
double SellBuffer[]; // bearish crossover arrows
double PriceBuffer[]; // applied price (calculation buffer)
int g_fastPeriod; // validated fast period
int g_slowPeriod; // validated slow period
int g_startBar; // first bar where a crossover can be detected
bool g_needCross; // true if crossovers must be calculated
string g_prefix; // unique prefix of the chart objects
datetime g_lastAlertTime; // time of the last bar checked for alerts
string KindName(const ENUM_MA_KIND kind)
{
switch(kind)
{
case MA_KIND_SMA:
return("SMA");
case MA_KIND_EMA:
return("EMA");
case MA_KIND_LWMA:
return("LWMA");
}
return("?");
}
void CreateLabel(const string name,const string text,const int y)
{
if(ObjectFind(0,name) < 0)
ObjectCreate(0,name,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,10);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,name,OBJPROP_COLOR,InpPanelColor);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,9);
ObjectSetString(0,name,OBJPROP_FONT,"Consolas");
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
}
double AppliedPrice(const int i,
const double &open[],
const double &high[],
const double &low[],
const double &close[])
{
switch(InpPrice)
{
case PRICE_OPEN:
return(open[i]);
case PRICE_HIGH:
return(high[i]);
case PRICE_LOW:
return(low[i]);
case PRICE_MEDIAN:
return((high[i] + low[i]) / 2.0);
case PRICE_TYPICAL:
return((high[i] + low[i] + close[i]) / 3.0);
case PRICE_WEIGHTED:
return((high[i] + low[i] + 2.0 * close[i]) / 4.0);
default:
return(close[i]);
}
}
double CalcMA(const ENUM_MA_KIND kind,
const int period,
const int i,
const double &price[],
const double &ma[])
{
if(kind == MA_KIND_EMA)
{
if(i == 0)
return(price[0]);
const double k = 2.0 / (period + 1.0); // smoothing factor
return(price[i] * k + ma[i - 1] * (1.0 - k));
}
if(i < period - 1)
return(EMPTY_VALUE);
double sum = 0.0;
if(kind == MA_KIND_SMA)
{
for(int j = 0; j < period; j++)
sum += price[i - j];
return(sum / period);
}
const double weightSum = period * (period + 1) / 2.0;
for(int j = 0; j < period; j++)
sum += price[i - j] * (period - j);
return(sum / weightSum);
}
void UpdatePanel(const int total)
{
if(!InpShowPanel)
return;
const int last = total - 1;
string state = "Fast/Slow: n/a";
string slope = "flat";
if(FastBuffer[last] != EMPTY_VALUE && SlowBuffer[last] != EMPTY_VALUE)
{
Показано первые 50% кода (символов: 8176)