//+------------------------------------------------------------------+
//| SuperTrend_Cross_Arrow.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
extern int Fast_CCIperiod = 50;
extern int Fast_ATRperiod = 5;
extern int Slow_CCIperiod = 100;
extern int Slow_ATRperiod = 10;
extern int ArrowGap = 10;
extern string ST_Indicator_Name = "SuperTrend nrp"; // без .mq4
extern bool EnableAlert = true;
extern bool EnableSound = true;
extern bool EnablePush = false;
double BuyArrow[];
double SellArrow[];
int OnInit()
{
SetIndexBuffer(0, BuyArrow);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233); // стрелка вверх
SetIndexBuffer(1, SellArrow);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234); // стрелка вниз
return(INIT_SUCCEEDED);
}
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 limit = rates_total - 100;
if (limit < 1) return(0);
for (int i = limit; i >= 1; i--)
{
double fastDirPrev = iCustom(NULL, 0, ST_Indicator_Name, "", Fast_CCIperiod, Fast_ATRperiod, 5, 3, i + 1);
double fastDirCurr = iCustom(NULL, 0, ST_Indicator_Name, "", Fast_CCIperiod, Fast_ATRperiod, 5, 3, i);
double slowDirPrev = iCustom(NULL, 0, ST_Indicator_Name, "", Slow_CCIperiod, Slow_ATRperiod, 5, 3, i + 1);
double slowDirCurr = iCustom(NULL, 0, ST_Indicator_Name, "", Slow_CCIperiod, Slow_ATRperiod, 5, 3, i);
// Buy signal
if (fastDirPrev == -1 && slowDirPrev == -1 && fastDirCurr == 1 && slowDirCurr == 1)
{
BuyArrow = Low - ArrowGap * Point;
SellArrow = EMPTY_VALUE;
if (i == 1) TriggerAlert("Buy", Time);
}
// Sell signal
else if (fastDirPrev == 1 && slowDirPrev == 1 && fastDirCurr == -1 && slowDirCurr == -1)
{
SellArrow = High + ArrowGap * Point;
BuyArrow = EMPTY_VALUE;
if (i == 1) TriggerAlert("Sell", Time);
}
else
{
BuyArrow = EMPTY_VALUE;
SellArrow = EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Функция алертов и уведомлений |
//+------------------------------------------------------------------+
void TriggerAlert(string signalType, datetime barTime)
{
string msg = "SuperTrend Cross Signal: " + signalType + " on " + Symbol() + " (" + TimeToString(barTime, TIME_DATE | TIME_MINUTES) + ")";
if (EnableAlert) Alert(msg);
if (EnableSound) PlaySound("alert.wav");
if (EnablePush) SendNotification(msg);
}