#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red
extern int SignalPeriod = 12;
extern int ArrowPeriod = 2;
int gi_84 = 1;
int gi_88 = 1;
int gi_92 = 1;
int gi_96 = 999;
extern int SL_pips = 100;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
extern bool AlertON = TRUE;
extern bool Email = TRUE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
datetime g_time_144;
void displayAlert(string as_0, double ad_8, double ad_16, double ad_24) {
string ls_32;
string ls_40;
string ls_48;
string ls_56;
string ls_64;
if (Time[0] != g_time_144) {
g_time_144 = Time[0];
if (ad_24 != 0.0) ls_48 = " at price " + DoubleToStr(ad_24, 4);
else ls_48 = "";
if (ad_8 != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(ad_8, 4);
else ls_40 = "";
if (ad_16 != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(ad_16, 4);
else ls_32 = "";
Alert("BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minute chart");
ls_56 = "BUYSELL MAGIC - " + as_0 + ls_48;
ls_64 = "BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minute chart";
if (Email) SendMail(ls_56, ls_64);
}
}
int init() {
SetIndexBuffer(0, g_ibuf_104);
SetIndexBuffer(1, g_ibuf_108);
SetIndexBuffer(2, g_ibuf_112);
SetIndexBuffer(3, g_ibuf_116);
SetIndexBuffer(4, g_ibuf_120);
SetIndexBuffer(5, g_ibuf_124);
SetIndexStyle(0, DRAW_ARROW, 6, 0);
SetIndexStyle(1, DRAW_ARROW, 6, 0);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(4, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexStyle(5, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexArrow(0, 159);
SetIndexArrow(1, 159);
SetIndexArrow(2, 233);
SetIndexArrow(3, 234);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
string ls_0 = "BUYSELL MAGIC(" + AlertON + "," + ArrowPeriod + ")";
IndicatorShortName(ls_0);
SetIndexLabel(0, "UpTrend Stop");
SetIndexLabel(1, "DownTrend Stop");
SetIndexLabel(2, "UpTrend Signal");
SetIndexLabel(3, "DownTrend Signal");
SetIndexLabel(4, "UpTrend Line");
SetIndexLabel(5, "DownTrend Line");
SetIndexDrawBegin(0, SignalPeriod);
SetIndexDrawBegin(1, SignalPeriod);
SetIndexDrawBegin(2, SignalPeriod);
SetIndexDrawBegin(3, SignalPeriod);
SetIndexDrawBegin(4, SignalPeriod);
SetIndexDrawBegin(5, SignalPeriod);
return (0);
}
int start() {
int li_8;
double lda_12[25000];
double lda_16[25000];
double lda_20[25000];
double lda_24[25000];
double ld_28;
double l_close_36;
for (int l_shift_4 = gi_96; l_shift_4 > 0; l_shift_4--) {
g_ibuf_104[l_shift_4] = 0;
g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
for (l_shift_4 = gi_96 - SignalPeriod - 1; l_shift_4 > 0; l_shift_4--) {
lda_12[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_UPPER, l_shift_4);
lda_16[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_LOWER, l_shift_4);
if (Close[l_shift_4] > lda_12[l_shift_4 + 1]) li_8 = 1;
if (Close[l_shift_4] < lda_16[l_shift_4 + 1]) li_8 = -1;
if (li_8 > 0 && lda_16[l_shift_4] < lda_16[l_shift_4 + 1]) lda_16[l_shift_4] = lda_16[l_shift_4 + 1];
if (li_8 < 0 && lda_12[l_shift_4] > lda_12[l_shift_4 + 1]) lda_12[l_shift_4] = lda_12[l_shift_4 + 1];
lda_20[l_shift_4] = lda_12[l_shift_4] + (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
lda_24[l_shift_4] = lda_16[l_shift_4] - (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
if (li_8 > 0 && lda_24[l_shift_4] < lda_24[l_shift_4 + 1]) lda_24[l_shift_4] = lda_24[l_shift_4 + 1];
if (li_8 < 0 && lda_20[l_shift_4] > lda_20[l_shift_4 + 1]) lda_20[l_shift_4] = lda_20[l_shift_4 + 1];
if (li_8 > 0) {
if (gi_88 > 0 && g_ibuf_104[l_shift_4 + 1] == -1.0) {
g_ibuf_112[l_shift_4] = lda_24[l_shift_4];
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_136) {
ld_28 = Low[1];
if (Low[2] < ld_28) ld_28 = Low[2];
if (Low[3] < ld_28) ld_28 = Low[3];
if (Low[4] < ld_28) ld_28 = Low[4];
ld_28 -= SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Buy signal", 0, ld_28, l_close_36);
gi_136 = TRUE;
gi_140 = FALSE;
}
} else {
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
g_ibuf_112[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_104[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = -1;
g_ibuf_108[l_shift_4] = -1.0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
if (li_8 < 0) {
if (gi_88 > 0 && g_ibuf_108[l_shift_4 + 1] == -1.0) {
g_ibuf_116[l_shift_4] = lda_20[l_shift_4];
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_140) {
ld_28 = High[1];
if (High[2] > ld_28) ld_28 = High[2];
if (High[3] > ld_28) ld_28 = High[3];
if (High[4] > ld_28) ld_28 = High[4];
ld_28 += SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Sell signal", 0, ld_28, l_close_36);
gi_140 = TRUE;
gi_136 = FALSE;
}
} else {
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
g_ibuf_116[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = -1;
g_ibuf_104[l_shift_4] = -1.0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
}
}
return (0);
}