#property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 2 #property indicator_color1 clrBlue #property indicator_color2 clrRed #property indicator_width1 1 #property indicator_width2 1 double dUpBuffer[]; double dDownBuffer[]; double dTrendBuffer[]; extern int MA_Period = 20; extern ENUM_MA_METHOD MA_Method_1 = MODE_SMA; extern ENUM_MA_METHOD MA_Method_2 = MODE_SMA; extern ENUM_APPLIED_PRICE MA_Price_1 = PRICE_HIGH; extern ENUM_APPLIED_PRICE MA_Price_2 = PRICE_LOW; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(3); //---- indicator buffers mapping SetIndexBuffer(0, dUpBuffer); SetIndexBuffer(1, dDownBuffer); SetIndexBuffer(2, dTrendBuffer); //---- drawing settings SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233); //241 option for different arrow head SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 234); //242 option for different arrow head //---- SetIndexEmptyValue(0, EMPTY_VALUE); SetIndexEmptyValue(1, EMPTY_VALUE); SetIndexEmptyValue(2, EMPTY_VALUE); //---- name for DataWindow SetIndexLabel(0, "Up"); SetIndexLabel(1, "Down"); SetIndexDrawBegin(0, MA_Period - 1); SetIndexDrawBegin(1, MA_Period - 1); IndicatorShortName("MA Arrows (" + MA_Period + ")"); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); int limit = Bars - counted_bars - 1; if (limit > Bars - MA_Period) limit = Bars - MA_Period; double spread = MarketInfo(Symbol(), MODE_SPREAD) * MarketInfo(Symbol(), MODE_POINT); for (int i = limit; i >= 1; i--) { double myMA1 = iMA(NULL, 0, MA_Period, 0, MA_Method_1, MA_Price_1, i); double myMA2 = iMA(NULL, 0, MA_Period, 0, MA_Method_2, MA_Price_2, i); if (Close[i] > myMA1) dTrendBuffer[i] = 1; else if (Close[i] < myMA2) dTrendBuffer[i] = 2; if ((dTrendBuffer[i + 1] != 1) && (dTrendBuffer[i] == 1)) dUpBuffer[i] = High[i] + 2 * spread; if ((dTrendBuffer[i + 1] != 2) && (dTrendBuffer[i] == 2)) dDownBuffer[i] = Low[i] - 2 * spread; } return(0); }