Buy and Sell Alert for a specific candle

 

Hi. The buy signal alert works properly for the following code (Alert is displayed when the candle is closed), but does not work for the sell signal. Can anyone solve the problem?


//+-------------------------------------------n-----------------------+
//|                        MAB_TD_Sequential                         |
//|                              v1.2                                |
//|                                                                  |
//|   Indicator based off of Tom DeMarks' TD Sequential indicator as |
//|   described in Jason Perl's book "DeMark Indicators"             |
//|                                                                  |
//|   05/22/2009 - Created Buy and Sell Setup along with TDST lines  |
//|               and set up criteria for arrow and alert to appear  |
//|               for a perfect setup.                               |
//|      issues:  TDST line starts updating before a full setup is   |
//|               made                                               |
//|      still needs:  Countdown criteria                            |
//|                                                                  |
//|   05/26/2009 - Added the Countdown criteria.  Countdown will also|
//|               create a "+" when 13 is reach but not perfected.   |
//|      still needs:  Countdown recycle criteria(currently recycles |
//|                  automatically when setup completed)             |   
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Black

extern color Setup=Black;
extern color Countdown=Black;

extern int NumBars=1000;
extern int Space=50;    //space above or below high to place number

extern bool Alerts=false;

double Support[], Resistance[], bPerfected[], sPerfected[], Buy[], Sell[];
datetime last_alert = 0;

#define SIGNAL_BAR 2
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   //TDST lines
   SetIndexBuffer(0,Support);
   SetIndexStyle(0,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1,Resistance);
   SetIndexStyle(1,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   
   //Perfected Setup
   SetIndexBuffer(2,bPerfected);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,217);
   SetIndexBuffer(3,sPerfected);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,218);
   
   //Countdown
   SetIndexBuffer(4,Buy);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,217);
   SetIndexBuffer(5,Sell);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,218);
//----
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  for(int i=0;i<Bars;i++) 
  {
  ObjectDelete(""+i); 
  ObjectDelete("cd"+i);
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int counted_bars=IndicatorCounted();
   int bSetup, sSetup, bCountdown, sCountdown;
   int x;
   double tfm=Space*Point;
   bool bSetupInd, sSetupInd;
//----
   for(int i=NumBars; i>=0; i--)
      {
      ObjectDelete(""+i);
      ObjectDelete("cd"+i);
//+------------------------------------------------------------------+
//| Buy Setup                                                        |
//+------------------------------------------------------------------+
      if(Close[i]<=Close[i+4] && Close[i+1]>=Close[i+5] && bSetup==0)//start setup
         {  
         bSetup++;
//         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
//         ObjectSetText(""+i,""+bSetup,8,"Arial",Setup);
         }
      if(Close[i]<Close[i+4] && bSetup!=0 && ObjectFind(""+i)==-1) 
         {
         bSetup++;
         if(bSetup==5)
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
            ObjectSetText(""+i,9,10,"Arial Black",Blue); 
            bSetup=0;
            bPerfected [i]=Low[i]-(WindowPriceMax()-WindowPriceMin() )/20; 
            bSetupInd=true;
            sSetupInd=false;
            sCountdown=0;     

            } 
                  
         }
 
 
       
      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]>=Close[i+4] && bSetup!=0) 
         {
         for(x=i+1; x<=i+bSetup-1; x++) ObjectDelete(""+x);
         bSetup=0; 
         }

//+------------------------------------------------------------------+
//| Sell Setup                                                       |
//+------------------------------------------------------------------+
      if(Close[i]>=Close[i+4] && Close[i+1]<=Close[i+5] && bSetup==0)//start setup
         {  
         sSetup++;
//         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+tfm);
//         ObjectSetText(""+i,""+sSetup,8,"Arial",Setup);
         }
      if(Close[i]>=Close[i+4] && sSetup!=0) //&& ObjectFind(""+i)==-1) 
         {
         sSetup++;
         if(sSetup==5) 
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+(WindowPriceMax()-WindowPriceMin() )/20);//+tfm);
            ObjectSetText(""+i,9,10,"Arial Black",Red);
            sSetup=0;
            sPerfected [i]=High[i]+(WindowPriceMax()-WindowPriceMin())/20;
            sSetupInd=true;
            bSetupInd=false;
            bCountdown=0;
          
            }
              
         }


      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]<=Close[i+4] && sSetup!=0) 
         {
         for(x=i+1; x<=i+sSetup-1; x++) ObjectDelete(""+x);
         sSetup=0; 
         }
      }
//----

          static int PrevSignal = 0, PrevTime = 0;

          if(SIGNAL_BAR > 0 && Time[0] <= PrevTime ) 
              return(0);        

          PrevTime = Time[0];

          if(PrevSignal <= 0)
            {
            
/////////Buy Alert ////////////
//////////////////////////////

                     if(Close[SIGNAL_BAR-1] - bPerfected[SIGNAL_BAR-1] > 0)
                       {
                                PrevSignal = 1;
                                Alert("", Symbol(), ", ", Period(), "  -  BUY!!!");
                       }
            }
            
///////////Sell Alert///////////
///////////////////////////////

   if(PrevSignal >= 0)
     {


       if(sPerfected[SIGNAL_BAR] - Close[SIGNAL_BAR] < 0)
         {
                  PrevSignal = -1;
                  Alert("", Symbol(), ", ", Period(), "  -  SELL!!!");
         }
     }




   return(0);
  
   };
//+------------------------------------------------------------------+
 
afshin amirii:

Hi. The buy signal alert works properly for the following code (Alert is displayed when the candle is closed), but does not work for the sell signal. Can anyone solve the problem?


Ok.

//+-------------------------------------------n-----------------------+
//|                        MAB_TD_Sequential                         |
//|                              v1.2                                |
//|                                                                  |
//|   Indicator based off of Tom DeMarks' TD Sequential indicator as |
//|   described in Jason Perl's book "DeMark Indicators"             |
//|                                                                  |
//|   05/22/2009 - Created Buy and Sell Setup along with TDST lines  |
//|               and set up criteria for arrow and alert to appear  |
//|               for a perfect setup.                               |
//|      issues:  TDST line starts updating before a full setup is   |
//|               made                                               |
//|      still needs:  Countdown criteria                            |
//|                                                                  |
//|   05/26/2009 - Added the Countdown criteria.  Countdown will also|
//|               create a "+" when 13 is reach but not perfected.   |
//|      still needs:  Countdown recycle criteria(currently recycles |
//|                  automatically when setup completed)             |   
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Black

extern color Setup=Black;
extern color Countdown=Black;

extern int NumBars=1000;
extern int Space=50;    //space above or below high to place number

extern bool Alerts=false;

double Support[], Resistance[], bPerfected[], sPerfected[], Buy[], Sell[];
datetime last_alert = 0;

#define SIGNAL_BAR 2
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   //TDST lines
   SetIndexBuffer(0,Support);
   SetIndexStyle(0,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1,Resistance);
   SetIndexStyle(1,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   
   //Perfected Setup
   SetIndexBuffer(2,bPerfected);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,217);
   SetIndexBuffer(3,sPerfected);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,218);
   
   //Countdown
   SetIndexBuffer(4,Buy);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,217);
   SetIndexBuffer(5,Sell);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,218);
//----
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  for(int i=0;i<Bars;i++) 
  {
  ObjectDelete(""+i); 
  ObjectDelete("cd"+i);
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int counted_bars=IndicatorCounted();
   int bSetup, sSetup, bCountdown, sCountdown;
   int x;
   double tfm=Space*Point;
   bool bSetupInd, sSetupInd;
//----
   for(int i=NumBars; i>=0; i--)
      {
      ObjectDelete(""+i);
      ObjectDelete("cd"+i);
//+------------------------------------------------------------------+
//| Buy Setup                                                        |
//+------------------------------------------------------------------+
      if(Close[i]<=Close[i+4] && Close[i+1]>=Close[i+5] && bSetup==0)//start setup
         {  
         bSetup++;
//         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
//         ObjectSetText(""+i,""+bSetup,8,"Arial",Setup);
         }
      if(Close[i]<Close[i+4] && bSetup!=0 && ObjectFind(""+i)==-1) 
         {
         bSetup++;
         if(bSetup==5)
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
            ObjectSetText(""+i,9,10,"Arial Black",Blue); 
            bSetup=0;
            bPerfected [i]=Low[i]-(WindowPriceMax()-WindowPriceMin() )/20; 
            bSetupInd=true;
            sSetupInd=false;
            sCountdown=0;     

            } 
                  
         }
 
 
       
      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]>=Close[i+4] && bSetup!=0) 
         {
         for(x=i+1; x<=i+bSetup-1; x++) ObjectDelete(""+x);
         bSetup=0; 
         }

//+------------------------------------------------------------------+
//| Sell Setup                                                       |
//+------------------------------------------------------------------+
      if(Close[i]>=Close[i+4] && Close[i+1]<=Close[i+5] && bSetup==0)//start setup
         {  
         sSetup++;
//         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+tfm);
//         ObjectSetText(""+i,""+sSetup,8,"Arial",Setup);
         }
      if(Close[i]>=Close[i+4] && sSetup!=0) //&& ObjectFind(""+i)==-1) 
         {
         sSetup++;
         if(sSetup==5) 
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+(WindowPriceMax()-WindowPriceMin() )/20);//+tfm);
            ObjectSetText(""+i,9,10,"Arial Black",Red);
            sSetup=0;
            sPerfected [i]=High[i]+(WindowPriceMax()-WindowPriceMin())/20;
            sSetupInd=true;
            bSetupInd=false;
            bCountdown=0;
          
            }
              
         }


      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]<=Close[i+4] && sSetup!=0) 
         {
         for(x=i+1; x<=i+sSetup-1; x++) ObjectDelete(""+x);
         sSetup=0; 
         }
      }
//----
//


//Print( bPerfected[SIGNAL_BAR-1]," ",sPerfected[SIGNAL_BAR]);

          static int PrevSignal = 0, PrevTime = 0;

          if(SIGNAL_BAR > 0 && Time[0] <= PrevTime ) 
              return(0);        

          PrevTime = Time[0];

          if(PrevSignal <= 0)
            {
            
/////////Buy Alert ////////////
//////////////////////////////

                     if(bPerfected[SIGNAL_BAR] > 0 && bPerfected[SIGNAL_BAR]!=2147483647)

                       {
                                PrevSignal = 1;
                                Alert("", Symbol(), ", ", Period(), "  -  BUY!!!");
                       }
            }
            
///////////Sell Alert///////////
///////////////////////////////

   if(PrevSignal >= 0)
     {


       if(sPerfected[SIGNAL_BAR]>0 &&  sPerfected[SIGNAL_BAR]!=2147483647)
         {
                  PrevSignal = -1;
                  Alert("", Symbol(), ", ", Period(), "  -  SELL!!!");
         }
     }




   return(0);
  
   };
//+------------------------------------------------------------------+



aa

 
Mehmet Bastem #:

Ok.





Thank you, it works well.

I have another problem, I want to have signals with alert when sSetup or bSetup equel to 5, 11, 13 and 15. What should I do?

Reason: