It is often necessary to write an indicator, which will mark some important point on the price chart with a dot or an arrow, e.g. an oscillator reaching certain level or a moving average crossing.
Personally, I like such indicators very much, because they don’t clutter up the chart and allow to indicate precisely the place of a certain condition occuring, which is not so easy to read from the oscillator window.
Implementation of such indicator is very simple and I will show you the template below.
#property indicator_chart_window // we set the number of buffers and indicator buffers colors #property indicator_buffers 2 #property indicator_color1 RoyalBlue #property indicator_color2 Red // it's good to make our dots bigger to see them better #property indicator_width1 2 #property indicator_width2 2 // we define indicator arrays double long[]; double short[]; // extern variable to set the distance of the dot from the candle extern int margin=20; int init() { // we set the properties of indicator buffers SetIndexBuffer(0,long); SetIndexStyle(0,DRAW_ARROW,0,1); SetIndexArrow(0,159); // 159 is a dot code SetIndexBuffer(1,short); SetIndexStyle(1,DRAW_ARROW,0,1); SetIndexArrow(1,159); return(0); } int start() { // we start checking conditions for the last 500 periods for(int i=0;i<500;i++) { if(........) { // long condition (blue dot under the candle) long[i]=Low[i]-margin*Point; } else { long[i]=EMPTY_VALUE; } if(........) { // short condition (red dot under the candle) short[i]=High[i]+margin*Point; } else { short[i]=EMPTY_VALUE; } } return(0); }
Arrow drawing code looks similiar, but we set the second argument of a SetIndexArrow function to 241 for long and to 242 for short.