#property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Green #property indicator_color2 Violet #property indicator_color3 Green #property indicator_color4 Violet extern int MA_Price = 0; extern int MA_Length = 1; extern int MA_Mode = 0; extern int ATR_Length = 8; extern double Kv = 4.0; extern double MoneyRisk = 1.0; extern bool usePrice_HiLoBreak = TRUE; extern bool useMA_HiLoEnvelope = FALSE; extern int AlertMode = 0; extern int VisualMode = 0; extern string Applied_Price_ = "0-C,1-O,2-H,3-L,4-Median(H+L)/2,5-Typical(H+L+C)/3,6-Weighted(H+L+C+C)/4"; extern string MAmethod_mode_ = "0-SMA,1-EMA,2-SMMA,3-LWMA"; extern string Visual_Mode___ = "0-lines,1-dots "; double g_ibuf_148[]; double g_ibuf_152[]; double g_ibuf_156[]; double g_ibuf_160[]; double g_ibuf_164[]; double g_ibuf_168[]; double g_ibuf_172[]; bool gi_176 = FALSE; bool gi_180 = FALSE; int init() { IndicatorBuffers(7); SetIndexBuffer(0, g_ibuf_148); SetIndexBuffer(1, g_ibuf_152); SetIndexBuffer(2, g_ibuf_156); SetIndexBuffer(3, g_ibuf_160); SetIndexBuffer(4, g_ibuf_164); SetIndexBuffer(5, g_ibuf_168); SetIndexBuffer(6, g_ibuf_172); if (VisualMode == 0) { SetIndexStyle(0, DRAW_LINE); SetIndexStyle(1, DRAW_LINE); } else { SetIndexStyle(0, DRAW_ARROW); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(0, 159); SetIndexArrow(1, 159); } SetIndexStyle(2, DRAW_ARROW); SetIndexStyle(3, DRAW_ARROW); SetIndexArrow(2, 108); SetIndexArrow(3, 108); string ls_0 = " Guard Indicator(" + MA_Length + "," + ATR_Length + "," + DoubleToStr(Kv, 3) + ")"; IndicatorShortName(ls_0); SetIndexLabel(0, "UpTrend"); SetIndexLabel(1, "DnTrend"); SetIndexLabel(2, "UpSignal"); SetIndexLabel(3, "DnSignal"); SetIndexDrawBegin(0, MA_Length + ATR_Length); SetIndexDrawBegin(1, MA_Length + ATR_Length); SetIndexDrawBegin(2, MA_Length + ATR_Length); SetIndexDrawBegin(3, MA_Length + ATR_Length); return (0); } int start() { int li_4; double l_ima_12; double l_ima_20; string ls_28; int l_ind_counted_8 = IndicatorCounted(); if (l_ind_counted_8 > 0) li_4 = Bars - l_ind_counted_8; if (l_ind_counted_8 < 0) return (0); if (l_ind_counted_8 == 0) li_4 = Bars - MA_Length - 1; for (int li_0 = li_4; li_0 >= 0; li_0--) { if (useMA_HiLoEnvelope) { l_ima_12 = iMA(NULL, 0, MA_Length, 0, MA_Mode, PRICE_HIGH, li_0); l_ima_20 = iMA(NULL, 0, MA_Length, 0, MA_Mode, PRICE_LOW, li_0); } else { l_ima_12 = iMA(NULL, 0, MA_Length, 0, MA_Mode, MA_Price, li_0); l_ima_20 = iMA(NULL, 0, MA_Length, 0, MA_Mode, MA_Price, li_0); } g_ibuf_168[li_0] = l_ima_12 + Kv * iATR(NULL, 0, ATR_Length, li_0); g_ibuf_164[li_0] = l_ima_20 - Kv * iATR(NULL, 0, ATR_Length, li_0); g_ibuf_172[li_0] = g_ibuf_172[li_0 + 1]; if (usePrice_HiLoBreak) { if (High[li_0] > g_ibuf_168[li_0 + 1]) g_ibuf_172[li_0] = 1; if (Low[li_0] < g_ibuf_164[li_0 + 1]) g_ibuf_172[li_0] = -1; } else { if (l_ima_12 > g_ibuf_168[li_0 + 1]) g_ibuf_172[li_0] = 1; if (l_ima_20 < g_ibuf_164[li_0 + 1]) g_ibuf_172[li_0] = -1; } if (g_ibuf_172[li_0] > 0.0) { if (g_ibuf_164[li_0] < g_ibuf_164[li_0 + 1]) g_ibuf_164[li_0] = g_ibuf_164[li_0 + 1]; g_ibuf_148[li_0] = g_ibuf_164[li_0] - (MoneyRisk - 1.0) * iATR(NULL, 0, ATR_Length, li_0); if (g_ibuf_148[li_0] < g_ibuf_148[li_0 + 1] && g_ibuf_148[li_0 + 1] != EMPTY_VALUE) g_ibuf_148[li_0] = g_ibuf_148[li_0 + 1]; if (g_ibuf_172[li_0 + 1] != g_ibuf_172[li_0]) g_ibuf_156[li_0] = g_ibuf_148[li_0]; else g_ibuf_156[li_0] = EMPTY_VALUE; g_ibuf_152[li_0] = EMPTY_VALUE; g_ibuf_160[li_0] = EMPTY_VALUE; } else { if (g_ibuf_172[li_0] < 0.0) { if (g_ibuf_168[li_0] > g_ibuf_168[li_0 + 1]) g_ibuf_168[li_0] = g_ibuf_168[li_0 + 1]; g_ibuf_152[li_0] = g_ibuf_168[li_0] + (MoneyRisk - 1.0) * iATR(NULL, 0, ATR_Length, li_0); if (g_ibuf_152[li_0] > g_ibuf_152[li_0 + 1]) g_ibuf_152[li_0] = g_ibuf_152[li_0 + 1]; if (g_ibuf_172[li_0 + 1] != g_ibuf_172[li_0]) g_ibuf_160[li_0] = g_ibuf_152[li_0]; else g_ibuf_160[li_0] = EMPTY_VALUE; g_ibuf_148[li_0] = EMPTY_VALUE; g_ibuf_156[li_0] = EMPTY_VALUE; } } } if (g_ibuf_172[2] < 0.0 && g_ibuf_172[1] > 0.0 && Volume[0] > 1.0 && !gi_176) { ls_28 = " " + Symbol() + " M" + Period() + ": Guard Signal for BUY"; if (AlertMode > 0) Alert(ls_28); gi_176 = TRUE; gi_180 = FALSE; } if (g_ibuf_172[2] > 0.0 && g_ibuf_172[1] < 0.0 && Volume[0] > 1.0 && !gi_180) { ls_28 = " " + Symbol() + " M" + Period() + ": Guard Signal for SELL"; if (AlertMode > 0) Alert(ls_28); gi_180 = TRUE; gi_176 = FALSE; } return (0); }