Indicator not drawing Lines/Arrows New comment

 

Dear All,

       I'm Newbie in MQL5. I made one indicator based on MQL4 file. I've checked all values by printing values and I got proper values but Indicator doesn't draw any arrow or lines. Please anyone can help me with it.  Thanks in Advance.



#property version   "1.00"
#property indicator_chart_window

#include <MovingAverages.mqh>

#define MODE_LOW 1
#define MODE_HIGH 2

#property indicator_buffers 7
#property indicator_plots   4
#property indicator_color1 DodgerBlue 
#property indicator_width1 1
#property indicator_type1   DRAW_ARROW
#property indicator_color2 Red  
#property indicator_type2   DRAW_ARROW
#property indicator_width2 1

#property indicator_type3   DRAW_LINE
#property indicator_color3  DodgerBlue
#property indicator_type4   DRAW_LINE
#property indicator_color4  Red

input int    Value1        = 2;


bool nexttrend;
double minhighprice,maxlowprice;
double up[],down[],atrlo[],atrhi[],trend[];
double arrup[],arrdwn[];

datetime prevTime = 0;

double   HighMA[];
double   LowMA[];


int MA1 = 0;
int MA2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,arrup,INDICATOR_DATA);
   SetIndexBuffer(1,arrdwn,INDICATOR_DATA);
   SetIndexBuffer(2,up,INDICATOR_DATA);
   SetIndexBuffer(3,down,INDICATOR_DATA);
  SetIndexBuffer(4,atrlo,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,atrhi,INDICATOR_CALCULATIONS);
  
   SetIndexBuffer(6,trend,INDICATOR_CALCULATIONS);

   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
   
  /* PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Value1);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,Value1);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,Value1);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,Value1);*/
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   
   
   IndicatorSetString(INDICATOR_SHORTNAME,"Test("+string(Value1)+")");
   
   
   MA1=iMA(NULL,0,Value1,0,MODE_SMA,PRICE_LOW);
   MA2=iMA(NULL,0,Value1,0,MODE_SMA,PRICE_HIGH);

      nexttrend=0;
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
       
      datetime Time[];
      int count = 10;   // number of elements to copy
      ArraySetAsSeries(Time,true);
      CopyTime(_Symbol,_Period,0,count,Time);

      if(Time[0] == prevTime)
         return(0);


      double lowprice_i,highprice_i;  //,lowma,highma;
      int workbar=0;
//--- check for rates count
      if(rates_total<=Value1)
         return(0);
//--- preliminary calculations
     
  
     ArraySetAsSeries(LowMA, true);
      if (CopyBuffer(MA1,0,0,1000,LowMA) < 0){Print("CopyBufferMA1 error =",GetLastError());}
      
      ArraySetAsSeries(HighMA, true);
      if (CopyBuffer(MA2,0,0,1000,HighMA) < 0){Print("CopyBufferMA1 error =",GetLastError());}
   
   
      for(int i=900;i>=0;i--)
     {
      lowprice_i= iLowMQL4(Symbol(),Period(),iLowestMQL4(Symbol(),Period(),MODE_LOW,Value1,i));
      highprice_i=iHighMQL4(Symbol(),Period(),iHighestMQL4(Symbol(),Period(),MODE_HIGH,Value1,i));
      //lowma=iMAMQL4(Symbol(),Period(),21,0,MODE_SMA,PRICE_LOW,i);
      //highma=iMAMQL4(Symbol(),Period(),21,0,MODE_SMA,PRICE_HIGH,i);
      trend[i]=trend[i+1];
     
      arrup[i]  = EMPTY_VALUE;
      arrdwn[i] = EMPTY_VALUE;
      
       if(nexttrend==1)
        {
         maxlowprice=MathMax(lowprice_i,maxlowprice);
         if(HighMA[i]<maxlowprice && close[i]<low[i+1])
           {
            trend[i]=1.0;
            nexttrend=0;
            minhighprice=highprice_i;
           }
        }
      if(nexttrend==0)
        {
         minhighprice=MathMin(highprice_i,minhighprice);
        if(LowMA[i]>minhighprice && close[i]>high[i+1])
           {
            trend[i]=0.0;
            nexttrend=1;
            maxlowprice=lowprice_i;
           }
        }
     if(trend[i]==0.0)
        {
         if(trend[i+1]!=0.0)
           {
            up[i]=down[i+1];
            up[i+1]=up[i];
            arrup[i] = up[i];    // - 2*atr;
           }
         else
           {
            up[i]=MathMax(maxlowprice,up[i+1]);
           }
         atrhi[i] = up[i];;
         atrlo[i] = up[i];
         down[i]=0.0;
        }
      else
        {
         if(trend[i+1]!=1.0)
           {
            down[i]=up[i+1];
            down[i+1]=down[i];
            arrdwn[i] = down[i]; // + 2*atr;           
           }
         else
           {
            down[i]=MathMin(minhighprice,down[i+1]);
           }
         atrhi[i] = down[i];  // + atr
         atrlo[i] = down[i];
         up[i]=0.0;
        }
     }
        
     prevTime = Time[0]; 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
double iLowMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyLow(symbol,timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}
//+------------------------------------------------------------------+
int iLowestMQL4(string symbol,
                int tf,
                int type,
                int count=WHOLE_ARRAY,
                int start=0)
  {
   if(start<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(count<=0) count=Bars(symbol,timeframe);
   if(type==MODE_LOW)
     {
      double Low[];
      ArraySetAsSeries(Low,true);
      CopyLow(symbol,timeframe,start,count,Low);
      return(ArrayMinimum(Low,0,count)+start);
     }
   if(type==MODE_HIGH)
     {
      double High[];
      ArraySetAsSeries(High,true);
      CopyHigh(symbol,timeframe,start,count,High);
      return(ArrayMinimum(High,0,count)+start);
     }

//---
   return(0);
  }
//+------------------------------------------------------------------+
double iHighMQL4(string symbol,int tf,int index)

{
   if(index < 0) return(-1);
   double Arr[];
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(CopyHigh(symbol,timeframe, index, 1, Arr)>0) 
        return(Arr[0]);
   else return(-1);
}
//+------------------------------------------------------------------+
int iHighestMQL4(string symbol,
                 int tf,
                 int type,
                 int count=WHOLE_ARRAY,
                 int start=0)
  {
   if(start<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   if(count<=0) count=Bars(symbol,timeframe);
   if(type==MODE_LOW)
     {
      double Low[];
      ArraySetAsSeries(Low,true);
      CopyLow(symbol,timeframe,start,count,Low);
      return(ArrayMaximum(Low,0,count)+start);
     }
   if(type==MODE_HIGH)
     {
      double High[];
      ArraySetAsSeries(High,true);
      CopyHigh(symbol,timeframe,start,count,High);
      return(ArrayMaximum(High,0,count)+start);
     }
   return(0);
  }
//+------------------------------------------------------------------+
double iMAMQL4(string symbol,
               int tf,
               int period,
               int ma_shift,
               int method,
               int price,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iMA(symbol,timeframe,period,ma_shift,
                  ma_method,applied_price);
   if(handle<0)
     {
      Print("The iMA object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);
     }
  }
//+------------------------------------------------------------------+
ENUM_MA_METHOD MethodMigrate(int method)
  {
   switch(method)
     {
      case 0: return(MODE_SMA);
      case 1: return(MODE_EMA);
      case 2: return(MODE_SMMA);
      case 3: return(MODE_LWMA);
      default: return(MODE_SMA);
     }
  }
//+------------------------------------------------------------------+
ENUM_APPLIED_PRICE PriceMigrate(int price)
  {
   switch(price)
     {
      case 1: return(PRICE_CLOSE);
      case 2: return(PRICE_OPEN);
      case 3: return(PRICE_HIGH);
      case 4: return(PRICE_LOW);
      case 5: return(PRICE_MEDIAN);
      case 6: return(PRICE_TYPICAL);
      case 7: return(PRICE_WEIGHTED);
      default: return(PRICE_CLOSE);
     }
  }
//+------------------------------------------------------------------+
double CopyBufferMQL4(int handle,int index,int shift)
  {
   double buf[];
   switch(index)
     {
      case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
         return(buf[0]); break;
      case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
         return(buf[0]); break;
      case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
         return(buf[0]); break;
      case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
         return(buf[0]); break;
      case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
         return(buf[0]); break;
      default: break;
     }
   return(EMPTY_VALUE);
  }
//+------------------------------------------------------------------+
double iATRMQL4(string symbol,
                int tf,
                int period,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iATR(symbol,timeframe,period);
   if(handle<0)
     {
      Print("The iATR object is not created: Error",GetLastError());
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
//+------------------------------------------------------------------+
  
Files:
Test.mq5  12 kb
Reason: