I would like to turn this into an Expert Advisors

 

Hello, I had this indicator and I wanted to convert it to an Expert Advisor. I tried to do it myself but it didn't work. Thanks!

//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1  1
#property indicator_width2  1
#define MAGIC 94949449
//----
extern bool PushON=true;
extern bool SoundON=true;
extern bool EmailON=false;
extern bool BuyON=false;
extern bool SellON=false;
//---- input parameters
input double Lots=0.2;
input int  StopLoss=600;
input int  TakeProfit=1100;
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MA_Method=0; // SMA 0, EMA 1, SMMA 2, LWMA 3
extern int PriceField=0; // Low/High 0, Close/Close 1
extern int OverBoughtLevel  =80;
extern int OverSoldLevel    =20;
extern bool show_KD_cross=false;
extern bool show_K_OBOScross=true;
extern bool show_D_OBOScross=false;
extern string note_Price="PriceField:  Low/High = 0, Close/Close = 1";
extern string _MA_Method="SMA0 EMA1 SMMA2 LWMA3";
extern string msg="";
double CrossUp[];
double CrossDown[];
datetime prevtime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
     for(i=1; i<=limit; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i ;counter<=i+9;counter++)
        {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
        }
      Range=AvgRange/10;
      fastMAnow=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i);
      fastMAprevious=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1);
      slowMAnow=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i);
      slowMAprevious=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i+1);
      CrossUp[i]=EMPTY_VALUE;
      CrossDown[i]=EMPTY_VALUE;
      if (((show_KD_cross)&&(fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))||
          ((show_K_OBOScross)&&(fastMAnow > OverSoldLevel) && (fastMAprevious < OverSoldLevel))||
          ((show_D_OBOScross)&&(slowMAnow > OverSoldLevel) && (slowMAprevious < OverSoldLevel)) )
         {
          CrossUp[i]=Low[i] - Range*0.5;
          CrossDown[i]=EMPTY_VALUE;
         }
      else if (((show_KD_cross)&&(fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))||
               ((show_K_OBOScross)&&(fastMAnow < OverBoughtLevel) && (fastMAprevious > OverBoughtLevel))||
               ((show_D_OBOScross)&&(slowMAnow < OverBoughtLevel) && (slowMAprevious > OverBoughtLevel)) )
         {
          CrossDown[i]=High[i] + Range*0.5;
          CrossUp[i]=EMPTY_VALUE;
         }
     }
//----,
   if(iTime(Symbol(),0,0) == prevtime) return(0);
   prevtime = iTime(Symbol(),0,0);
   //Alerts and Orders      
   //BUY
   if (CrossUp[1]!=2147483647 &&  CrossUp[1]>0)
     {
      if (BuyON) OrderSend(_Symbol,OP_BUY,Lots,Ask,3,StopLoss,TakeProfit,"Timed Trade",MAGIC,0,clrLime);
      msg=StringConcatenate("BUY @",Ask," ",Symbol(),"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Period=",Period());
      if (PushON) SendNotification(msg);
      if (SoundON) Alert(msg);
      if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
     }
   //SELL
   if (CrossDown[1]!=2147483647 &&  CrossDown[1]>0)
     {
      if (SellON) OrderSend(_Symbol,OP_SELL,Lots,Bid,3,StopLoss,TakeProfit,"Timed Trade",MAGIC,0,clrLime);
      msg=StringConcatenate("SELL @",Ask," ",Symbol(),"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Period=",Period());
      if (PushON) SendNotification(msg);
      if (SoundON) Alert(msg);
      if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
     }

   return(0);
  }
//+------------------------------------------------------------------+
 

Hello, Mehmet ... can you fix this too? Thanks in advance :)

@Mehmet Bastem
 
Khalid Aldarawy: I had this indicator and I wanted to convert it to an Expert Advisor

Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.
          Detailed explanation of iCustom - MQL4 programming forum (2017)

Reason: