Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
joshatt
336
joshatt 2016.01.23 13:25 

Hi all,

"Ichimoku" indicator has a band plus three lines. I'm trying to hide the three lines(No. 1,2,5) and add three MA lines.

The following is the code, but why that band does not show up in the chart? Could anybody please help?

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Yellow
#property indicator_color2 Orange
#property indicator_color3 SandyBrown   // Up Kumo
#property indicator_color4 Thistle      // Down Kumo
#property indicator_color5 Red
#property indicator_color6 SandyBrown   // Up Kumo bounding line
#property indicator_color7 Thistle      // Down Kumo bounding line
//--- input parameters
input int InpTenkan=9;   // Tenkan-sen
input int InpKijun=26;   // Kijun-sen
input int InpSenkou=52;  // Senkou Span B

extern int MA1=30;
extern int MA1Shift=0;
extern int MA2=50;
extern int MA2Shift=0;
extern int MA3Period=100;
extern int MA3Shift=0;
//--- buffers
double ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtSpanA_Buffer[];
double ExtSpanB_Buffer[];
double ExtChikouBuffer[];
double ExtSpanA2_Buffer[];
double ExtSpanB2_Buffer[];

double ExtMA1Buffer[];
double ExtMA2Buffer[];
double ExtMA3Buffer[];
//---
int    ExtBegin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   IndicatorDigits(Digits);
//---

//---
   ExtBegin=InpKijun;
   if(ExtBegin<InpTenkan)
      ExtBegin=InpTenkan;
//---
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(2,ExtSpanA_Buffer);
   SetIndexDrawBegin(2,InpKijun+ExtBegin-1);
   SetIndexShift(2,InpKijun);
   SetIndexLabel(2,NULL);
   SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(5,ExtSpanA2_Buffer);
   SetIndexDrawBegin(5,InpKijun+ExtBegin-1);
   SetIndexShift(5,InpKijun);
   SetIndexLabel(5,"Senkou Span A");
//---
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(3,ExtSpanB_Buffer);
   SetIndexDrawBegin(3,InpKijun+InpSenkou-1);
   SetIndexShift(3,InpKijun);
   SetIndexLabel(3,NULL);
   SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(6,ExtSpanB2_Buffer);
   SetIndexDrawBegin(6,InpKijun+InpSenkou-1);
   SetIndexShift(6,InpKijun);
   SetIndexLabel(6,"Senkou Span B");
//---


//---- line shifts when drawing
   SetIndexShift(0,MA1Shift);
   SetIndexShift(1,MA2Shift);
   SetIndexShift(4,MA3Shift);

//---- first positions skipped when drawing
   SetIndexDrawBegin(0,MA1Shift+MA1);
   SetIndexDrawBegin(1,MA2Shift+MA2);
   SetIndexDrawBegin(4,MA3Shift+MA3Period);

//---- 4 indicator buffers mapping
   SetIndexBuffer(0,ExtMA1Buffer);
   SetIndexBuffer(1,ExtMA2Buffer);
   SetIndexBuffer(4,ExtMA3Buffer);

//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);

//---- index labels
   SetIndexLabel(0,"MA1");
   SetIndexLabel(1,"MA2");
   SetIndexLabel(4,"MA3");
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   int limit;
   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;
//---- main loop
   for(int ii=0; ii<limit; ii++)
     {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      ExtMA1Buffer[ii]=iMA(NULL,0,MA1,0,MODE_SMA,PRICE_CLOSE,ii);
      ExtMA2Buffer[ii]=iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,ii);
      ExtMA3Buffer[ii]=iMA(NULL,0,MA3Period,0,MODE_SMA,PRICE_CLOSE,ii);

     }
//---- done


   int    i,k,pos;
   double high_value,low_value;
//---
   if(rates_total<=InpTenkan || rates_total<=InpKijun || rates_total<=InpSenkou)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtTenkanBuffer,false);
   ArraySetAsSeries(ExtKijunBuffer,false);
   ArraySetAsSeries(ExtSpanA_Buffer,false);
   ArraySetAsSeries(ExtSpanB_Buffer,false);
   ArraySetAsSeries(ExtChikouBuffer,false);
   ArraySetAsSeries(ExtSpanA2_Buffer,false);
   ArraySetAsSeries(ExtSpanB2_Buffer,false);
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<InpTenkan; i++)
         ExtTenkanBuffer[i]=0.0;
      for(i=0; i<InpKijun; i++)
         ExtKijunBuffer[i]=0.0;
      for(i=0; i<ExtBegin; i++)
        {
         ExtSpanA_Buffer[i]=0.0;
         ExtSpanA2_Buffer[i]=0.0;
        }
      for(i=0; i<InpSenkou; i++)
        {
         ExtSpanB_Buffer[i]=0.0;
         ExtSpanB2_Buffer[i]=0.0;
        }
     }
//--- Tenkan Sen
   pos=InpTenkan-1;
   if(prev_calculated>InpTenkan)
      pos=prev_calculated-1;
   for(i=pos; i<rates_total; i++)
     {
      high_value=high[i];
      low_value=low[i];
      k=i+1-InpTenkan;
      while(k<=i)
        {
         if(high_value<high[k])
            high_value=high[k];
         if(low_value>low[k])
            low_value=low[k];
         k++;
        }
      ExtTenkanBuffer[i]=(high_value+low_value)/2;
     }
//--- Kijun Sen
   pos=InpKijun-1;
   if(prev_calculated>InpKijun)
      pos=prev_calculated-1;
   for(i=pos; i<rates_total; i++)
     {
      high_value=high[i];
      low_value=low[i];
      k=i+1-InpKijun;
      while(k<=i)
        {
         if(high_value<high[k])
            high_value=high[k];
         if(low_value>low[k])
            low_value=low[k];
         k++;
        }
      ExtKijunBuffer[i]=(high_value+low_value)/2;
     }
//--- Senkou Span A
   pos=ExtBegin-1;
   if(prev_calculated>ExtBegin)
      pos=prev_calculated-1;
   for(i=pos; i<rates_total; i++)
     {
      ExtSpanA_Buffer[i]=(ExtKijunBuffer[i]+ExtTenkanBuffer[i])/2;
      ExtSpanA2_Buffer[i]=ExtSpanA_Buffer[i];
     }
//--- Senkou Span B
   pos=InpSenkou-1;
   if(prev_calculated>InpSenkou)
      pos=prev_calculated-1;
   for(i=pos; i<rates_total; i++)
     {
      high_value=high[i];
      low_value=low[i];
      k=i+1-InpSenkou;
      while(k<=i)
        {
         if(high_value<high[k])
            high_value=high[k];
         if(low_value>low[k])
            low_value=low[k];
         k++;
        }
      ExtSpanB_Buffer[i]=(high_value+low_value)/2;
      ExtSpanB2_Buffer[i]=ExtSpanB_Buffer[i];
     }
//--- Chikou Span
   pos=0;
   if(prev_calculated>1)
      pos=prev_calculated-1;
   for(i=pos; i<rates_total; i++)
      ExtChikouBuffer[i]=close[i];
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
whroeder1
13641
whroeder1 2016.01.23 15:57  
joshatt: "Ichimoku" indicator has a band plus three lines. I'm trying to hide the three lines(No. 1,2,5) and add three MA lines.
No code required
  1. Set the three lines to the color none.
  2. Add three MAs. done.
joshatt
336
joshatt 2016.01.24 01:03  
WHRoeder:
joshatt: "Ichimoku" indicator has a band plus three lines. I'm trying to hide the three lines(No. 1,2,5) and add three MA lines.
No code required
  1. Set the three lines to the color none.
  2. Add three MAs. done.

  

"DRAW_NONE" then add MAs, it works like you said......I was worrying about 8-line limitation, but it's not. Glad this one solved so quick. 

Thanks a lot!   

Zirkon
123
Zirkon 2016.01.26 18:35  
joshatt:

 

  

"DRAW_NONE" then add MAs, it works like you said......I was worrying about 8-line limitation, but it's not. Glad this one solved so quick. 

Thanks a lot!   

 

There is no "8-line" limitation.
whroeder1
13641
whroeder1 2016.01.26 18:59  
zirkoner: There is no "8-line" limitation.
Since February 3, 2014 (Build 600) There is no 8-line limitation per indicator.
There has never been a limitation of indicators per chart.
/
To add comments, please log in or register