Buffer value differs print/chart

 

Hi! ***

To make it quick, I'm a newb on mql but I can manage few things. I already have an EA but I want to change the indicator it uses and I ran into an issue where I have an indicator that prints arrows (that are not objects) and I want to base a signal on those arrows. When the arrow appears the buffer has a value, the problem is that they have different values when I print them/use them.

On Pic 1 we can see that the arrow has value and it's shown in data but when I print, the value is empty.

And on Pic 2 it prints a value where there was no arrow/signal on chart (and no value in data when I hover over that day).

Is the problem with the indicator or me? If it's the indicator, what's the easiest way to make it work? I have the source code of the indicator.

  Print("Buffer 0: ",iCustom(NULL,0,"Confirmation\\Sidus_(Vulkan profit)",0,1));
  Print("Buffer 1: ",iCustom(NULL,0,"Confirmation\\Sidus_(Vulkan profit)",1,1));

This is the printing part, the buffers are correct as I can see, I can provide the neccesary code.
Thanks!

Files:
Screen_1.png  127 kb
Screen_2.png  121 kb
 

You should provide the picture directly on your post and not by links which are not even clickable.

Seems like a repainting indicator, difficult to say more. You should provide the indicator code.

 
Oh, the link became unreachable, sorry, my fault, I'm used to not overloading the sites I post on. I attached the pictures and here is the indicator code:

// Original Sidus Method filtered with RSI and CCI.
// Edited by Tians using Sidus-Crossover_Signal.mq4 as a
// template.
//(Tians)

/*
  +------------------------------------------------------------------+
  | Shows an arrow when there is a Sidus signal.  Shows dots when    |
  | the Sidus tunnel crosses.   Blue dot confirms uptrend.  Red dot  |
  | confirms downtrend.  Alerts on Sidus signal by default - Sounds  |
  | alert and sends e-mail.                                          |
  +------------------------------------------------------------------+
*/   

extern bool Alerts = true;
extern bool Tunnel_Alerts= false;
extern bool Email_Alerts = false;

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Black
#property indicator_color4 Black

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

double CrossUp[];
double CrossDown[];
double Tup[];
double Tdown[];
bool   DownTunnel = false;
bool   UpTunnel = false;
bool   Signal = false;

extern int FasterLWMA = 3;
extern int SlowerLWMA = 8;
extern int FasterSidusEMA = 18;
extern int SlowerSidusEMA = 28;

int upalert=false,downalert=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   SetIndexStyle(2, DRAW_ARROW, EMPTY,1);
   SetIndexArrow(2, 167);
   SetIndexBuffer(2, Tup);
   SetIndexStyle(3, DRAW_ARROW, EMPTY,1);
   SetIndexArrow(3, 167);
   SetIndexBuffer(3, Tdown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double RSI, RSIp, CCI, FasterLWMAnow, SlowerLWMAnow, FasterLWMAprevious, SlowerLWMAprevious, FasterLWMAafter, SlowerLWMAafter, fasterSidusEMAnow, fasterSidusEMAprevious, fasterSidusEMAafter, slowerSidusEMAnow, slowerSidusEMAprevious, slowerSidusEMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {

      counter=i;
      Range=0;
      AvgRange=0;
   
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }

      Range=AvgRange/10;
       
      FasterLWMAnow = iMA(NULL, 0, FasterLWMA, 0, MODE_LWMA, PRICE_CLOSE, i);
      FasterLWMAprevious = iMA(NULL, 0, FasterLWMA, 0, MODE_LWMA, PRICE_CLOSE, i+1);
      FasterLWMAafter = iMA(NULL, 0, SlowerLWMA, 0, MODE_LWMA, PRICE_CLOSE, i-1);

      SlowerLWMAnow = iMA(NULL, 0, SlowerLWMA, 0, MODE_LWMA, PRICE_CLOSE, i);
      SlowerLWMAprevious = iMA(NULL, 0, SlowerLWMA, 0, MODE_LWMA, PRICE_CLOSE, i+1);
      SlowerLWMAafter = iMA(NULL, 0, SlowerLWMA, 0, FasterLWMA, PRICE_CLOSE, i-1);

      fasterSidusEMAnow = iMA(NULL, 0, FasterSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      fasterSidusEMAprevious = iMA(NULL, 0, FasterSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      fasterSidusEMAafter = iMA(NULL, 0, FasterSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

      slowerSidusEMAnow = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      slowerSidusEMAprevious = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      slowerSidusEMAafter = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
      
      RSI=iRSI(NULL,0,21,PRICE_CLOSE,i);
      RSIp=iRSI(NULL,0,21,PRICE_CLOSE,i+1);
      
      CCI=iCCI(NULL,0,50,PRICE_CLOSE,i);
      
      if (   fasterSidusEMAnow > slowerSidusEMAnow &&
             fasterSidusEMAprevious <= slowerSidusEMAprevious &&
             fasterSidusEMAafter > slowerSidusEMAafter )
      { 
         UpTunnel=true; DownTunnel=false; Tup[i] = Low[i] - Range*1;
         if( i<=2 && Alerts && !upalert && Tunnel_Alerts )
         {
            upalert=true; downalert=false;
            Alert (Symbol()," ",Period(),"M  Sidus Tunnel UP ");
            if ( Email_Alerts ) { SendMail("Sidus Tunnel UP "+Symbol(),""); }
         }
      }

      if ( fasterSidusEMAnow < slowerSidusEMAnow &&
           fasterSidusEMAprevious >= slowerSidusEMAprevious &&
           fasterSidusEMAafter < slowerSidusEMAafter )
      {
         DownTunnel=true; UpTunnel=false; Tdown[i] = High[i] + Range*1.2;
         if( i<=2 && Alerts && !downalert && Tunnel_Alerts )
         {
            upalert=false; downalert=true;
            Alert (Symbol()," ",Period(),"M  Sidus Tunnel DOWN ");
            if ( Email_Alerts ) { SendMail("Sidus Tunnel DOWN "+Symbol(),""); }
         }
      }
      
      if (  
           ( // Conditions for up signal for EMA-Sidus crosses
             (( FasterLWMAnow > fasterSidusEMAnow && FasterLWMAnow > slowerSidusEMAnow ) ||
              ( SlowerLWMAnow > fasterSidusEMAnow && SlowerLWMAnow > slowerSidusEMAnow )) &&
             ( FasterLWMAprevious <= fasterSidusEMAprevious || FasterLWMAprevious <= slowerSidusEMAprevious ) &&
             ( SlowerLWMAprevious <= fasterSidusEMAprevious || SlowerLWMAprevious <= slowerSidusEMAprevious ) &&
             // RSI > 50 &&
             // CCI > 0 &&
             UpTunnel
           )
         )
         {   // IF all that above is correct, then do this:
             UpTunnel=false;
             DownTunnel=false;
             Signal=true;
             CrossUp[i] = Low[i] - Range*1.6;
             if(i<=2 && Alerts && !upalert)
               {
                  Alert (Symbol()," ",Period(),"M  Sidus BUY ");
                  if ( Email_Alerts ) { SendMail("Sidus BUY "+Symbol(),""); }
                  upalert=true;
                  downalert=false;
               }
         }
      
      if (  
           ( // Conditions for down signal for EMA-Sidus crosses too
             (( FasterLWMAnow < fasterSidusEMAnow && FasterLWMAnow < slowerSidusEMAnow ) ||
              ( SlowerLWMAnow < fasterSidusEMAnow && SlowerLWMAnow < slowerSidusEMAnow )) &&
             ( FasterLWMAprevious >= fasterSidusEMAprevious || FasterLWMAprevious >= slowerSidusEMAprevious ) &&
             ( SlowerLWMAprevious >= fasterSidusEMAprevious || SlowerLWMAprevious >= slowerSidusEMAprevious ) &&
             // RSI < 50 &&
             // CCI < 0 &&
             DownTunnel
           )
         )
         {   // IF all that above is correct, then do this:
             UpTunnel=false;
             DownTunnel=false;
             Signal=true;
             CrossDown[i] = High[i] + Range*1.2;
             if(i<=2 && Alerts && !downalert)
               {
                  Alert (Symbol()," ",Period(),"M  Sidus SELL ");
                  if ( Email_Alerts ) { SendMail("Sidus SELL "+Symbol(),""); }
                  downalert=true;
                  upalert=false;
               }
         }
   }
   
   return(0);
}
 
MrKalindro:
Oh, the link became unreachable, sorry, my fault, I'm used to not overloading the sites I post on. I attached the pictures and here is the indicator code:
      slowerSidusEMAprevious = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      slowerSidusEMAafter    = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

1. As expected, this indicator is repainting, it draws signal in the past up to 3rd closed candle.

   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {

On live update limit is up to 3 (on a new bar). So 'i' can be 3 and it will eventually draw a signal on 3rd closed candle : CrossUp[3]=....

So when in your EA you look at bar index=1, you miss the signal.

2. Also, and even worst, this indicator use values from the future ! For example :

      slowerSidusEMAprevious = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      slowerSidusEMAafter    = iMA(NULL, 0, SlowerSidusEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

If i=10 for example, it look at iMA value for candle 9, which is in the future of candle 10.

In summary, this indicator is useless and is a good example of bad coding and self-deception.

 
Ough that's horrible but also awesome that you discovered it. It really sometimes seemed to good to be true. Now I know the red flags of repainting indicators, I'm really grateful, thank you for the help!
 
MrKalindro:
Ough that's horrible but also awesome that you discovered it. It really sometimes seemed to good to be true. Now I know the red flags of repainting indicators, I'm really grateful, thank you for the help!
You are welcome.
Reason: