Custom Indicator not drawing lines, but data Prints out in Experts tab

 

I know this must be really simple or obvious to others but I am still kind of new to MQL5 and am only partially successful at converting my MT4 indicators (my EA is going to be a nightmare, I'm sure).  The data shows when I use the print function but no lines are displayed.  Also nothing shows for this in the data window, which is probably a clue.  I thought I had it when I saw I was missing the PLOT_DRAW_TYPE,DRAW_LINE, but no.  I have read many help articles but can't seem to find the answer.  If anyone can help, THANKS!  Here is the code trying to make fractals display lines instead of the arrows (with a little extra garbage):

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_color1 clrPaleGreen
#property indicator_color2 clrTomato

input int numberOfBars=1000;
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
bool firstTime;
//--- Auxiliary arrays 
   double Ups[],Downs[]; 
   datetime Time[]; 
//+------------------------------------------------------------------+
void OnInit()
  {
   firstTime=true;
  //IndicatorBuffers(2);
 
//---- drawing settings
//--- Set the arrays as timeseries 
   ArrayResize(Ups,numberOfBars,0);
   ArraySetAsSeries(Ups,true); 
   ArrayResize(Downs,numberOfBars,0);
   ArraySetAsSeries(Downs,true); 
   ArrayResize(Time,numberOfBars,0);
   ArraySetAsSeries(Time,true); 
   
   IndicatorSetString(INDICATOR_SHORTNAME,"iFractalLines");
  
   SetIndexBuffer(0,v1,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,indicator_color1);
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(0,PLOT_LABEL,"Resistance");
    

   SetIndexBuffer(1,v2,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(1,PLOT_LINE_COLOR,indicator_color2);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(1,PLOT_LABEL,"Support");
 
   return;
  }

//+------------------------------------------------------------------+
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[])
  {

//--- Create handle of the Indicator Fractals 
   int FractalsHandle=iFractals(NULL,0); 
   //Print("FractalsHandle = ",FractalsHandle); 
//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups); 
   if(copied<=0) 
     { 
      Print("Unable to copy the upper fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs); 
   if(copied<=0) 
     { 
      Print("Unable to copy the bottom fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Copy timeseries containing the opening bars of the last 1000 ones 
   copied=CopyTime(NULL,0,0,1000,Time); 
   if(copied<=0) 
     { 
      Print("Unable to copy the Opening Time of the last 1000 bars"); 
      return(0); 
     } 
  
   //int upcounter=0,downcounter=0; // count there the number of arrows 
   //bool created;// receive the result of attempts to create an object 
   //i=1000;
   ArrayResize(v1,numberOfBars,0);
   ArrayResize(v2,numberOfBars,0);
   //Print("ArraySize(v1)=",ArraySize(v1));
   v1[numberOfBars-1]=0;
   v2[numberOfBars-1]=0;
   for(i=numberOfBars-2 ;i>=0;i--)// Run through the values of the indicator iFractals 
     { 
      if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal 
        { 
         v1[i]=iHigh(NULL,PERIOD_CURRENT,i);
         //Print("v1[",i,"]=",v1[i]);
        } 
      else
        {
        v1[i] = v1[i+1];
         //Print("v1[",i,"]=",v1[i]);
         }

      if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal 
        { 
         v2[i]=iLow(NULL,PERIOD_CURRENT,i);
        } 
      else
         v2[i] = v2[i+1];
     } 
   }
   return(0);
  }
 
omega13lives :

I know this must be really simple or obvious to others but I am still kind of new to MQL5 and am only partially successful at converting my MT4 indicators (my EA is going to be a nightmare, I'm sure).  The data shows when I use the print function but no lines are displayed.  Also nothing shows for this in the data window, which is probably a clue.  I thought I had it when I saw I was missing the PLOT_DRAW_TYPE,DRAW_LINE, but no.  I have read many help articles but can't seem to find the answer.  If anyone can help, THANKS!  Here is the code trying to make fractals display lines instead of the arrows (with a little extra garbage):

Correct the main mistake: you create an indicator handle AT EVERY TICK !!!

Remember, read the help, see examples: in MQL5, the indicator handle MUST BE CREATED ONCE and this is done in OnInit !!!

 
Vladimir Karputov:

Correct the main mistake: you create an indicator handle AT EVERY TICK !!!

Remember, read the help, see examples: in MQL5, the indicator handle MUST BE CREATED ONCE and this is done in OnInit !!!

Thank you I will try this.  I am not very good at MQL5 and I copied the code EXACTLY from the documentation, which is usually quite confusing and hard to understand if you are not an expert with MQL5.  I don't understand why, but I moved it to the OnInit.  I recompiled the code and I still do not see the lines from the indicator buffers.
 
omega13lives :
Thank you I will try this.  I am not very good at MQL5 and I copied the code EXACTLY from the documentation, which is usually quite confusing and hard to understand if you are not an expert with MQL5.  I don't understand why, but I moved it to the OnInit.  I recompiled the code and I still do not see the lines from the indicator buffers .

Where is the MQL5 code? No code, no help.

 
Vladimir Karputov:

Where is the MQL5 code? No code, no help.

All I did was move the code but here it is:

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 2
#property indicator_color1 clrPaleGreen
#property indicator_color2 clrTomato

input int numberOfBars=1000;
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
bool firstTime;
//--- Auxiliary arrays 
   double Ups[],Downs[]; 
   datetime Time[]; 
int FractalsHandle;
//+------------------------------------------------------------------+
void OnInit()
  {
   firstTime=true;
//--- Create handle of the Indicator Fractals 
   FractalsHandle=iFractals(NULL,0); 
   //Print("FractalsHandle = ",FractalsHandle); 

  //IndicatorBuffers(2);
 
//---- drawing settings
//--- Set the arrays as timeseries 
   ArrayResize(Ups,numberOfBars,0);
   ArraySetAsSeries(Ups,true); 
   ArrayResize(Downs,numberOfBars,0);
   ArraySetAsSeries(Downs,true); 
   ArrayResize(Time,numberOfBars,0);
   ArraySetAsSeries(Time,true); 
   
   IndicatorSetString(INDICATOR_SHORTNAME,"iFractalLines");
  
   SetIndexBuffer(0,v1,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,indicator_color1);
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(0,PLOT_LABEL,"Resistance");
    

   SetIndexBuffer(1,v2,INDICATOR_DATA);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_DASH);
   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,1);
   PlotIndexSetInteger(1,PLOT_LINE_COLOR,indicator_color2);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,998);//i-1);
   PlotIndexSetString(1,PLOT_LABEL,"Support");
 
   return;
  }

//+------------------------------------------------------------------+
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[])
  {

//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups); 
   if(copied<=0) 
     { 
      Print("Unable to copy the upper fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs); 
   if(copied<=0) 
     { 
      Print("Unable to copy the bottom fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Copy timeseries containing the opening bars of the last 1000 ones 
   copied=CopyTime(NULL,0,0,1000,Time); 
   if(copied<=0) 
     { 
      Print("Unable to copy the Opening Time of the last 1000 bars"); 
      return(0); 
     } 
  
   //int upcounter=0,downcounter=0; // count there the number of arrows 
   //bool created;// receive the result of attempts to create an object 
   //i=1000;
   ArrayResize(v1,numberOfBars,0);
   ArrayResize(v2,numberOfBars,0);
   //Print("ArraySize(v1)=",ArraySize(v1));
   v1[numberOfBars-1]=0;
   v2[numberOfBars-1]=0;
   for(i=numberOfBars-2 ;i>=0;i--)// Run through the values of the indicator iFractals 
     { 
      if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal 
        { 
         v1[i]=iHigh(NULL,PERIOD_CURRENT,i);
         //Print("v1[",i,"]=",v1[i]);
        } 
      else
        {
        v1[i] = v1[i+1];
         //Print("v1[",i,"]=",v1[i]);
         }

      if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal 
        { 
         v2[i]=iLow(NULL,PERIOD_CURRENT,i);
        } 
      else
         v2[i] = v2[i+1];
     } 
   }
   return(0);
  }
 
omega13lives :

All I did was move the code but here it is:

Why are you using 'CopyTime', 'iHigh' and 'iLow' ??? The indicator already supplies all arrays:

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[])
  {

Correct your mistakes.

 

Where are the lines with the indicator name? (These lines are put at the very beginning).

See example:

//+------------------------------------------------------------------+
//|                                                  Accelerator.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2020, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Accelerator/Decelerator"

//--- indicator settings

Correct your mistakes.

 
Vladimir Karputov:

Where are the lines with the indicator name? (These lines are put at the very beginning).

See example:

Correct your mistakes.

Why are you being mean?  I don't know what the mistakes are and you are only asking me questions I don't know the answer and tell me to fix it.  If I knew how to fix it I wouldn't be asking for HELP!!!

Here is my line for indicator name: 

IndicatorSetString(INDICATOR_SHORTNAME,"iFractalLines");

What is wrong with that???

I am using iHigh and iLow to place those values into the buffer.  How should I do it??????????

 
I printed out the values for v1 buffer in the Experts tab and they are all correct.  What am I doing wrong with the PlotIndex that the lines are not showing on the chart?  Everything looks EXACTLY as shown in the documentation.
 
omega13lives :
I printed out the values for v1 buffer in the Experts tab and they are all correct.  What am I doing wrong with the PlotIndex that the lines are not showing on the chart?  Everything looks EXACTLY as shown in the documentation.

Fill out the file correctly - write down its name (I gave you an example).

Use arrays from

 OnCalculate


In general, correct your mistakes first. And only then ask.

 
Vladimir Karputov:

Fill out the file correctly - write down its name (I gave you an example).

Use arrays from


In general, correct your mistakes first. And only then ask.

Ok, I hope I fixed all the "mistakes".  Still no lines.

//+------------------------------------------------------------------+
//|                                             UFX INDEX BO Scalper |
//+------------------------------------------------------------------+
#property copyright "UdineFX"
#property link      "udinefx@gmail.com"
#property description "iFractalLines"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

//--- plot Upper
#property indicator_label1  "Resistance"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrPaleGreen
#property indicator_style1  STYLE_DASH
#property indicator_width1  1
//--- plot Lower
#property indicator_label2  "Support"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrTomato
#property indicator_style2  STYLE_DASH
#property indicator_width2  1

input int numberOfBars=1000;
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
//bool firstTime;
//--- Auxiliary arrays 
double Ups[],Downs[]; 
int FractalsHandle;
//+------------------------------------------------------------------+
void OnInit()
  {
   //firstTime=true;
//--- Create handle of the Indicator Fractals 
   FractalsHandle=iFractals(NULL,0); 
   //Print("FractalsHandle = ",FractalsHandle); 

//---- drawing settings
//--- Set the arrays as timeseries 
   ArrayResize(Ups,numberOfBars,0);
   ArraySetAsSeries(Ups,true); 
   ArrayResize(Downs,numberOfBars,0);
   ArraySetAsSeries(Downs,true); 
   
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
  
   SetIndexBuffer(0,v1,INDICATOR_DATA);
   ArraySetAsSeries(v1,true);
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,998);//i-1);
    

   SetIndexBuffer(1,v2,INDICATOR_DATA);
   ArraySetAsSeries(v2,true);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,998);//i-1);
 
   return;
  }

//+------------------------------------------------------------------+
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[])
  {

//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups); 
   if(copied<=0) 
     { 
      Print("Unable to copy the upper fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs); 
   if(copied<=0) 
     { 
      Print("Unable to copy the bottom fractals. Error = ",GetLastError()); 
      return(0); 
     } 
  
   ResetLastError(); 

   ArrayResize(v1,numberOfBars,0);
   ArrayResize(v2,numberOfBars,0);
   //Print("ArraySize(v1)=",ArraySize(v1));
   v1[numberOfBars-1]=0;
   v2[numberOfBars-1]=0;
   for(i=numberOfBars-2 ;i>=0;i--)// Run through the values of the indicator iFractals 
     { 
      if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal 
        { 
         v1[i]=Ups[i];
         //Print("v1[",i,"]=",v1[i]);
        } 
      else
        {
        v1[i] = v1[i+1];
         //Print("v1[",i,"]=",v1[i]);
         }

      if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal 
        { 
         v2[i]=Downs[i];
        } 
      else
         v2[i] = v2[i+1];
     } 
   }
   return(0);
  }
 
Reason: