//+------------------------------------------------------------------+ //| Momentum candles v1.mq5 | //| by cja | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 5 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_CANDLES #property indicator_color1 Green,Red,CLR_NONE #property indicator_width1 3 #property indicator_label1 "Momentum Candles" input int CandlePipValue = 10; input int HilowPipValue = 15; //--- indicator buffers double ExtOBuffer[]; double ExtHBuffer[]; double ExtLBuffer[]; double ExtCBuffer[]; double ExtColorBuffer[]; //--- handles of indicators //--- bars minimum for calculation #define DATA_LIMIT 38 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA); SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA); SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA); SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX); //--- IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- sets first bar from what index will be drawn IndicatorSetString(INDICATOR_SHORTNAME,"Momentum Candles v1"); //--- don't show indicator data in DataWindow PlotIndexSetInteger(0,PLOT_SHOW_DATA,false); //--- sets first candle from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT); //--- get handles //--- initialization done } 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 &TickVolume[], const long &Volume[], const int &Spread[]) { int i,limit; //--- we can copy not all data int to_copy; if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++; } //--- set first bar from what calculation will start if(prev_calculatedClose[i] && (Open[i]-Close[i])>=CandlePipValue*_Point*pipModifier && (High[i]-Low[i])>=HilowPipValue*_Point*pipModifier) ExtColorBuffer[i]=1.0; //--- check for Red Zone and set Color Red if(Open[i]=CandlePipValue*_Point*pipModifier && (High[i]-Low[i])>=HilowPipValue*_Point*pipModifier) ExtColorBuffer[i]=0.0; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+