Easy arrows drawing on the chart

When writing EAs, it is very often necessary to check if it reads indicator data properly. In such cases I find drawArrow function very useful.

The function allows to add an arrow pointing up or down to the chart in an easy way, which helps to visually trace signal generation moments, trend reversals, certain conditions being met or whatever you may want :)

void drawArrow(string iName,int signal,int margin) {

 string name=iName+TimeToStr(Time[0],TIME_DATE|TIME_MINUTES|TIME_SECONDS);
 double p=0;

 if(signal>0) {
  p=Low[0]-margin*Point;
 }

 if(signal<0) {
  p=High[0]+margin*Point;
 }

 if(signal!=0) {

  if(ObjectFind(name)==-1) {
   ObjectCreate(name,OBJ_ARROW,0,Time[0],p);
  }

  ObjectSet(name,OBJPROP_PRICE1,p);

  if(signal>0) {
   ObjectSet(name,OBJPROP_ARROWCODE,241);
  }

  if(signal<0) {
   ObjectSet(name,OBJPROP_ARROWCODE,242);
  }
 }
}

The function takes three parameters:

  • iName – name for an arrow series (thanks to that we can draw many series of arrows on the same chart)
  • signal – decides if an arrow will be pointing down (values less than zero) or up (values greater than zero)
  • margin – distance from the current bar high/low prices

Share with your friends:

Send us your comments

Name (required)

Email (required)

Message

  • Facebook