How can I draw arrow on chart from inside an EA?

 

This is MQL5 question.

AIM: I want to add code that draws arrow from inside the Expert advisor/Robot so that the user can use the arrow signal to enter a trade.

Note: I don't want to have a separate indicator for this.


I have tried below code. I created WorkingArrowC()function then I called it in onInit. I checked the chart nothing is showing. Please help me Thank you.


#property       indicator_chart_window
#property       indicator_buffers 2
#property       indicator_width1  2
#property       indicator_width2  2
#property       indicator_color1  Green
#property       indicator_color2  Red

int KPeriod = 50;
int DPeriod=12;
int Slowing = 12

int draw;
double BuyArrow[];
double SellArrow[];

int OnInit()
  {
//--- create timer
   EventSetTimer(60);

   Comment("");
   ArraySetAsSeries(bar, true);
   
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW,1);
   PlotIndexSetInteger(1,PLOT_ARROW,233); // 233 159
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetString(1,PLOT_LABEL,"Buy");
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,draw);
   SetIndexBuffer(1,BuyArrow,INDICATOR_DATA);
   
   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_ARROW,1);
   PlotIndexSetInteger(2,PLOT_ARROW,234); // 234 233
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetString(2,PLOT_LABEL,"Sell");
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,draw);
   SetIndexBuffer(2,SellArrow,INDICATOR_DATA);
   
   WorkingArrowC();
//---
   return(INIT_SUCCEEDED);
  }

void WorkingArrowC(){
   CopyRates(_Symbol,PERIOD_CURRENT,0,Bars(_Symbol,PERIOD_CURRENT),bar);
   int total = (int)bar.Size()-4;
   int isUp = -1;

   for(int i=1;i<total;i++){
      if(STOCHSignal(i+2) < 
80  && STOCHSignal(i+1)>=
80  && isUp != 0){
         
         string dn_arrow = "sell_arrow"+TimeToString(bar[i+1].time);
         SellArrow[i]=bar[i+1].high+10*_Point;
         Print(dn_arrow);
         isUp=0;
         
      }else if(STOCHSignal(i+2) > 
20  && STOCHSignal(i+1)<=
20  && isUp != 1){
         
         string up_arrow = "buy_arrow"+TimeToString(bar[i+1].time);
         BuyArrow[i]=bar[i+1].low-10*_Point;
         Print(up_arrow);
         isUp=1;
      }
   }
}
 
Raphael Adetunji Olaiyapo: AIM: I want to add code that draws arrow from inside the Expert advisor/Robot so that the user can use the arrow signal to enter a trade.

Note: I don't want to have a separate indicator for this.

   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW,1);
   ⋮
   SetIndexBuffer(1,BuyArrow,INDICATOR_DATA);
  1. There are no plots or buffer in EAs. Of course your code does nothing.
  2. Create an indicator, or read the manual. ObjectCreate - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

Reason: