Break in Indicator

 

Is there a way to stop the indicator from drawing when a certain criteria is met? I am currently trying to program a D-Wave indicator and I am trying to figure out how to "stop" the indicator when the wave is completed.

The attached code will currently have a line that goes from when the wave is completed to the start of the next wave. I want this line to be deleted.

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
//Wave formatting:
extern color Upclr=Red; //color of up wave

//Text formatting:
extern int  NbrSize=8;  //size of wave marker
extern int Space=100;   //position of marker

//misc
extern int  showBars=1000;

double dWaveHigh[], dWaveLow[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_ZIGZAG);
   SetIndexStyle(1,DRAW_ZIGZAG);
//---- indicator buffers mapping
   SetIndexBuffer(0,dWaveHigh);
   SetIndexBuffer(1,dWaveLow);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
  int wCounterUp;
  int pos0up, pos1up, pos2up;
  int tfm=Space*Point;
  
  double lowval, highval, strtval;
  bool W0upA, W0upB, W1up, W2up;
  
  if (showBars==0) showBars=Bars;
  for(int cnt=showBars;cnt>=0;cnt--) 
     {
     ObjectDelete("Wave");
     
//+------------------------------------------------------------------+
//|Up Wave Cycle                                                     |
//+------------------------------------------------------------------+
      if(wCounterUp==0 && W0upA==false)
         {
         dWaveHigh[cnt]=0.0;
         strtval=Close[iLowest(NULL,0,MODE_CLOSE,21,cnt)];
         if(Close[cnt]==strtval)
            {
            pos0up=cnt;
            W0upA=true;
            }
         }
      if(wCounterUp==0 && W0upA==true)
         {
         strtval=Close[iHighest(NULL,0,MODE_CLOSE,13,cnt-12)];
         if(Close[cnt-12]==strtval)
            {
            W0upB=true;
            W0upA=false;
            lowval=Low[iLowest(NULL,0,MODE_LOW,14,cnt-13)];
            pos0up=cnt;
            }
         }
      if(wCounterUp==0 && W0upB==true && Low[cnt]==lowval)
         {
         pos0up=cnt;
         dWaveLow[cnt]=lowval;
         wCounterUp++;
         }
      if(wCounterUp==1 && Wave1Up(cnt)!=0)
         {
         highval=High[iHighest(NULL,0,MODE_HIGH,9,cnt-8)];
         W0upB=false;
         W1up=true;
         lowval=0;
         }
      if(W1up==true && High[cnt]==highval)
         {
         ObjectCreate("Wave"+cnt,OBJ_TEXT,0,Time[cnt],High[cnt]+tfm);
         ObjectSetText("Wave"+cnt,""+wCounterUp,NbrSize,"Arial",Upclr);
         wCounterUp++;
         W1up=false;
         pos1up=cnt;
         dWaveHigh[cnt]=highval;
         }
      if(wCounterUp==2 && Wave2Up(cnt)!=0)
         {
         lowval=Low[iLowest(NULL,0,MODE_LOW,22,cnt-21)];
         W2up=true;
         highval=0;
         }
      if(W2up==true && Low[cnt]==lowval)
         {
         ObjectCreate("Wave"+cnt,OBJ_TEXT,0,Time[cnt],Low[cnt]-tfm);
         ObjectSetText("Wave"+cnt,""+wCounterUp,NbrSize,"Arial",Upclr);
         wCounterUp++;
         W2up=false;
         pos2up=cnt;
         dWaveLow[cnt]=lowval;
         }
      if(wCounterUp==3 && Close[cnt]>High[pos1up])
         {
         highval=Close[cnt];
         dWaveHigh[cnt]=highval;
         wCounterUp++;
         lowval=0;
         }
      if(wCounterUp==4)
         {
         dWaveLow[cnt]=0.0;
         wCounterUp=0;
         }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Wave1Up(int i)
   {
   double val;
   val=Close[iLowest(NULL,0,MODE_CLOSE,8,i-8)];
   if(Close[i-8]==val)
      {
      return(High[i]);
      }
   else return(0);
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Wave2Up(int i)
   {
   double val;
   val=Close[iHighest(NULL,0,MODE_CLOSE,21,i-21)];
   if(Close[i-21]==val)
      {
      return(Low[i]);
      }
   else return(0);
   }
 

Hi

You can fill the indicator buffers dWaveHigh & DWaveLow with EMPTY when you don't want them displayed.

 
Ruptor wrote >>

Hi

You can fill the indicator buffers dWaveHigh & DWaveLow with EMPTY when you don't want them displayed.

Except that when you do that the line still exists it just drops down. I want it to disappear at this point. I figured that I could do the empty and change the color of the line to match the background, but I am wondering if there isn't a better way to do this.

 
LadyPips:

Except that when you do that the line still exists it just drops down. I want it to disappear at this point. I figured that I could do the empty and change the color of the line to match the background, but I am wondering if there isn't a better way to do this.

Use two buffers, one for what u want to see and the other for what u do not want to see

 
LadyPips:

Except that when you do that the line still exists it just drops down.

I have always found the indicator buffers very quirky. The EMPTY value worked for me but only when the buffers were drawn in a certain order. I was accidently getting gaps in my Tema worm line where I was using 3 buffers of different colours so it is definitely possible to generate gaps. Maybe one of the experts can help. Incidently when you say drop down it sounds like you are using the value 0 rather than the predefined constant EMPTY. Try setting the buffer[i]=EMPTY before deciding what to put in it.

 

Thank you to you both for your responses but I still have a few questions.

Ronaldoism,

What do you mean by "use two buffers"? Will I need to have a seperate High and Low zig zag that this one connects to in order to get the gap? Can you give an example of this?

Ruptor,

I did set the buffer to =EMPTY. The problem is that the setindexemptyvalue is set to 0.0, so when my buffer equals empty it drops the lines down to 0.0. I have tried to set my setindexemptyvalue to equal NULL but I get the same effect. What was your empty value set to that caused you to get the gap, do you remember?

 

Hi

You can find the value of an empty buffer by printing it out before setting it's elements. I have never needed to load the enormous value. Aaaaah! I just realised you are not using EMPTY as a shorthand you require EMPTY_VALUE. This is the correct value to use sorry I didn't pickup on that sooner.

 
Ruptor wrote >>

Hi

You can find the value of an empty buffer by printing it out before setting it's elements. I have never needed to load the enormous value. Aaaaah! I just realised you are not using EMPTY as a shorthand you require EMPTY_VALUE. This is the correct value to use sorry I didn't pickup on that sooner

Placing in EMPTY_VALUE seems to make the code worse. Now all of my indicators are dropping down to 0.
 
LadyPips wrote >>

Thank you to you both for your responses but I still have a few questions.

Ronaldoism,

What do you mean by "use two buffers"? Will I need to have a seperate High and Low zig zag that this one connects to in order to get the gap? Can you give an example of this?

Ruptor,

I did set the buffer to =EMPTY. The problem is that the setindexemptyvalue is set to 0.0, so when my buffer equals empty it drops the lines down to 0.0. I have tried to set my setindexemptyvalue to equal NULL but I get the same effect. What was your empty value set to that caused you to get the gap, do you remember?

Some lines have two colours; to achieve two colours u need two buffers for the same line; so in yr case u need one to see and the other to hide;

tell me what exactly are u doing in this indicator, I tried to load into chart and i see zig zag with 2 appearing but I do not know what u are trying to draw

 
ronaldosim wrote >>

Some lines have two colours; to achieve two colours u need two buffers for the same line; so in yr case u need one to see and the other to hide;

tell me what exactly are u doing in this indicator, I tried to load into chart and i see zig zag with 2 appearing but I do not know what u are trying to draw

The D-Wave is basically a mechanized Elliot Wave, so eventually I will put in all of the coding for 5 waves and the abc waves. Right now I am just trying to figure if I want to use the buffers and the DRAW_ZIGZAG or if I will just do Objects with Trend lines. I figured that the ZIGZAG would be a little bit cleaner so I was leaning more towards that. I am testing right now to see if I can accomplish what I need to with the ZIGZAG and that is basically that when the wave is completed I need there to be a gap between the end of the wave and the start of a new one.

I know that using the ObjectCreate with the Trendlines will work, it just involves a lot of setting up the properties and then a lot of deleting past objects. As my knowledge of MQL is somewhat limited I thought that I would venture into something new by seeing if I could use the indicator buffers instead and if this would be cleaner.

 
LadyPips:
Placing in EMPTY_VALUE seems to make the code worse. Now all of my indicators are dropping down to 0.

Hi

Here is an example of breaks in an indicator produced by setting Fatbuffer to the EMPTY_VALUE instead of letting it be yellow. You should check your code because clearly the value does its job. Maybe you can learn from this example.

Files:
ifatworm.mq4  5 kb
Reason: