Disappearing Indicator

 

Hello

Below is the coding I am writing which give the correct result, but if I change timeframe or symbol, the indicator disappears. The only way I can get it back is if I recompile the code.

#property copyright "Brian307"
#property link      "B121ANS@Hotmail.com"
#include <WinUser32.mqh>
//--------------------------------------------------- 1 ---------------------------------------------------------------------------------------
                                                                                             //DECLARING INDICATOR PROPERTIES
#property indicator_separate_window                                                         //Drawn in separate window  
#property indicator_buffers 3                                                             //Number of Buffers

#property indicator_color2 LimeGreen                                                     //Colour of long indication
#property indicator_color3 Red                                                         //Colour of short indication

#property indicator_width2 4                                                              //Line width of long indication
#property indicator_width3 4                                                              //Line width of short indication

#property indicator_minimum -1.1                                                               //Minimum height of indicator window
#property indicator_maximum 1.1                                                        //Maximum height of indicator window

//--------------------------------------------------- 2 ---------------------------------------------------------------------------------------
double ind[];                                                                           //DECLARING VARIABLES USED          
double ind_long[];
double ind_short[];     
double RSI[];
double RSIMA[];
double RSIBBU[];
double RSIBBL[];

extern int  AlertSleepMins    = 60;

extern bool PopupAlerts = true;                                                         //DECLARING VARIABLES USED
extern bool SoundAlerts = true;
extern bool EmailAlerts = true;
bool          alertTriggered;
datetime        lastAlertTime;
//--------------------------------------------------- 3 ---------------------------------------------------------------------------------------
void init()                                                                                 //Special function init()
{
   IndicatorBuffers(7);                                                                 //Number of buffer required for indicator

   SetIndexBuffer(0, ind);                                                                //Assigning array 'ind' to buffer 0
   SetIndexStyle(0, DRAW_NONE);                                                        //Line style to buffer 0

   SetIndexBuffer(1, ind_long);                                                                //Assigning array 'ind' to buffer 1
   SetIndexStyle(1, DRAW_HISTOGRAM);                                                     //Line style to buffer 1

   SetIndexBuffer(2, ind_short);                                                            //Assigning array 'ind' to buffer 2
   SetIndexStyle(2, DRAW_HISTOGRAM);                                                     //Line style to buffer 2

   SetIndexStyle(3,DRAW_NONE);
   SetIndexBuffer(3, RSI);

   SetIndexStyle(4,DRAW_NONE);
   SetIndexBuffer(4, RSIMA);
   
   SetIndexStyle(5,DRAW_NONE);
   SetIndexBuffer(5, RSIBBU);

   SetIndexStyle(6,DRAW_NONE);
   SetIndexBuffer(6, RSIBBL);

}
//--------------------------------------------------- 4 ---------------------------------------------------------------------------------------
int start()
{                                                                                              // Special function start()
   int    counted_bars=IndicatorCounted();

   int limit, i, RSIBBM;
   limit=(Bars-counted_bars)-1;
   for (i = limit; i >= 0; i--)
   {
      RSI[i]            = iRSI(NULL,0,8,PRICE_CLOSE,i);
      RSIMA[i]          = iMAOnArray(RSI,0,8,0,MODE_SMA,i);
      RSIBBU[i]         = iBandsOnArray(RSI,0,20,2,0,MODE_UPPER,i);
      RSIBBL[i]         = iBandsOnArray(RSI,0,20,2,0,MODE_LOWER,i);
      RSIBBM            = (RSIBBL[i] + RSIBBU[i]) / 2;
//--------------------------------------------------- 5 ---------------------------------------------------------------------------------------
                                                                                        // Initialize Latest Buffer Value
      ind[i]         = 0.0;
      ind_long[i]    = 0.0;
      ind_short[i]   = 0.0;
//--------------------------------------------------- 6 ---------------------------------------------------------------------------------------
                                                                                        // Long Signal
      if((RSI[i] > RSIMA[i]) && (RSI[i+1] < RSIMA[i+1]) && (RSI[i+1] < RSIBBM))
      {
         ind[i]      = 1;
         ind_long[i] = 1;
      }
//--------------------------------------------------- 7 ---------------------------------------------------------------------------------------
                                                                                        // Short Signal
      if((RSI[i] < RSIMA[i]) && (RSI[i+1] > RSIMA[i+1]) && (RSI[i+1] > RSIBBM))
      {
         ind[i]         = -1;
         ind_short[i]   = -1;
      }
   }
//--------------------------------------------------- 8 ---------------------------------------------------------------------------------------
                                                                                        // Trigger the Alert if Required
   string signal = "";
   if (ind[0] == 1)
      signal = "Long";
   else if (ind[0] == -1)
      signal = "Short";
//--------------------------------------------------- 9 ---------------------------------------------------------------------------------------
   if (ind[0] != 0)
   {
      if (alertTriggered == false && lastAlertTime <= TimeCurrent() - AlertSleepMins * 60)
      {
         lastAlertTime = TimeCurrent();
         if (PopupAlerts == true)
            Alert(Symbol() + " " + signal + " BB RSI MA alert");
         if (SoundAlerts == true)
            PlaySound("Alert.wav");
         if (EmailAlerts == true)
            SendMail(Symbol() + " " + signal + " BB RSI MA alert ", + TimeCurrent());
      }
      alertTriggered = true;
   }
   else 
      alertTriggered = false;
}
return(0);
//--------------------------------------------------- 10 --------------------------------------------------------------------------------------
  


Is there anyone who can help resolve this issue please?

 
brian307: 2010.11.13 21:04

Below is the coding I am writing which give the correct result, but if I change timeframe or symbol, the indicator disappears. The only way I can get it back is if I recompile the code.

Is there anyone who can help resolve this issue please?

  1. It won't repaint until a tick comes in and calls start. Market is currently closed.

  2. // int    counted_bars=IndicatorCounted();
    // int    limit=(Bars-counted_bars)-1;
    // Do it right
       int    counted_bars=IndicatorCounted();
       if(counted_bars>0) counted_bars--;
       limit=Bars-counted_bars;
    
 
reply
WHRoeder:

It won't repaint until a tick comes in and calls start. Market is currently closed.

right click/refresh?

Hello WHRoeder

Thank you for your response.

Although the market is closed, I have other indicators that don't disaapear when I change timeframe/symbol. This was also happening yesterday during market hours.

The refresh will not repaint the indicator either.

B

 

I'm seeing this on my indicator, works fine initially but changing the length results in iMAOnArray is returning garbage though the inputs are correct. I have no clue. Here's my code

    buffer1[i]=iMA(NULL,0,per2,0,MODE_LWMA,PRICE_CLOSE,i)*2-
                iMA(NULL,0,HMA_Period,0,MODE_LWMA,PRICE_CLOSE,i);
    tmpPrevious=iMAOnArray(buffer1,0,sqrt,0,MODE_LWMA,i+1);
    tmp        =iMAOnArray(buffer1,0,sqrt,0,MODE_LWMA,i);
                                                    if (i> Bars-20) Print(
"b[",i,"]=",buffer1[i],",",buffer1[i+1],",",buffer1[i+2],",",buffer1[i+3],
",",buffer1[i+4],",",buffer1[i+5],",",buffer1[i+6],",b[",i+7,"]=",buffer1[i+7],
" t=",tmp," sq=",sqrt," db=",draw_begin0," per=", HMA_Period," Bars=",Bars);
//b[34486]=1.2377,1.2377,1.237,1.2362,1.2361,1.2348,1.2336,b[34493]=1.2329 t=2147483647 sq=3 db=14 per=10 Bars=34505
//b[34487]=1.2377,1.237,1.2362,1.2361,1.2348,1.2336,1.2329,b[34494]=1.2332 t=1789569706.0394 sq=3 db=14 per=10 Bars=34505
//b[34488]=1.237,1.2362,1.2361,1.2348,1.2336,1.2329,1.2332,b[34495]=1.2325 t=1073741824.1181 sq=3 db=14 per=10 Bars=34505
//b[34489]=1.2362,1.2361,1.2348,1.2336,1.2329,1.2332,1.2325,b[34496]=1.2332 t=1.236 sq=3 db=14 per=10 Bars=34505
Reason: