Having Problem Setting Arrays on a Dynamic Envelope Indicator

 

Good Day Folks , I am Programming a Custom Dynamic Envelope based on band on Macd array 

everything was set and data came out well , except for the array drawing that i got are a little bit messy , 


what would be the problem ? 

its a simple indicator but i am bad with array functions 


Thanks in advance ! 

//+------------------------------------------------------------------+

//|                                              CustomTornadoV2.mq4 |

//|                                 Copyright 2017, Ghamdan Mohammed |

//|                                                      www.mec.biz |

//+------------------------------------------------------------------+

#property copyright "Copyright 2017, Ghamdan Mohammed"

#property link      "www.mec.biz"

#property version   "1.00"

#property strict

#property indicator_chart_window

#property indicator_buffers 6

#property indicator_plots   6

//--- plot FastUp

#property indicator_label1  "FastUp"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrLime

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot FastDown

#property indicator_label2  "FastDown"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot SlowUp

#property indicator_label3  "SlowUp"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrBlack

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- plot SlowDown

#property indicator_label4  "SlowDown"

#property indicator_type4   DRAW_LINE

#property indicator_color4  clrDodgerBlue

#property indicator_style4  STYLE_SOLID

#property indicator_width4  1

//--- plot MACD1

#property indicator_label5  "MACD1"

#property indicator_type5   DRAW_LINE

#property indicator_color5  clrRed

#property indicator_style5  STYLE_SOLID

#property indicator_width5  1

//--- plot MACD2

#property indicator_label6  "MACD2"

#property indicator_type6   DRAW_LINE

#property indicator_color6  clrRed

#property indicator_style6  STYLE_SOLID

#property indicator_width6  1

//--- indicator buffers


input int      PeriodFast=24;

input int      FastShift=0;

input ENUM_MA_METHOD      FastMethod=0;

input ENUM_APPLIED_PRICE      FastApplied=0;

input int      PeriodSlow=120;

input int      SlowShift=0;

input ENUM_MA_METHOD      SlowMethod=0;

input ENUM_APPLIED_PRICE      SlowApplied=0;


double         FastUpBuffer[];

double         FastDownBuffer[];

double         SlowUpBuffer[];

double         SlowDownBuffer[];

double         MACD1Buffer[];

double         MACD2Buffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,FastUpBuffer);

   SetIndexBuffer(1,FastDownBuffer);

   SetIndexBuffer(2,SlowUpBuffer);

   SetIndexBuffer(3,SlowDownBuffer);

   SetIndexBuffer(4,MACD1Buffer);

   SetIndexBuffer(5,MACD2Buffer);

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

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 i,pos;

//---

   if(rates_total<=PeriodFast || PeriodFast<=0)

      return(0);

          {

      for(i=0; i<PeriodFast; i++)

        {

         FastUpBuffer[i]=EMPTY_VALUE;

         FastDownBuffer[i]=EMPTY_VALUE;

         SlowUpBuffer[i]=EMPTY_VALUE;

         SlowDownBuffer[i]=EMPTY_VALUE;

         MACD1Buffer[i]=EMPTY_VALUE;

         MACD2Buffer[i]=EMPTY_VALUE;

         

        }

     } 

    if(prev_calculated>1)

      pos=prev_calculated-1;

   else

      pos=0;     

         for(i=pos; i<rates_total && !IsStopped(); i++)

     {

    MACD1Buffer[i]=iMA(NULL,0,2,0,FastMethod,FastApplied,i)-

                    iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i);

      FastUpBuffer[i] = iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i)+iBandsOnArray(MACD1Buffer,0,200,2,0,1,0); 

      FastDownBuffer[i] =iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i)+ iBandsOnArray(MACD1Buffer,0,200,2,0,2,0); 

    MACD2Buffer[i]=iMA(NULL,0,2,0,SlowMethod,SlowApplied,i)-

                    iMA(NULL,0,PeriodSlow,0,SlowMethod,SlowApplied,i);

      SlowUpBuffer[i] = iMA(NULL,0,PeriodSlow,0,SlowMethod,SlowApplied,i)+iBandsOnArray(MACD2Buffer,0,200,2,0,1,0); 

      SlowDownBuffer[i] =iMA(NULL,0,PeriodSlow,0,SlowMethod,SlowApplied,i)+ iBandsOnArray(MACD2Buffer,0,200,2,0,2,0); 

      

      

      }  

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 
thank you very much  ! appreciate it ! 
 
  1. #property indicator_plots   6
    No such property in MT4
  2. MACD1Buffer[i]=iMA(NULL,0,2,0,FastMethod,FastApplied,i)-
    
                        iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i);
    Buffer @ i is filled with corresponding MA @i. Makes sense.
        FastUpBuffer[i] = iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i)+iBandsOnArray(MACD1Buffer,0,200,2,0,1,0); 
    
          FastDownBuffer[i] =iMA(NULL,0,PeriodFast,0,FastMethod,FastApplied,i)+ iBandsOnArray(MACD1Buffer,0,200,2,0,2,0); 
    
    Not so for the bands. Also you need to set the buffer to asSeries before filling so bands knows how to read it.
  3. But it still won't work because you are counting up, you haven't fill the higher ones yet. Remove that buffer initialization code, count down, and do How to do your lookbacks correctly.
Reason: