support_and_resistance.mq5
Похожие материалы по тегам
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «support_and_resistance.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
Данный продукт представляет собой пользовательский индикатор для платформы MetaTrader 5, написанный на языке MQL5. Он рассчитывает диапазоны ценовых зон на основе сглаженного индикатора ATR(200) и отображает их на графике в виде заливаемых прямоугольников и горизонтальных линий.
Индикатор определяет центральную цену как середину бара (HL2), а расстояние до верхней и нижней границ вычисляет как произведение 100-барной скользящей средней ATR на заданный множитель. При пробое ценой верхней или нижней границы диапазон сбрасывается и начинает формироваться заново, а направление тренда фиксируется.
На графике отрисовываются маркеры подтверждённых пробоев, сигналы на промежуточных уровнях, а также опциональные маркеры ложных пробоев. Старые объекты автоматически удаляются за пределами заданного количества видимых баров. Индикатор не использует торговые функции и не отправляет ордера.
Настройки программы
| Настройка | Описание |
|---|---|
| InpMulti | Множитель, применяемый к сглаженному ATR для определения расстояния от центра до каждой границы диапазона. |
| InpDisplayBars | Количество последних баров, в пределах которых объекты диапазонов остаются видимыми на графике. |
| InpFillZones | Включает или отключает заливку верхней и нижней зон диапазона. |
| InpZoneColorUpper | Цвет верхней зоны диапазона. |
| InpZoneColorLower | Цвет нижней зоны диапазона. |
| InpColorBullish | Цвет, используемый для бычьих маркеров пробоя и сигналов покупки. |
| InpColorBearish | Цвет, используемый для медвежьих маркеров пробоя и сигналов продажи. |
| InpDebugLog | Включает или отключает вывод отладочных сообщений в журнал Experts. |
| InpFilterSignals | Отображать сигналы на промежуточных уровнях только при совпадении с текущим трендом. |
| InpShowX | Отображает маркеры X для неудачных пробоев границ диапазона. |
Поиск по коду файла
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
input double InpMulti = 4.0; // Multiplier applied to the smoothed ATR to determine distance from the center to each boundary
input int InpDisplayBars = 500; // Number of recent bars for which range objects remain visible
input bool InpFillZones = true; // Enable or disable filling of the upper and lower zones
input color InpZoneColorUpper = C'34,88,209'; // Color of the upper zone
input color InpZoneColorLower = C'247,207,158'; // Color of the lower zone
input color InpColorBullish = C'29,172,112'; // Color used for bullish breakout and buy markers
input color InpColorBearish = C'223,58,121'; // Color used for bearish breakout and sell markers
input bool InpDebugLog = false; // Enable debug messages in the Experts log
input bool InpFilterSignals = false; // Show midpoint signals only when they agree with the current trend
input bool InpShowX = false; // Show X markers for failed breakouts
int g_atrHandle = INVALID_HANDLE; // Handle for the ATR(200) indicator
double g_atrRaw[];
double ATRSmooth[]; // Stores the 100-bar smoothed ATR multiplied by InpMulti
double Value[]; // Stores the central price of each range
double ValueUpper[]; // Stores the upper boundary of each range
double ValueLower[]; // Stores the lower boundary of each range
double ValueUpperMid[]; // Stores the midpoint between the central price and upper boundary
double ValueLowerMid[]; // Stores the midpoint between the central price and lower boundary
double Trend[]; // Stores the current directional state: 1 for bullish, 0 for bearish
double SegStartTime[]; // Stores the starting time of each range segment
#define OBJ_PREFIX "ATRCH_" // Prefix used to identify objects created by this indicator
color g_MidColor; // Stores the chart foreground color for the middle range lines
void UpsertZone(string name, datetime t1, double p1v, datetime t2, double p2v, color clr)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_RECTANGLE, 0, t1, p1v, t2, p2v);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_FILL, InpFillZones);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
}
else
{
ObjectSetInteger(0, name, OBJPROP_TIME, 1, t2);
}
}
void UpsertHLine(string name, datetime t1, double price, datetime t2, color clr, bool dotted)
{
if(ObjectFind(0, name) < 0)
{
ObjectCreate(0, name, OBJ_TREND, 0, t1, price, t2, price);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_STYLE, dotted ? STYLE_DOT : STYLE_SOLID);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, false);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
}
else
{
ObjectSetInteger(0, name, OBJPROP_TIME, 1, t2);
}
}
void DrawO(datetime t, double price, color clr, bool upper)
{
string name = OBJ_PREFIX + "O_" + (upper ? "u_" : "l_") + (string)((long)t);
if(ObjectFind(0, name) >= 0)
return;
ObjectCreate(0, name, OBJ_TEXT, 0, t, price);
ObjectSetString(0, name, OBJPROP_TEXT, CharToString(108));
ObjectSetString(0, name, OBJPROP_FONT, "Wingdings");
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 12);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_CENTER);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
if(InpDebugLog)
PrintFormat("ATRCH: O created at %s price=%.5f",
TimeToString(t, TIME_DATE|TIME_MINUTES|TIME_SECONDS), price);
}
void DrawTriangle(datetime t, double price, color clr, bool up)
{
string name = OBJ_PREFIX + (up ? "Buy_" : "Sell_") + (string)((long)t);
if(ObjectFind(0, name) >= 0)
return;
ObjectCreate(0, name, OBJ_ARROW, 0, t, price);
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, up ? 233 : 234);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, up ? ANCHOR_TOP : ANCHOR_BOTTOM);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
}
void DrawX(datetime t, double price, color clr, bool anchorAbove)
{
string name = OBJ_PREFIX + "X_" + (string)((long)t) + (anchorAbove ? "a" : "b");
if(ObjectFind(0, name) >= 0)
return;
ObjectCreate(0, name, OBJ_TEXT, 0, t, price);
ObjectSetString(0, name, OBJPROP_TEXT, "X");
ObjectSetString(0, name, OBJPROP_FONT, "Arial Bold");
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, anchorAbove ? ANCHOR_BOTTOM : ANCHOR_TOP);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
}
void PruneOldObjects(const datetime &time[], int rates_total)
{
int cutoffIdx = rates_total - InpDisplayBars;
if(cutoffIdx < 0)
return;
datetime cutoffTime = time[cutoffIdx];
int total = ObjectsTotal(0, 0, -1);
for(int o = total - 1; o >= 0; o--)
{
string nm = ObjectName(0, o, 0, -1);
if(StringFind(nm, OBJ_PREFIX) != 0)
continue;
long typeVal = ObjectGetInteger(0, nm, OBJPROP_TYPE);
datetime tEnd;
if(typeVal == OBJ_RECTANGLE || typeVal == OBJ_TREND)
tEnd = (datetime)ObjectGetInteger(0, nm, OBJPROP_TIME, 1);
else
tEnd = (datetime)ObjectGetInteger(0, nm, OBJPROP_TIME, 0);
if(tEnd < cutoffTime)
ObjectDelete(0, nm);
}
}
int OnInit()
{
// код доступен только после оплаты
}
g_atrHandle = iATR(NULL, 0, 200);
if(g_atrHandle == INVALID_HANDLE)
{
Print("Failed to create ATR(200) handle");
return(INIT_FAILED);
}
if(InpMulti <= 0Показано первые 50% кода (символов: 9559)