problem with my indicator work correctly but there is a problem with signal in live

 

Hello,,

this is the first time I post a topic here and hope to find solve to my problem

 the problem is the indicator work correctly when attach it to the chart but when the price go there is a repainting in the signals and some signals disappear (but when reattach the indicator it appear!!)

 

the idea of the indicator :

there is a lot of conditions,, it will give signal of them but if there is any condition of it has a false signal it will not give any signal.

 

hope you will help me

 

the code of the indicator

 

//+------------------------------------------------------------------+
//|                                                 grandesmiles.mq4 |
//|                                     Copyright 09/05/2013, ElSakr |
//|                                           sakr_amr2010@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 09/05/2013, ElSakr"
#property link      "sakr_amr2010@yahoo.com"

#property indicator_chart_window
#property  indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 4
#property indicator_width2 4
#property indicator_color2 Red
#property indicator_color3 Gray
double up[];
double down[];
extern bool TMA1_IchimokuCloud = true;
extern int CrossPips = 10;
extern bool Use_Stoc = true;
extern double High_Level_Stoc = 80;
extern double Low_Level_Stoc =20;
extern bool Price_Close_TMA5 = false;
extern int TMA5_Dif_Pip = 10;
extern bool Use_Babon_Slope = false;
extern bool highest_lowest = false;
extern int bars_for_highest_lowest = 100;
extern bool alert = true;
extern string filename = "ok.wav";
extern string inputs_indicator = "inputs for used indicators";
extern string note = "------------------------------------------------------------";
extern string TmaTrue1 = "inputs for TmaTrue1 indicator";
extern int eintTimeFrame = 1;
extern int eintHalfLength = 20;
extern double edblAtrMultiplier = 2;
extern int eintAtrPeriod = 100;
extern string note1 = "------------------------------------------------------------";
extern string Ichimoku = "inputs for Ichimoku indicator";
extern int tenkan_sen = 9;
extern int kijun_sen = 26;
extern int senkou_span_b = 52;
extern string note2 = "------------------------------------------------------------";
extern string IMA100 = "inputs for Moving average 100 indicator";
extern int period = 100;
extern int ma_shift = 0;
extern int ma_method = 3;
extern int applied_price = 0;
extern string note3 = "------------------------------------------------------------";
extern string stoc = "inputs for Stochastic oscillator indicator";
extern int Kperiod = 5;
extern int Dperiod = 3;
extern int slowing = 3;
extern int method = 0;
extern int price_field =0;
extern string note4 = "------------------------------------------------------------";
extern string TmaTrue5 = "inputs for TmaTrue5 indicator";
extern int eintTimeFrame5 = 5;
extern int eintHalfLength5 = 20;
extern double edblAtrMultiplier5 = 2;
extern int eintAtrPeriod5 = 100;
extern string note5 = "------------------------------------------------------------";
extern string BabonSlope = "inputs for Babon+Slope+ indicator";
extern int BabonPeriod = 10;
extern int BabonMethod = 3;
extern int BabonPrice =0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexBuffer(0, up);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexBuffer(1, down);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
bool NewBar()
{
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
}  
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=limit; i>=0; i--)
     {
      double upper = Low[i] - (10*Point);
      double lower = High[i] + (10*Point);
      if(TMA1_IchimokuCloud==true){
      double tma1trueupper = iCustom(NULL,0,"TmaTrue",eintTimeFrame,eintHalfLength,edblAtrMultiplier,eintAtrPeriod,limit+10,1,i);
      double tma1truelower = iCustom(NULL,0,"TmaTrue",eintTimeFrame,eintHalfLength,edblAtrMultiplier,eintAtrPeriod,limit+10,2,i);
      double ichimocupper = iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,3,i);
      double ichimoclower = iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,4,i);
         if (tma1trueupper-(CrossPips*Point)>ichimocupper && tma1truelower-(CrossPips*Point)>ichimocupper && tma1truelower-(CrossPips*Point)>ichimoclower && tma1trueupper-(CrossPips*Point)>ichimoclower){
            if(up[i]!=EMPTY && down[i]!=lower){
            up[i] = upper;
            down[i] = EMPTY;
            }
            if(down[i]==lower){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else if (tma1trueupper+(CrossPips*Point)<ichimocupper && tma1truelower+(CrossPips*Point)<ichimocupper && tma1truelower+(CrossPips*Point)<ichimoclower && tma1trueupper+(CrossPips*Point)<ichimoclower){
            if(down[i]!=EMPTY && up[i]!=upper){
            down[i] = lower;
            up[i] = EMPTY;
            }
            if(up[i]==upper){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else {
         up[i] = EMPTY;
         down[i] = EMPTY;
         }
      }
      if(Use_Stoc==true){
      double stoc = iStochastic(NULL,0,Kperiod,Dperiod,slowing,method,price_field,0,i);
      double stocprev = iStochastic(NULL,0,Kperiod,Dperiod,slowing,method,price_field,0,i-1);
      double stocafter = iStochastic(NULL,0,Kperiod,Dperiod,slowing,method,price_field,0,i+1);
         if(stoc>High_Level_Stoc && stocprev<stoc && stocafter<stoc){
            if(down[i]!=EMPTY && up[i]!=upper){
            down[i] = lower;
            up[i] = EMPTY;
            }
            if(up[i]==upper){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else if(stoc<Low_Level_Stoc && stocprev>stoc && stocafter>stoc){
            if(up[i]!=EMPTY && down[i]!=lower){
            up[i] = upper;
            down[i] = EMPTY;
            }
            if(down[i]==lower){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else {
         up[i] = EMPTY;
         down[i] = EMPTY;
         }
      }
      if(Price_Close_TMA5==true){
      double tma5truecenter = iCustom(NULL,0,"TmaTrue",eintTimeFrame5,eintHalfLength5,edblAtrMultiplier5,eintAtrPeriod5,limit+10,0,i);
      double close = iClose(NULL,0,i);
         if(MathAbs(tma5truecenter-close)<=MathAbs(TMA5_Dif_Pip*Point) && close>tma5truecenter){
            if(up[i]!=EMPTY && down[i]!=lower){
            up[i] = upper;
            down[i] = EMPTY;
            }
            if(down[i]==lower){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else if(MathAbs(tma5truecenter-close)<=MathAbs(TMA5_Dif_Pip*Point) && close<tma5truecenter){
            if(down[i]!=EMPTY && up[i]!=upper){
            down[i] = lower;
            up[i] = EMPTY;
            }
            if(up[i]==upper){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else {
         up[i] = EMPTY;
         down[i] = EMPTY;
         }
      }
      if(Use_Babon_Slope==true){
      double babonup = iCustom(NULL,0,"Babon+Slope+",BabonPeriod,BabonMethod,BabonPrice,0,i);
      double babonuplast = iCustom(NULL,0,"Babon+Slope+",BabonPeriod,BabonMethod,BabonPrice,0,i+1);
      double babondown = iCustom(NULL,0,"Babon+Slope+",BabonPeriod,BabonMethod,BabonPrice,1,i);
      double babondownlast = iCustom(NULL,0,"Babon+Slope+",BabonPeriod,BabonMethod,BabonPrice,1,i+1);
         if(babonup<999999 && babondownlast<999999 && babondown>999999){
            if(up[i]!=EMPTY && down[i]!=lower){
            up[i] = upper;
            down[i] = EMPTY;
            }
            if(down[i]==lower){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else if(babondown<999999 && babonuplast<999999 && babonup>999999){
            if(down[i]!=EMPTY && up[i]!=upper){
            down[i] = lower;
            up[i] = EMPTY;
            }
            if(up[i]==upper){
            down[i] = EMPTY;
            up[i] = EMPTY;
            }
         }
         else {
         up[i] = EMPTY;
         down[i] = EMPTY;
         }
      }
      if (highest_lowest==true){
      int high = iHighest(NULL,0,MODE_HIGH,bars_for_highest_lowest,0);
      int low = iLowest(NULL,0,MODE_LOW,bars_for_highest_lowest,0);
      down[high] = High[high] + (10*Point);
      up[low] = Low[low] - (10*Point);
      }
      if(alert==true && NewBar()){
         if(down[i]==High[i] + (10*Point) ||up[i]==Low[i] - (10*Point)){
         PlaySound(filename);
         Alert("new signal");
         
         }
      }
      
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

 and in attached the indicators this indicator depend on

Files:
tmatrue.ex4  5 kb
 
  1. int start(){
       for(int i=limit; i>=0; i--){
          :
                if(up[i]!=EMPTY && down[i]!=lower){
    
    up[i]/down[i] haven't values yet, so they will always be EMPTY_VALUE. Not EMPTY

  2. Unnecessary decrementContradictory information on IndicatorCounted() - MQL4 forum
    if(counted_bars>0) counted_bars--;
       limit=Bars-counted_bars;
       limit=Bars-1-counted_bars;


  3. double upper = Low[i] - (10*Point);
          double lower = High[i] + (10*Point);
    :
    else if (tma1trueupper+(CrossPips*Point)<ichimocupper ...
    Not adjusting for 4/5 digit brokers
  4. if(Use_Babon_Slope==true){
    You would never write if( (2+2 == 4) == true ) would you? You'd write if(2+2 == 4). So don't write if (boolean == true). if(boolean) and if(!boolean) is sufficient, especially if you name your variables logically (Use_X, is_X, do_X, etc.
          if (highest_lowest==true){
          if(alert==true && NewBar()){
    

  5. Attaching the binary is useless for us humans to read.
  6. if(babonup<999999 && babondownlast<999999 && babondown>999999){
    Don't hard code numbers. Use a #define so you self-document the code. If you mean EMPTY_VALUE use it.
  7. double babonup = iCustom(NULL,0,"Babon+Slope+",BabonPeriod,BabonMethod,BabonPrice,0,i);
    Do you really have an indicator named "Babon+Slope+.mq4"?
  8. I recommend factoring code into functions as a matter of good coding. I have ONE exception NewBar() and equivalents. They can ONLY be called once per tick - they return false if called a second time. Thus I recommend inline coding of that to prevent multiple calls.
    bool NewBar()
    {
       static datetime lastbar;
       datetime curbar = Time[0];
       if(lastbar!=curbar)
       {
          lastbar=curbar;
          return (true);
       }
       else
       {
          return(false);
       }
    }
     for(int i=limit; i>=0; i--)
    :
          if(alert==true && NewBar()){
             if(down[i]==High[i] + (10*Point) ||up[i]==Low[i] - (10*Point)){

    You are calling it every time in your loop.
    A) must be outside the loop.
    B) When NewBar is true high[0] == low[0] etc perhaps you mean to look at down[1] etc.
    C) Doubles rarely compare equal.
 

many many thanks Mr.William,

 I think the problem was with the first solution you told above, I think that what made the indicator repaint.

many thanks too for your advices in coding that help me very well, really I don't find words help me to thank you.