My indicator doesn't work

To add comments, please log in or register
[Deleted]  
hello,

I joined this forum because I need your help.
I tried to write a code but it does not work well.

The problem: the indicator does not work anymore after taking the signals (buy, sell).
I do not know where I made ​​the mistake.

Can you help me?

my code:

int a=0;
int b=0;

//-----------CYCLE---------------

for(int i=0;i<limit;i++) {
  
     
      if ( sig_buy == 1 && a !=1) { //A single buy signal
      buff1[i] = Low[i+1];
      a = 1; 
      }
      
      if ( sig_sell == 1 && b !=1) { //A single sell signal
      buff2[i] = High[i+1]; 
      b = 1;
      }
     
  } 


   
   return(0);
  }
//+------------------------------------------------------------------+
William Roeder
22674
William Roeder  

Once you set a=1 or b=1 are they ever set back to zero?

you really shouldn't be using an int b!=1 b=1, you should be using bool b=true;

next time post all the code. we have no idea where you set a=0 or what limit is.

[Deleted]  
Hello thank you for your reply.
I set a = 0 and b = 0 at the beginning of the code.
I wrote this code because I had too many signals (an arrow on all the candles).

I'll try with "bool" and I'll post all the code

thank you very much
[Deleted]  
I inserted "bool" in my code, but I do not know if I wrote it correctly.

I made a screenshot (too many signals).



my code:


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2

//--- input parameters

extern int       barsToProcess=1000;

//--- buffers
double buff1[];
double buff2[];




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
    IndicatorBuffers(2); 
     
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,225);
   SetIndexBuffer(0,buff1);
   SetIndexEmptyValue(0,0.0);
   
   
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,226);
   SetIndexBuffer(1,buff2);
   SetIndexEmptyValue(1,0.0);
   
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   bool a = false;
   int    limit;
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
        double Var1 = iCustom(NULL, 0, "BTrendv1", 20,3, 0, 0); //up
        double Var2 = iCustom(NULL, 0, "Btrendv1", 20,3, 1, 0); //down
        double Var3 = iCustom(NULL, 0, "Sonar", 9,30, 0, 0);
        double Var4 = iCustom(NULL, 0, "Damiani_volatmeter", 13,20,40,100,1.4,TRUE,2000,0,0); //down
        double Var5 = iCustom(NULL, 0, "Damiani_volatmeter", 13,20,40,100,1.4,TRUE,2000,2,0);//up
        double Var6 = iCCI(NULL,0,14,PRICE_TYPICAL,0);
                     
        double sig_buy = Var2>Var1 && Var3>Var2 && (Var5>Var4 && Var6>0);
        double sig_sell = Var2<Var1 && Var3<Var2 && (Var5>Var4 && Var6<0);
        
 // ---------------------------------------------------------------------       
    
      for(int i=0;i<limit;i++) {
  
       
       if ( sig_buy == true) {
      buff1[i] = Low[i+1] - 25*Point;
      a = true;
       
      }
      
      if ( sig_sell == true) {
      buff2[i] = High[i+1] + 25*Point; 
      a = true;
      }
      
  } 


   
   return(0);
  }
//+------------------------------------------------------------------+
Simon Gniadkowski
17279
Simon Gniadkowski  
So you only want to show the arrow when it changes from up to down or down to up ? You need to remember its current state and only set a value for buff1[i] and buiff2[i] when the state changes. So use a = true for buff1 and a = false for buff2 . . . then check the value of a before you set the buff1 value, if ( sig_buy == true && !a) and visa versa for buff2 . . . . give it a go, if you need more help ask . .
[Deleted]  
RaptorUK:
So you only want to show the arrow when it changes from up to down or down to up ? You need to remember its current state and only set a value for buff1[i] and buiff2[i] when the state changes. So use a = true for buff1 and a = false for buff2 . . . then check the value of a before you set the buff1 value, if ( sig_buy == true && !a) and visa versa for buff2 . . . . give it a go, if you need more help ask . .

I love you RaptorUK thank you very much!!!
William Roeder
22674
William Roeder  
Why isn't a=0 INSIDE the loop?
To add comments, please log in or register