Download MetaTrader 5

Add Shifted Bars data to indicator?

To add comments, please log in or register
Do you want to know about the MQL5.community development? Have a look at the Wall!
Christopher Evans
335
Christopher Evans 2015.03.15 17:06 

Hi to you all,

I have programmed an indicator that shows great buy/sell signals (historically) when shifted bars are used say minus two (-2).

When no shift is used the indicator is very ordinary. In real time, the indicator is not showing true values till the 3rd bar back.

Because the shift is minus (-) and not plus (+), using formed or forming bars is there a piece of code that will count the information

on the two shifted bars and add it to the indicator info to give real time indication?

Your thoughts will be much appreciated!!

Vladimir Karputov
Moderator
45569
Vladimir Karputov 2015.03.15 19:02  
Please insert a picture with explanations.
Christopher Evans
335
Christopher Evans 2015.03.15 19:54  

 

Above is a Pic of the problem with indicator. Bottom right (at price action) the band is missing a portion of info and breaks the band, the 3rd bar back shows the fully expanded band (unbroken).

Historically if the band is broken a good trading signal is given. In real time the band is not fully expanded and as the price moves on to the next bar, bar 2 falls inside the bands, so the info is

false. 

Vladimir Karputov
Moderator
45569
Vladimir Karputov 2015.03.15 20:47  

The indicator is similar to the bollinger bands. Probably a bug in the code. Please show your code.

Vladimir Karputov
Moderator
45569
Vladimir Karputov 2015.03.15 21:07  
This is not all of the code. It does not compile.
Vladimir Karputov
Moderator
45569
Vladimir Karputov 2015.03.16 18:56  

Try this code:

#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"

#property indicator_chart_window
#property indicator_buffers   3
#property indicator_type1     DRAW_LINE     
#property indicator_type2     DRAW_LINE  
#property indicator_type3     DRAW_LINE 
#property indicator_color1    SlateGray
#property indicator_color2    SlateGray
#property indicator_color3    Orange
#property indicator_width1    1
#property indicator_width2    1
#property indicator_width3    1
#property strict
//-------------------------
extern double Factor= 1.0;
extern double Width = 2.4;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+ 
void OnInit()
  {
   Comment("EezymoneyBandsV8");
   IndicatorBuffers(3);
   SetIndexBuffer(0,ExtMapBuffer1,INDICATOR_DATA);
   SetIndexBuffer(1,ExtMapBuffer2,INDICATOR_DATA);
   SetIndexBuffer(2,ExtMapBuffer3,INDICATOR_DATA);
  }
//---------------------------------------- 
int OnCalculate(
                const int rates_total,       // размер входных таймсерий
                const int prev_calculated,   // обработано баров на предыдущем вызове
                const datetime& time[],      // Time
                const double& open[],        // Open
                const double& high[],        // High
                const double& low[],         // Low
                const double& close[],       // Close
                const long& tick_volume[],   // Tick Volume
                const long& volume[],        // Real Volume
                const int &spread[]          // Spread
                )
  {
   int i,limit;
//---
   if(rates_total<=2)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- indicator counted in the 1-st buffer
   for(i=0; i<limit; i++)
     {
      //Print("i=",i,"; time[",i,"]",time[i]);
      double MAH = iMA(NULL,0,5,-2,MODE_LWMA,PRICE_HIGH,i);
      double BUP = iBands(NULL,0,7,Factor,0,PRICE_HIGH,MODE_UPPER,i);

      double MAL = iMA(NULL,0,5,-2,MODE_LWMA,PRICE_LOW,i);
      double BDN = iBands(NULL,0,7,Factor,0,PRICE_LOW,MODE_LOWER,i);
      double ATR = iATR(NULL,0,5,i);

      if(MAH>BUP)
        {
         ExtMapBuffer1[i]=MAH+(ATR/Width)+20*Point;
         BUP=EMPTY_VALUE;
        }
      else if(MAH<BUP)
        {
         ExtMapBuffer1[i]=BUP+(ATR/Width);
         MAH=EMPTY_VALUE;
        }
      //--------------------------------------------------------------------             
      if(MAL>0.0)
        {
         if(MAL<BDN)
           {
            ExtMapBuffer2[i]=MAL-(ATR/Width)-20*Point;
            BDN=EMPTY_VALUE;
           }
         else if(MAL>BDN)
           {
            ExtMapBuffer2[i]=BDN-(ATR/Width);
            MAL=EMPTY_VALUE;
           }
        }
      if(MAL==0.0)
        {
         ExtMapBuffer2[i]=BDN-(ATR/Width);
         MAL=EMPTY_VALUE;
        }
      //-------------------
      ExtMapBuffer3[i]=(ExtMapBuffer1[i]+ExtMapBuffer2[i])/2.0;
     }
   return(rates_total);
//RefreshRates();
  }
//+------------------------------------------------------------------+
Christopher Evans
335
Christopher Evans 2015.03.16 20:30  

Thank you for your time on this project, you have really thought about this.

As you can see from my code I am not a studied programmer, but am prepared to have a go.

Have placed your code (indicator) over my own and I have noticed that on lower time frames your code produces some higher peaks (but never falls inside my code),

then as you move up the time frames, the bands become more identical. I will study  there behaviour in more detail over more time.

I have read an article by Nikolay Kositsin on NULL Bar recount and how indicators with NULL Bar info need to have variables placed into arrays to give proper

real time data.

My program expertise does not run this deep so do not know how to implement this idea. Are you familiar with this? Could this be the problem?

To add comments, please log in or register