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

 

Until you complete the file name

Forum on trading, automated trading systems and testing trading strategies

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

Vladimir Karputov, 2021.02.18 07:24

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.


- you do not get advice.

 
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):

Example Fractals Channel


Fractals Channel

Figure: 1. Fractals Channel indicator and two additional indicators: 'Fractals' and' MACD "

 
Vladimir Karputov:

Until you complete the file name


- you do not get advice.

Look at previous post!!!

3rd line!!!

 
omega13lives :

Look at previous post!!!

3rd line!!!

I do not understand. What is the third line? Did you originally want to connect fractals?

 
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2
//--- plot Res
#property indicator_label1  "Resistance"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrPaleGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Sup
#property indicator_label2  "Support"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrTomato
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         ResBuffer[];
double         SupBuffer[];
double         UpperBuffer[];
double         LowerBuffer[];
int handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if((handle=iFractals(_Symbol,_Period))==INVALID_HANDLE)
      return(INIT_FAILED);
//--- indicator buffers mapping
   SetIndexBuffer(0,ResBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,SupBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,UpperBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,LowerBuffer,INDICATOR_CALCULATIONS);
//---
   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[])
  {
//---
   const int toCopy=(prev_calculated<1)?rates_total:(rates_total!=prev_calculated)?rates_total-prev_calculated+2:3;
//---
   if(CopyBuffer(handle,0,0,toCopy,UpperBuffer)!=toCopy ||
      CopyBuffer(handle,1,0,toCopy,LowerBuffer)!=toCopy)
      return(0);
//---
   const int begin=(prev_calculated<1)?3:(rates_total!=prev_calculated)?prev_calculated-2:prev_calculated-3;
//---
   for(int i=begin;i<rates_total && !_StopFlag;i++)
     {
      double upper=UpperBuffer[i-2];
      double lower=LowerBuffer[i-2];
      double res0,res1,sup0,sup1;
      ResBuffer[i]=res0=(upper!=EMPTY_VALUE)?upper:res1=ResBuffer[i-1];
      ResBuffer[i-1]=(res1==res0)?res1:EMPTY_VALUE;
      SupBuffer[i]=sup0=(lower!=EMPTY_VALUE)?lower:sup1=SupBuffer[i-1];
      SupBuffer[i-1]=(sup1==sup0)?sup1:EMPTY_VALUE;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
 
Ernst Van Der Merwe :

Same idea? 

Fractals Corridor Breakdown

Fractals Corridor Breakdown


Fractals Corridor Breakdown
Fractals Corridor Breakdown
  • www.mql5.com
Индикатор на основе iFractals. Плюс зарисовка свечи, которая пробивает фрактал
 
Ernst Van Der Merwe:

Thanks Ernst, very helpful, but I still can't figure out why my indicator doesn't show any lines.  I will study these examples further and if you have an idea I will gladly listen.  Here is what the MT4 version looks like:

(and why can't I insert a picture that shows like everyone else and not an attached file?)
Files:
SRFractal.jpg  61 kb
 
Vladimir Karputov:

Same idea? 

Fractals Corridor Breakdown


Yes. Difference is the previous level extends two bars more because it only starts plotting on the bar when the fractal occurs, so no redrawing.


 
omega13lives:

Thanks Ernst, very helpful, but I still can't figure out why my indicator doesn't show any lines.  I will study these examples further and if you have an idea I will gladly listen.  Here is what the MT4 version looks like:

(and why can't I insert a picture that shows like everyone else and not an attached file?)

Your code is working this side. It's more efficient to only copy what is needed though.

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;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//--- Set Last error value to Zero 
   ResetLastError(); 
//--- Try to copy the values of the indicator 
   int toCopy=(prev_calculated<1)?rates_total:(rates_total!=prev_calculated)?rates_total-prev_calculated+2:3;
   //Sleep(1000);
   //if(!firstTime)
   {
   int copied=CopyBuffer(FractalsHandle,0,0,toCopy,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,toCopy,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;
   const int limit=(prev_calculated<1)?rates_total-3:(rates_total!=prev_calculated)?rates_total-prev_calculated+1:2;

   for(i=limit ;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 value of prev_calculated for next call
   return(rates_total);
  }
 
Ernst Van Der Merwe:

Your code is working this side. It's more efficient to only copy what is needed though.

This is driving me crazy!  I modified my code to what you posted and I STILL don't see the lines on my chart.  I even removed it, recompiled and put it back on the chart... nothing.  It shows in the list but does not show in the Data window either.  What could I possibly be doing wrong?  The 2 indicators mentioned here show on the screen and the Fractal_Channel indi from MetaQuotes shows on the screen, but uses different calculations, but mine does not.  Any ideas?

Fractals - Bill Williams' Indicators - MetaTrader 5 Help
Fractals - Bill Williams' Indicators - MetaTrader 5 Help
  • www.metatrader5.com
All markets are characterized by the fact that on the most part the prices do not change too much, and only short periods of time (15–30 percent)...
Reason: