Блог им. Mathematic
Давно стоил торговую систему под тренды, и лучше чем МА200 по ценам закрытия пока не нашёл. Если интересно, можете скачать-поглядеть.
для лонга ждёт пару падающих свечей, а потом одну растущую(текущую), если при этом МА10 > МА200 — рисуется стрелочка верх.
Дял шортов — условия противоположные. Ну, естественно, плечи небольшие, стоп выбирайте и ставьте, манименеджмент и риски на вас.
Мне этот индикатор — промежуточный этап в написании много-модельного торгового робота. Это одна из моделей сигналов.
не является инвест. рекомендацией
код индикатора в комментарии.
код на mql5
//+------------------------------------------------------------------+
//| MA_Signal_H1.mq5 |
//| Сигналы: MA10 vs MA200 + свечной паттерн на H1 |
//| Отображение: отдельное окно |
//+------------------------------------------------------------------+
#property copyright «MA Signal H1»
#property version «1.01»
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 2
//--- Параметры
input int InpPeriodMA10 = 10;
input int InpPeriodMA200 = 200;
input ENUM_MA_METHOD InpMethod = MODE_SMA;
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE;
//--- Буферы
double BufferLong[]; // стрелки лонг (значение 1)
double BufferShort[]; // стрелки шорт (значение -1)
double BufferSignal[]; // числовой сигнал: 1, -1, 0 (для EA)
//--- Хэндлы индикаторов
int handleMA10;
int handleMA200;
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, BufferLong, INDICATOR_DATA);
SetIndexBuffer(1, BufferShort, INDICATOR_DATA);
SetIndexBuffer(2, BufferSignal, INDICATOR_CALCULATIONS);
//--- Plot 0: Long (стрелка вверх на уровне 1)
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetString (0, PLOT_LABEL, «Long»);
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrLime);
PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 3);
PlotIndexSetDouble (0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//--- Plot 1: Short (стрелка вниз на уровне -1)
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetString (1, PLOT_LABEL, «Short»);
PlotIndexSetInteger(1, PLOT_ARROW, 234);
PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrRed);
PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 3);
PlotIndexSetDouble (1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
//--- Окно: фиксируем шкалу от -1.5 до 1.5
IndicatorSetInteger(INDICATOR_DIGITS, 0);
IndicatorSetDouble(INDICATOR_MINIMUM, -1.5);
IndicatorSetDouble(INDICATOR_MAXIMUM, 1.5);
handleMA10 = iMA(_Symbol, PERIOD_CURRENT, InpPeriodMA10, 0, InpMethod, InpPrice);
handleMA200 = iMA(_Symbol, PERIOD_CURRENT, InpPeriodMA200, 0, InpMethod, InpPrice);
if(handleMA10 == INVALID_HANDLE || handleMA200 == INVALID_HANDLE)
return INIT_FAILED;
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(handleMA10);
IndicatorRelease(handleMA200);
}
//+------------------------------------------------------------------+
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[])
{
int minBars = MathMax(InpPeriodMA10, InpPeriodMA200) + 4;
if(rates_total < minBars)
return 0;
double ma10[], ma200[];
if(CopyBuffer(handleMA10, 0, 0, rates_total, ma10) <= 0) return 0;
if(CopyBuffer(handleMA200, 0, 0, rates_total, ma200) <= 0) return 0;
int start = (prev_calculated > 1)? prev_calculated — 1: 3;
for(int i = start; i < rates_total — 1; i++)
{
BufferLong[i] = EMPTY_VALUE;
BufferShort[i] = EMPTY_VALUE;
BufferSignal[i] = 0;
bool c1_rising = close[i] > open[i];
bool c2_falling = close[i — 1] < open[i — 1];
bool c3_falling = close[i — 2] < open[i — 2];
bool c1_falling = close[i] < open[i];
bool c2_rising = close[i — 1] > open[i — 1];
bool c3_rising = close[i — 2] > open[i — 2];
//--- Long: MA10 > MA200, 2 падающие, перед ними 1 растущая
if(ma10[i] > ma200[i] && c3_falling && c2_falling && c1_rising)
{
BufferLong[i] = 1;
BufferSignal[i] = 1;
}
//--- Short: MA10 < MA200, 2 растущие, перед ними 1 падающая
if(ma10[i] < ma200[i] && c3_rising && c2_rising && c1_falling)
{
BufferShort[i] = -1;
BufferSignal[i] = -1;
}
}
//--- Текущий (формирующийся) бар — без сигнала
if(rates_total > 0)
{
BufferLong[rates_total — 1] = EMPTY_VALUE;
BufferShort[rates_total — 1] = EMPTY_VALUE;
BufferSignal[rates_total — 1] = 0;
}
return rates_total;
}