#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
extern int ADXbars = 14;
extern int CountBars = 350;
extern string SoundFile="Alert.wav";
extern bool UseSound=true;
bool SoundBuy = False;
bool SoundSell = False;
double gda_84[];
double gda_88[];
double gd_92;
double gd_100;
double gd_108;
double gd_116;
int init()
{
//string ls_0;
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 108);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 108);
SetIndexBuffer(0, gda_84);
SetIndexBuffer(1, gda_88);
return (0);
}
int start()
{
if (CountBars >= Bars) CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars);
SetIndexDrawBegin(1, Bars - CountBars);
int li_8 = IndicatorCounted();
if (li_8 < 0) return (-1);
if (li_8 < 1)
{
for (int li_0 = 1; li_0 <= CountBars; li_0++) gda_84[CountBars - li_0] = 0.0;
for (li_0 = 1; li_0 <= CountBars; li_0++) gda_88[CountBars - li_0] = 0.0;
}
for (int li_4 = CountBars; li_4 >= 0; li_4--)
{
gd_92 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, li_4 - 1);
gd_100 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, li_4);
gd_108 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, li_4 - 1);
gd_116 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, li_4);
if (gd_92 > gd_108 && gd_100 < gd_116) gda_84[li_4] = Low[li_4] - 5.0 * Point;
if (gd_92 < gd_108 && gd_100 > gd_116) gda_88[li_4] = High[li_4] + 5.0 * Point;
}
//+------------------------------------------------------------------+
if (gda_84[1] != EMPTY_VALUE && gda_84[1] != 0 && SoundBuy)
{
SoundBuy = False;
if (UseSound) PlaySound (SoundFile);
Alert("OLD-SixtySecondTrades(", Symbol(), ", ", Period(), ") — BUY!!!");
}
if (!SoundBuy && (gda_84[1] == EMPTY_VALUE || gda_84[1] == 0)) SoundBuy = True;
if (gda_88[1] != EMPTY_VALUE && gda_88[1] != 0 && SoundSell)
{
SoundSell = False;
if (UseSound) PlaySound (SoundFile);
Alert("OLD-SixtySecondTrades (", Symbol(), ", ", Period(), ") — SELL!!!");
}
if (!SoundSell && (gda_88[1] == EMPTY_VALUE || gda_88[1] == 0)) SoundSell = True;
//+------------------------------------------------------------------+
return (0);
}
//+------------------------------------------------------------------+
//| 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
}
}
//--------------------------------------------------------------------
//--- Условие для срабатывания оповещения на ПОКУПКУ -----------------
if (up_buffer[1] != EMPTY_VALUE && up_buffer[1] != 0 && SoundBuy) // Если буфер ВВЕРХ не пустой и не имеет значение 0 и звук покупки ИСТИНА
{
SoundBuy = false; //Звук на покупку ЛОЖНО (Оповещение сработало)
if (UseSound) PlaySound (SoundFile); // Выполнить проигрование звукового файла оповещения
Alert("SixtySecondTrades(", Symbol(), ", ", Period(), ") — BUY!!!"); // Сообщение оповещения
}
if (!SoundBuy && (up_buffer[1] == EMPTY_VALUE || up_buffer[1] == 0)) SoundBuy = true; //
//--------------------------------------------------------------------
//--- Условие для срабатывания оповещения на ПРОДАЖУ -----------------
if (down_buffer[1] != EMPTY_VALUE && down_buffer[1] != 0 && SoundSell)// Если буфер ВНИЗ не пустой и не имеет значение 0 и звук продажу ИСТИНА
{
SoundSell = false;//Звук на продажу ЛОЖНО (Оповещение сработало)
if (UseSound) PlaySound (SoundFile); // Выполнить проигрование звукового файла оповещения
Alert("SixtySecondTrades (", Symbol(), ", ", Period(), ") — SELL!!!");// Сообщение оповещения
}
if (!SoundSell && (down_buffer[1] == EMPTY_VALUE || down_buffer[1] == 0)) SoundSell = true;//
//--------------------------------------------------------------------
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
extern int ADXbars = 14;
extern int CountBars = 350;
extern string SoundFile="Alert.wav";
extern bool UseSound=true;
bool SoundBuy = False;
bool SoundSell = False;
double gda_84[];
double gda_88[];
double gd_92;
double gd_100;
double gd_108;
double gd_116;
int init()
{
//string ls_0;
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 108);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 108);
SetIndexBuffer(0, gda_84);
SetIndexBuffer(1, gda_88);
return (0);
}
int start()
{
if (CountBars >= Bars) CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars);
SetIndexDrawBegin(1, Bars - CountBars);
int li_8 = IndicatorCounted();
if (li_8 < 0) return (-1);
if (li_8 < 1)
{
for (int li_0 = 1; li_0 <= CountBars; li_0++) gda_84[CountBars - li_0] = 0.0;
for (li_0 = 1; li_0 <= CountBars; li_0++) gda_88[CountBars - li_0] = 0.0;
}
for (int li_4 = CountBars; li_4 >= 0; li_4--)
{
gd_92 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, li_4 - 1);
gd_100 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_PLUSDI, li_4);
gd_108 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, li_4 - 1);
gd_116 = iADX(NULL, 0, ADXbars, PRICE_CLOSE, MODE_MINUSDI, li_4);
if (gd_92 > gd_108 && gd_100 < gd_116) gda_84[li_4] = Low[li_4] - 5.0 * Point;
if (gd_92 < gd_108 && gd_100 > gd_116) gda_88[li_4] = High[li_4] + 5.0 * Point;
}
//+------------------------------------------------------------------+
if (gda_84[1] != EMPTY_VALUE && gda_84[1] != 0 && SoundBuy)
{
SoundBuy = False;
if (UseSound) PlaySound (SoundFile);
Alert("SixtySecondTrades(", Symbol(), ", ", Period(), ") — BUY!!!");
}
if (!SoundBuy && (gda_84[1] == EMPTY_VALUE || gda_84[1] == 0)) SoundBuy = True;
if (gda_88[1] != EMPTY_VALUE && gda_88[1] != 0 && SoundSell)
{
SoundSell = False;
if (UseSound) PlaySound (SoundFile);
Alert("SixtySecondTrades (", Symbol(), ", ", Period(), ") — SELL!!!");
}
if (!SoundSell && (gda_88[1] == EMPTY_VALUE || gda_88[1] == 0)) SoundSell = True;
//+------------------------------------------------------------------+
return (0);
}
int tickets_orders[];
//+------------------------------------------------------------------+
void close_all_position (string symbol,
int magic
)
{
//--------------------------------------------------------------------
int p = 0;
ArrayResize(tickets_orders,OrdersTotal(),1);
//--------------------------------------------------------------------
for (int index = 0; index < OrdersTotal(); index++)
{
if (OrderSelect(index, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
if (OrderSymbol() == symbol)
{
if (OrderMagicNumber() == magic || magic == NULL)
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
tickets_orders[p] = OrderTicket();
p++;
}
}
}
}
//--------------------------------------------------------------------
string comments="\n";
comments+=((string)p+"\n");
Comment(comments);
Sleep(10000);
//--------------------------------------------------------------------
for (int index = 0;index<ArraySize(tickets_orders);index++)
{
if (OrderSelect(tickets_orders[index],SELECT_BY_TICKET, MODE_TRADES) == FALSE) break;
{
RefreshRates();
if(!OrderClose(OrderTicket(),OrderLots(),(OrderType()==OP_BUY?Bid:Ask),9999,clrNONE))
Alert("Problem with closing #",OrderTicket(),"; Error: ",GetLastError());
}
}
//--------------------------------------------------------------------
}
//+------------------------------------------------------------------+
Kudryashov