//+------------------------------------------------------------------+
//| SixtySecondTrades.mq4 |
//| Copyright 2020, Dmitriy Kudryashov. |
//| https://www.mql5.com/ru/users/dlim0n4ik.dk |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Dmitriy Kudryashov."
#property link "https://www.mql5.com/ru/users/dlim0n4ik.dk"
#property version "200.226"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//+------------------------------------------------------------------+
//| Блок вводимых параметров |
//+------------------------------------------------------------------+
extern int ADXbars = 14; //Период ADX
extern int CountBars = 350; //Количество баров для отрисовки
extern string SoundFile="Alert.wav";//Файл звука оповещений (Alerts)
extern bool UseSound=true; //Использовыать звуковое оповещения
bool SoundBuy = false;
bool SoundSell = false;
double up_buffer[];
double down_buffer[];
double adx_plusdi_1;
double adx_plusdi_0;
double adx_minusdi_1;
double adx_minusdi_0;
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Функция инициализации программы |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 108);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 108);
SetIndexBuffer(0, up_buffer);
SetIndexBuffer(1, down_buffer);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Функция деинициализации программы |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--------------------------------------------------------------------
//ObjectDelete("info_copyright");
//--------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, // Размер входных таймсерий
const int prev_calculated, // Обработано баров на предыдущем вызове
const datetime &time[], // Time
const double &open[], // Open
const double &high[], // High
const double &low[], // Low
const double &close[], // Close
const long &tick_volume[], // Tick volume
const long &volume[], // Real volume
const int &spread[] // Spread
)
{
//
//string com;
//com += rates_total + "\n";
//com += prev_calculated + "\n";
//com += Bars + "\n";
//com += IndicatorCounted() + "\n";
//Comment(com);
//--------------------------------------------------------------------
//if(Bars <= 100) // Проверим количества баров для расчётов
// {
// Print("There are not enough bars in history to calculate.");
// return (rates_total);
// }
//--------------------------------------------------------------------
if (CountBars >= Bars) CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars);
SetIndexDrawBegin(1, Bars - CountBars);
//--------------------------------------------------------------------
int ExtCountedBars = IndicatorCounted(); // Получим количества уже посчитанных баров
if(ExtCountedBars < 0) return (-1); // Проверим на возможные ошибки в подсчетах
//--------------------------------------------------------------------
if (ExtCountedBars < 1)
{
for (int clear_bars = 1; clear_bars <= CountBars; clear_bars++)
{
up_buffer[CountBars - clear_bars] = 0.0;
down_buffer[CountBars - clear_bars] = 0.0;
}
//for (int clear_bars = 1; clear_bars <= CountBars; clear_bars++) down_buffer[CountBars - clear_bars] = 0.0;
}
//--------------------------------------------------------------------
for (int index = CountBars; index >= 0; index--)
{
//--- Расчет индикатора ADX на текущем баре
adx_plusdi_0 = iADX(Symbol(),PERIOD_CURRENT, ADXbars, PRICE_CLOSE, MODE_PLUSDI, index);
adx_minusdi_0 = iADX(Symbol(),PERIOD_CURRENT, ADXbars, PRICE_CLOSE, MODE_MINUSDI, index);
//--- Расчет индикатора ADX на предыдущем баре
adx_plusdi_1 = iADX(Symbol(),PERIOD_CURRENT, ADXbars, PRICE_CLOSE, MODE_PLUSDI, index - 1);
adx_minusdi_1 = iADX(Symbol(),PERIOD_CURRENT, ADXbars, PRICE_CLOSE, MODE_MINUSDI, index - 1);
//--- Условие для стрелки вверх
if (adx_plusdi_1 > adx_minusdi_1 && adx_plusdi_0 < adx_minusdi_0)
{
up_buffer[index] = Low[index] - 5.0 * Point; // Нарисуем стрелку вверх под ценой Low
}
//--- Условие для стрелки вниз
if (adx_plusdi_1 < adx_minusdi_1 && adx_plusdi_0 > adx_minusdi_0)
{
down_buffer[index] = High[index] + 5.0 * Point; // Нарисуем стрелку вверх под ценой High
}
так что придется словами…
Kudryashov