Download MetaTrader 5

Delete pre-alert

To add comments, please log in or register
They are making profit already using Freelance service. You can join them!
Massimo
479
Massimo 2016.03.18 23:53 

Hi guys. I have a problem I can not solve. I created this code where I have a pre-alert. Buffer1 and buffer2 are pre-alert, while the Buffer 3 and Buffer 4 are

the real alert.

I wish I could erase the dots of the pre-alert all the times that of Alert arrow appears. I made several attempts but did not succeed. Can you help me?

Thank you all, Massimo

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 Yellow
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 Yellow
#property indicator_label2 "Sell"

#property indicator_type3 DRAW_ARROW
#property indicator_width3 1
#property indicator_color3 Green
#property indicator_label3 "Buy"

#property indicator_type4 DRAW_ARROW
#property indicator_width4 1
#property indicator_color4 Red
#property indicator_label4 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Test @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 108);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 108);
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, 0);
   SetIndexArrow(2, 241);
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, 0);
   SetIndexArrow(3, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
      ArrayInitialize(Buffer3, 0);
      ArrayInitialize(Buffer4, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(iDeMarker(NULL, PERIOD_CURRENT, 3, i) == 0 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 3, 1+i) != 0 //DeMarker is not equal to fixed value
      )
        {
         Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(iDeMarker(NULL, PERIOD_CURRENT, 3, i) == 1 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 3, 1+i) != 1 //DeMarker is not equal to fixed value
      )
        {
         Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
        }
      else
        {
         Buffer2[i] = 0;
        }
      //Indicator Buffer 3
      if(iDeMarker(NULL, PERIOD_CURRENT, 4, i) == 0 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 4, 1+i) != 0 //DeMarker is not equal to fixed value
      )
        {
         Buffer3[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
         //Buffer1[i]=False;
         //Buffer2[i]=False;
         
         
        }
      else
        {
         Buffer3[i] = 0;
        }
      //Indicator Buffer 4
      if(iDeMarker(NULL, PERIOD_CURRENT, 4, i) == 1 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 4, 1+i) != 1 //DeMarker is not equal to fixed value
      )
        {
         Buffer4[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
         //Buffer1[i]=False;
         //Buffer2[i]=False;
        }
      else
        {
         Buffer4[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

 

Vasyl Nosal
18545
Vasyl Nosal 2016.03.19 09:17  

Delete 

 double Buffer1[];

double Buffer2[];
anf than delte all what comilier will say.
Massimo
479
Massimo 2016.03.19 11:05  
Hello eevviill thanks for the answer, but you have to help me because I can not solve. I entered the code but I can not figure out where to enter "delete".

Thanks for everything and for your kindness, greetings, Massimo.

//Indicator Buffer 3
      if(iDeMarker(NULL, PERIOD_CURRENT, 4, i) == 0 
      && iDeMarker(NULL, PERIOD_CURRENT, 4, 1+i) != 0
      )
        {
         Buffer3[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); 
        
         Buffer1[1]=0;
         Buffer2[1]=0;
         
         
        }
      else
        {
         Buffer3[i] = 0;
        }
Vasyl Nosal
18545
Vasyl Nosal 2016.03.19 11:23  

?

Attach code in file. 

Massimo
479
Massimo 2016.03.19 11:49  
eevviill:

?

Attach code in file. 


Eevviill Hello, I tried but it gives me error. Where I'm wrong. I'm sorry!! Thank you!!

 //Indicator Buffer 3
      if(iDeMarker(NULL, PERIOD_CURRENT, 4, i) == 0 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 4, 1+i) != 0 //DeMarker is not equal to fixed value
      )
        {
         Buffer3[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
          delete
          double Buffer1[1];
          double Buffer2[1];
         
         
        }
      else
        {
         Buffer3[i] = 0;
        }
whroeder1
14512
whroeder1 2016.03.19 12:23  
omissamf: . Buffer1 and buffer2 are pre-alert,  ... erase the dots of the pre-alert
Just don't assign to them
/*
     //Indicator Buffer 1
      if(iDeMarker(NULL, PERIOD_CURRENT, 3, i) == 0 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 3, 1+i) != 0 //DeMarker is not equal to fixed value
      )
        {
         Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(iDeMarker(NULL, PERIOD_CURRENT, 3, i) == 1 //DeMarker is equal to fixed value
      && iDeMarker(NULL, PERIOD_CURRENT, 3, 1+i) != 1 //DeMarker is not equal to fixed value
      )
        {
         Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
        }
      else
        {
         Buffer2[i] = 0;
        }
*/
     //Indicator Buffer 3
:
Vasyl Nosal
18545
Vasyl Nosal 2016.03.19 12:56  
omissamf:

Eevviill Hello, I tried but it gives me error. Where I'm wrong. I'm sorry!! Thank you!!

And do not use this 

if(Digits() == 5 || Digits() == 3)

     {

      myPoint *= 10;

     } 

 

There are many pairs that have 1Point=4,6... digits

Just set to inputs

enum dig_koefs

{

_1=1,_10=10,_100=100, 

};

extern  dig_koefs point_koef=_10;

...

 myPoint = Point*point_koef; 
Files:
lfuk45qi.mq4 4 kb
Massimo
479
Massimo 2016.03.19 13:51  
Hi guys and thanks for the answers, but I still do not understand. Forgive me !!!
In the attached photo, we see the result indicator. If I did not declare the buffer half as suggest by WHRoeder, the graph does not appear on pre-alert.
  I would rather that when you see the green or red arrow, yellow dots of pre-alert disappear, leaving only the arrows of Alert.
I would like every time you see an arrow, the buffer1 / 2 results were deleted from the chart.
  Thanks for everything, Massimo.




Massimo
479
Massimo 2016.03.19 18:24  
Hi guys, I have tried to solve in this world, but it does not work. If the arrow disappear, appear again all the yellow dots.
Thanks for your cooperation, Massimo.
//Indicator Buffer 3
      if(iDeMarker(NULL,PERIOD_CURRENT,4,i)==0 //DeMarker is equal to fixed value
         && iDeMarker(NULL,PERIOD_CURRENT,4,1+i)!=0 //DeMarker is not equal to fixed value
         )
        {
         Buffer3[i]=Low[i]-iATR(NULL,PERIOD_CURRENT,14,i); //Set indicator value at Candlestick Low - Average True Range
        SetIndexStyle(0,DRAW_ARROW,EMPTY,1,clrNONE);
        //SetIndexStyle(1,DRAW_ARROW,EMPTY,1,clrNONE);

        }
      else
        {
         Buffer3[i]=0;
         SetIndexStyle(0,DRAW_ARROW,EMPTY,1,clrYellow);
         //SetIndexStyle(1,DRAW_ARROW,EMPTY,1,clrYellow);
Vasyl Nosal
18545
Vasyl Nosal 2016.03.20 01:09  
I have atached ready file. Is it ok?
Massimo
479
Massimo 2016.03.20 07:41  
eevviill:
I have atached ready file. Is it ok?
Hello eevviill. In the file you sent me, you have taken away the buffer 1/2 which are the pre-alert.
Instead, the pre alert should appear and must disappear when the alert appears.
The pre alert are the yellow dots. When I see the yellow dot I prepare for entry and I wait to appear the arrow. If I see the arrow , I enter otherwise expect another occasion. When the red or green arrow appear,  I would like the yellow dots were deleted, leaving the cleanest look.
Thanks for everything, Massimo.
12
To add comments, please log in or register