Signal after candle close

 

Guys, how do I make sure that the signal is only given at the closing of the candle and not during the candle? What should I change in my code?


static datetime timeLastAlert = NULL;
   
   for (i=limit; i>=0; i--) 
   for (i=limit; i>=0; i--) 


if( buffer1[i] > buffer3[i] && buffer1[i+1] >= buffer3[i+1]  )
      { UP[i] = High[i] ; }
   
      
      
      if( buffer1[i] < buffer4[i] && buffer1[i+1] <= buffer4[i+1]  )
      { DOWN[i] = Low[i] ; }
      
 

if(NewBar())

{

}

bool NewBar()
  {
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
 
Mehmet Bastem:

if(NewBar())

{

}

hi, it worked, thank you very much, but how do I make the indicator appear tb the signal history?


thx

 
Guilherme Guimaraes:

hi, it worked, thank you very much, but how do I make the indicator appear tb the signal history?


thx

appear tb the signal history"

What does that mean?

 
Keith Watford:

appear tb the signal history"

What does that mean?

Sorry,


hi, it worked, thank you very much, but how do I make the indicator also show the signal history?



 
Guilherme Guimaraes:

Hi, it worked, thank you very much, but how do I make the indicator also show the signal history?

Show your code and somebody may be able to help you.

In the code that you have posted

   for (i=limit; i>=0; i--)                                             // Why have you repeated this line????
   for (i=limit; i>=0; i--) 


if( buffer1[i] > buffer3[i] && buffer1[i+1] >= buffer3[i+1]  )          //This is executed in the loop
      { UP[i] = High[i] ; }
   
      
      
      if( buffer1[i] < buffer4[i] && buffer1[i+1] <= buffer4[i+1]  )    //This isn't!
      { DOWN[i] = Low[i] ; }

WE don't know what value is assigned to limit, buffer1, buffer3 or buffer4.

 

//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Orange
#property indicator_color2 DarkGray
#property indicator_color3 Orange
#property indicator_color4 LimeGreen
#property indicator_color5 Red
#property indicator_color6 LimeGreen
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT



//
//
//
//
//

extern int    RsiLength  = 9;
extern int    RsiPrice   = PRICE_CLOSE;
extern int    HalfLength = 5;
extern int    DevPeriod  = 100;
extern double Deviations = 1.0;
extern bool   UseAlert   = true;
extern bool   DrawArrows = true;


input int  CountBars = 0; // CountBars - number of bars to count on, 0 = all.
int LastBars = 0;

bool NewBar()

{

static datetime lastbar;

datetime curbar = Time[0];

if(lastbar!=curbar)

{

lastbar=curbar;

return (true);

}

else

{

return(false);

}

}


double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double Arriba[];
double Abajo[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int init()
{
   HalfLength=MathMax(HalfLength,1);
         SetIndexBuffer(0,buffer1); 
         SetIndexBuffer(1,buffer2);
         SetIndexBuffer(2,buffer3); 
         SetIndexBuffer(3,buffer4);
         
         SetIndexBuffer(4,Arriba);
         SetIndexStyle(4,DRAW_ARROW);
         SetIndexArrow(4,234);
         SetIndexEmptyValue(4,0.0);
         SetIndexLabel(4,"Flecha Arriba");
         SetIndexBuffer(5,Abajo);
         SetIndexStyle(5,DRAW_ARROW);
         SetIndexArrow(5,233);
         SetIndexEmptyValue(5,0.0);
         SetIndexLabel(5,"Flecha Abajo");
         
         
   return(0);
}
int deinit() 
{
 /* DellObj(PrefixArrow);*/
  
 return(0); 
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start() {

// // // // //
 int i,j,k=IndicatorCounted();
 
  
 int NeedBarsCounted;
  
   if (LastBars == Bars) return(0);
   NeedBarsCounted = Bars - LastBars;
   if ((CountBars > 0) && (NeedBarsCounted > CountBars)) NeedBarsCounted = CountBars;
   LastBars = Bars;
   if (NeedBarsCounted == Bars) NeedBarsCounted--;
 // // // // //
 
 

 

   //
   //
   //
   //
   //
   Arriba[i]=0;
   Abajo[i]=0;
   
   static datetime timeLastAlert = NULL;
   
 // // // // // //
   for (i=NeedBarsCounted; i>=0; i--) buffer1[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
   for (i=NeedBarsCounted; i>=0; i--)
    // // // // // // // // //
   {
      double dev  = iStdDevOnArray(buffer1,0,DevPeriod,0,MODE_SMA,i);
      double sum  = (HalfLength+1)*buffer1[i];
      double sumw = (HalfLength+1);
      for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
      {
         sum  += k*buffer1[i+j];
         sumw += k;
         if (j<=i)
         {
            sum  += k*buffer1[i-j];
            sumw += k;
         }
      }
      buffer2[i] = sum/sumw;
      buffer3[i] = buffer2[i]+dev*Deviations;
      buffer4[i] = buffer2[i]-dev*Deviations;
  
  //Parte que envia señal    
  
      if( buffer1[i] > buffer3[i] && buffer1[i+1] < buffer3[i+1] /*&& NewBar() /*&& buffer1[i] < 50*/)
      { Arriba[i] = buffer3[i] ; }
      {  /*if( DrawArrows ) ArrowDn(Time[i], High[i]);*/  }
      
      
      if( buffer1[i] < buffer4[i] && buffer1[i+1] > buffer4[i+1] /*&& NewBar() /*&& buffer1[i] < 50*/)
      { Abajo[i] = buffer4[i] ; }
      { /* if( DrawArrows ) ArrowUp(Time[i], Low[i]);*/}
      
      
      //Parte que envia señal    
      if( buffer1[i] > buffer3[i] /*&& buffer1[i+1] < buffer3[i+1]*/ )
      { 
         
         
         if( UseAlert && i == 0 && Time[0] != timeLastAlert )
         {
            Alert(Symbol(),"  M",Period()," Posible Venta");
            
            timeLastAlert = Time[0];
         }
      }
      
      if( buffer1[i] < buffer4[i] /*&& buffer1[i+1] > buffer4[i+1] */)
      { 
         

         if( UseAlert && i == 0 && Time[0] != timeLastAlert )
         {
            Alert(Symbol(),"  M",Period()," Posible Compra");
            timeLastAlert = Time[0];
         }         
      }
   }
   return(0);
}

Reason: