Just one arrow per condition.

 
Hello every one, i am modifying an existing indicator according my way of trading.
And i want the arrow (in fact point) drawn just one time, not on each candle until the next reversal signal.

Can anyone help me ?
Regards.

Here is the code

//+------------------------------------------------------------------+
//|                                                  rsi extreme.mq4 |
//|                                  Original Author: LordoftheMoney |
//|                                Expert advisor is in the codebase |
//|                                                    (Easiest RSI) |
//|                                            Modified by MadaForex |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 0
#property indicator_width2 0
#property indicator_color1 White
#property indicator_color2 Black
extern int rsiperiod = 21;
extern int rsiperiod2 = 8;
extern int rsiperiod3 = 4;
double buffy1[];
double buffy2[];
int cb=0;
int bar;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int  draw;
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"buy");
   SetIndexLabel(1,"sell");
   SetIndexDrawBegin(0,draw);
   SetIndexDrawBegin(1,draw);
   SetIndexBuffer(0,buffy1);
   SetIndexBuffer(1,buffy2);
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0,OBJ_ARROW);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   if (bar==Time[0]) return(0);
   int cb=IndicatorCounted();
   int x;
   if(Bars<=100) return(0);
   if (cb<0) return(-1);
   if (cb>0) cb--;
   x=Bars-cb;
   for(int i=0; i<x; i++)
   {
    double r1a = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i);
    double r1b = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i+1);
    double r2a = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i);
    double r2b = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i+1);
    double r3a = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i);
    double r3b = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i+1);
     if (r1a>50 && r2a>50 && r3a>50)
      buffy1[i] = Low[i+1]-15*Point;
     bar=Time[0];
     if (r1a<50  && r2a<50 && r3a<50)
      buffy2[i] = High[i+1]+15*Point;
     bar=Time[0];
   }

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

First of all, I see that you put

   SetIndexEmptyValue(0,0.0);

in init. Why do you do that? If you are defining EmptyValue as zero for buffer0, why not for buffer1?

The following code is not tested or compiled.

I think that you should consider further changes, so that you only check values for closed bars.

Also, you delete all arrows in deinit. This code does not create objects, the arrows are drawn by the buffers.

   SetIndexEmptyValue(0,0.0);

   SetIndexEmptyValue(1,0.0);
if(bar==Time[0]) return(0);
   int cb=IndicatorCounted();
   int x;
   if(Bars<=100) return(0);
   if(cb<0) return(-1);
   if(cb>0) cb--;
   x=Bars-cb;
   if(x>Bars-2)
     x=Bars-2;
   for(int i=x; i>=0; i--)   // CHANGE LOOP TO COUNT DOWN
     {
      double r1a = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i);
      double r1b = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i+1);
      double r2a = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i);
      double r2b = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i+1);
      double r3a = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i);
      double r3b = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i+1);
      if(r1a>50 && r2a>50 && r3a>50 && buffy1[i+1]==0.0)
         {
         buffy1[i]=Low[i+1]-15*Point;
         bar=Time[0];
         } 
      if(r1a<50 && r2a<50 && r3a<50 && buffy2[i+1]==0.0)
         {
         buffy2[i]=High[i+1]+15*Point;
         bar=Time[0];
         }
     }
 
Hello GumRai,
Thank you for your help.

I am not a programmer. I have just modified existing source that i found on internet for my purpose.
Anyway, i tried your code but all dots disappear. There was no signal at all anymore.

Have you another suggestion ?

Regards.
 

Here is my original code for that indicator,  :

int start()
  {
    static bool trend_buy; static bool trend_sell;
    static bool arrow_buy = false; static bool  arrow_sell = false; 
    //static datetime  bar;
   int  x = -1;
   int  cb = IndicatorCounted();
   if( cb<0 ) return(-1);
   if( cb > 0 )  cb--;
    x = Bars - cb;
//---- macd counted in the 1-st additional buffer
   for(int i=x; i>=0; i--)   
    {
    double r1a = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i);
    double r1b = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i+1);
    double r2a = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i);
    double r2b = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i+1);
    double r3a = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i);
    double r3b = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i+1);
   
 //============================================================================
    if(trend_buy == false && arrow_buy == false &&  r1a>50 && r2a>50 && r3a>50)
    
     { trend_buy = true; trend_sell = false; arrow_buy = true;  } 
    else                                     arrow_buy = false;
   
    if( trend_sell == false && arrow_sell == false && r1a<50  && r2a<50 && r3a<50 )  
    { trend_sell = true;  trend_buy = false; arrow_sell = true; }
      else                                   arrow_sell = false;

 //=================== ARROW ============================================  
  
    if(  arrow_buy == true )  buy[i] =  Close[i]-5*Point; 
    else                      buy[i] = 0.0;
  
    if( arrow_sell == true )   sell[i] = Close[i]+5*Point;
    else                       sell[i] = 0.0;        
  
  //=================== TREND ===========================================
   
    static bool up =0; static bool down = 0;
    if( r1a>50 && r2a>50 && r3a>50 )  { up = 1; down = 0;}
    if( r1a<50 && r2a<50 && r3a<50 )  { up = 0; down = 1;}
  
    if( up == true ) { buy_trend[i] = iMA(NULL,0,5,0,2,4,i);     }    
    else               buy_trend[i] = 0.0;     
  
     if( down == true ) { sell_trend[i] = iMA(NULL,0,5,0,2,4,i);   }
    else                  sell_trend[i] = 0.0;     
   
  // i--;
   }
   return(0);
  }
//+-------------------------------------------------------


It"s not  easy to code that kind of indicator.

The indicator is sometime very good, sometime bad. One will have to deal with the false signals, if someone know how to do that, let me know.

two buffer line show the trend, and two buffer arrow for the beginning of the trend. Good trades.



Files:
 
1st of all, thank you very to you ffoorr.
It's exactly what i desired.

For the strategy, i am working on it, and will share you when i will be satisfied bout it.
6 month of very very very serious research for trading with RSI stochastic and MACD...I think i am near of my goal.

Again thank you for your help.

NB : Eventually, if you can add an alert.

Regards.
 
In fact, It didn't work properly.
When all rsi cross the level, the dot disappear and re-appear 1 or 2 candle after, on the good candle, but lately.
 

hello MadaForex,

The indicator work properly, it is coded on the Zero bar :

 double r1a = iRSI(NULL,0,rsiperiod,PRICE_WEIGHTED,i);   
    double r2a = iRSI(NULL,0,rsiperiod2,PRICE_WEIGHTED,i);   
    double r3a = iRSI(NULL,0,rsiperiod3,PRICE_WEIGHTED,i);
 //============================================================================
    if(trend_buy == false && arrow_buy == false &&  r1a>50 && r2a>50 && r3a>50)


So one has to wait for bar 1 to have the confirmation of the signal, the arrow can disapear on bar 0.

In an EA one has to look for signal on bar 1 to avoid false signal.

It work, I tested it.


I know nothing about alert, but just add a line just before the end of the program, to alert on bar 1

 if( buy[i+1] != 0.0  )  Alert("buy") ; // or    PlaySound("Ok.wav");

 if( sell[i+1] != 0.0  )  Alert("sell") ;

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

 
Here you can see what i mean.
Close candle and all conditions gathered, but no signal.

 
Hello,
I have redone another.
I'ts on chart's bars.

I am looking now to filter signals.
Regards.