Is it possible to interrupt the line of an indicator?

 
Hello,

Is it possible to interrupt the line of an indicator?

I tried setting it to null at points, but I get vertical lines.

//--------------------------------------------------------------------
// hight5bars.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
#property indicator_chart_window    // Indicator is drawn in the main window
#property indicator_buffers 2       // Number of buffers
#property indicator_color1 Blue     // Color of the 1st line
#property indicator_color2 Red      // Color of the 2nd line

double Buf_0[],Buf_1[];             // Declaring arrays (for indicator buffers)
//--------------------------------------------------------------------
int init() {                        // Special function init()
        SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
        SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style
        SetIndexBuffer(1,Buf_1);         // Assigning an array to a buffer
        SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1);// Line style
        return;                          // Exit the special funct. init()
}
//--------------------------------------------------------------------
int start() {                       // Special function start()
        int i,j,                           // Bar index
            Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
        Counted_bars=IndicatorCounted(); // Number of counted bars
        i=Bars-Counted_bars-1;           // Index of the first uncounted
        while(i>=0) {
                if(j<5) {
                        Buf_0[i]=High[i];             // Value of 0 buffer on i bar
                        Buf_1[i]=Low[i];              // Value of 1st buffer on i bar
                } else if(j<9) {
                        Buf_0[i]=NULL;             // Value of 0 buffer on i bar
                        Buf_1[i]=NULL;              // Value of 1st buffer on i bar
                } else {
                        Buf_0[i]=NULL;             // Value of 0 buffer on i bar
                        Buf_1[i]=NULL;              // Value of 1st buffer on i bar
                        j=-1;
                }
                i--;                          // Calculating index of the next bar
                j++;                          // Calculating index of the next bar
        }
//--------------------------------------------------------------------
        return;                          // Exit the special funct. start()
}
//--------------------------------------------------------------------

 

tintin92: Is it possible to interrupt the line of an indicator?

I tried setting it to null at points, but I get vertical lines.

  1. You set it to the value you used in SetIndexEmptyValue - MQL4 Documentation which defaults to EMPTY_VALUE.
  2. You don't actually have to set the buffer unless you previously did and want to change it.
  3. NULL is ONLY used to specify the current market pair in some function calls.
 

NULL will set any type of variable to zero. That is why you get the vertical lines it is drawing a line down to price value 0.0

 

Thanks to William Roeder and SDC.

Works great.

//--------------------------------------------------------------------
// hight5bars.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
#property indicator_chart_window    // Indicator is drawn in the main window
#property indicator_buffers 2       // Number of buffers
#property indicator_color1 Blue     // Color of the 1st line
#property indicator_color2 Red      // Color of the 2nd line

double Buf_0[],Buf_1[];             // Declaring arrays (for indicator buffers)
//--------------------------------------------------------------------
int init() {                        // Special function init()
        SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
        SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style
        SetIndexBuffer(1,Buf_1);         // Assigning an array to a buffer
        SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1);// Line style
        
//---- 0 value will not be displayed
    SetIndexEmptyValue(0,EMPTY_VALUE);
    SetIndexEmptyValue(1,EMPTY_VALUE);
        
        return;                          // Exit the special funct. init()
}
//--------------------------------------------------------------------
int start() {                       // Special function start()
        int i,j,                           // Bar index
            Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
        Counted_bars=IndicatorCounted(); // Number of counted bars
        i=Bars-Counted_bars-1;           // Index of the first uncounted
        while(i>=0) {
                if(j<5) {
                        Buf_0[i]=High[i];             // Value of 0 buffer on i bar
                        Buf_1[i]=Low[i];              // Value of 1st buffer on i bar
                } else if(j<9) {
                } else {
                        j=-1;
                }
                i--;                          // Calculating index of the next bar
                j++;                          // Calculating index of the next bar
        }
//--------------------------------------------------------------------
        return;                          // Exit the special funct. start()
}
//--------------------------------------------------------------------
 

You don't need this:

//---- 0 value will not be displayed
    SetIndexEmptyValue(0,EMPTY_VALUE);
    SetIndexEmptyValue(1,EMPTY_VALUE);

It is already EMPTY_VALUE.

Reason: