Candle body size

 

Hi

I have been trying to put together a simple alert that will do the following:

Place an UP arrow under a candle that has met a set of criteria (e.g., Close[1] - Open[1] > 10 points)

Place a DOWN arrow above a candle that has met a set of criteria (e.g., Open[1] - Close[1] > 10 points)

The arrows should also be placed for past candle sizes (but no emails).

The points should be a volatile input meaning I can specify the amount depending on the chart I attach it too.

Alert is based on the last completed candle (i.e., ignores the current candle even it the condition is satisfied). This is to avoid having multiple alerts for the same candle.

When alert is triggered, an email is sent along with a message advising of the currency pair and if it is a buy or sell (if possible, a chart).

 

Would appreciate if someone can complete correct code for me.

Thanks

//+------------------------------------------------------------------+
//|                                                Candle size 2.mq4 |
//|                                                            Tex   |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Tex"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict



//****************************************************
//---- indicator parameters

extern double Range=0.0010;

double Bull[],
       Bear[];
//***************************************************


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

   SetIndexStyle(0,DRAW_ARROW,EMPTY);
   SetIndexArrow(0,225);
   SetIndexBuffer(0,Bull);

   SetIndexStyle(1,DRAW_ARROW,EMPTY);
   SetIndexArrow(1,226);
   SetIndexBuffer(1,Bear);

   return(0);

//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
   
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   int counted_bars=IndicatorCounted();
   int i;
   int limit;
   if(counted_bars<0)
      if(counted_bars>0)
         counted_bars--;
   limit= Bars-counted_bars;
   for(i=0; i<=limit; i++)


      if(Close[i+1]>Open[i+1]+Range
         )

        {Bull[i]=Low[i]-0.0005;}

   if(Close[i+1]<Open[i+1]-Range
      )

     {Bear[i]=High[i]+0.0005;}


 //***************************************************     
 //*** Sends the e-mail
//----------------------------

static datetime Close_Time;
static bool mail_flag_up=true;
static bool mail_flag_dn=true;


if (  mail_flag_up  &&     // This line is for sending an e-mail at the first occurence
      Close_Time != Time[0]   &&
      Close[i+1] > Open[i+1] + Range
    )  
    
  
    
 /*                     
      {  SendMail("L/-" + Symbol(), "Buy" + Symbol() + Period() );
         //SendMail("LONG", "test" );
         Close_Time = Time[0]; 
    //   mail_flag_up=false;  This line is for sending an e-mail at the first occurence
    //   mail_flag_dn=true;   This line is for sending an e-mail at the first occurence
      }

*/


if (  mail_flag_dn  &&      //  This line is for sending an e-mail at the first occurence
      Close_Time != Time[0]  &&
      Close[i+1] < Open[i+1] - Range    
   
    )


 /*           
      { SendMail("S\-" + Symbol(), "Sell" + Symbol() + Period()  );
         //SendMail("SHORT", "test" );
         Close_Time = Time[0];
    //   mail_flag_dn=false;  This line is for sending an e-mail at the first occurence
    //   mail_flag_up=true;   This line is for sending an e-mail at the first occurence
      }

*/




return();

}
  
//+------------------------------------------------------------------+



 
#property strict

   int counted_bars=IndicatorCounted();
   int i;
   int limit;
   if(counted_bars<0)
      if(counted_bars>0)
         counted_bars--;
   limit= Bars-counted_bars;
   for(i=0; i<=limit; i++)
      if(Close[i+1]>Open[i+1]+Range
  1. When counted is zero, i becomes Bars, and you have an array bounds error. This you should have seen in the log.
  2. No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forum
  3. Do your lookbacks correctly.
 
texcan:

      if(Close[i+1]>Open[i+1]+Range
         )

        {Bull[i]=Low[i]-0.0005;}

   if(Close[i+1]<Open[i+1]-Range
      )

     {Bear[i]=High[i]+0.0005;}



try this

Bull[i]=Low[i]-iATR(NULL,0,20,i)/2;

Bear[i]=High[i]+iATR(NULL,0,20,i)/2;


thx.

<Links  removed>
Reason: