error in ma code
  #1 (permalink)  
Old 12-05-2006, 05:52 PM
Sophomore
 
Join Date: Nov 2006
Posts: 73
Thanks: 1
Thanked 22 Times in 18 Posts
hayseed is on a distinguished road
Default error in ma code

can someone see my error in the code below.... it's unstable and will only show 4 lines instead of 8.... i've seen other indicators that have more than 4 components , so the number of moving averages should not be the issue.... i've replaced parts of the code here and there with ideas from some of the best coders here on the forum but still the last 4 will not plot..... if you plot it and only 2 lines appear, refresh the chart ..... here is a poor reprentation of final product, i had to use 2 indicators in that image instead of 1, to show the idea...... any thoughts......thanks .....h

PHP Code:
//+------------------------------------------------------------------+
//|                                          moving average bars.mq4 |
//|                                                           .....h |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ".....h"
#property link      ""
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 10
#property indicator_buffers 16
 
 
//---- input parameters
extern int MA_Method=0;  //0 Simple moving average,  
                         //1 Exponential moving average,  
                         //2 Smoothed moving average,  
                         //3 Linear weighted moving average.  
 
extern int applied_price=PRICE_CLOSE//0 Close  
                                      //1 Open  
                                      //2 High  
                                      //3 Low  
                                      //4 Median  
                                      //5 Typical 
                                      //6 Weighted  
 
 
extern int EMA1Period  10;    
extern int EMA2Period 20;  
extern int EMA3Period  33;    
extern int EMA4Period 50;  
extern int EMA5Period=89;
extern int EMA6Period=100;
extern int EMA7Period=150;
extern int EMA8Period=200
 
//---- buffers
double aboveEMA1[];
double belowEMA1[];
double aboveEMA2[];
double belowEMA2[];
double aboveEMA3[];
double belowEMA3[];
double aboveEMA4[];
double belowEMA4[];
double aboveEMA5[];
double belowEMA5[];
double aboveEMA6[];
double belowEMA6[];
double aboveEMA7[];
double belowEMA7[];
double aboveEMA8[];
double belowEMA8[];
int i
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
 {
  
IndicatorDigits(2);
  
SetIndexBuffer(0aboveEMA1);SetIndexDrawBegin(0,i-1);
  
SetIndexLabel (0"EMA1");
  
SetIndexStyle (0DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(1belowEMA1);SetIndexDrawBegin(1,i-1);
  
SetIndexLabel (1"EMA1");
  
SetIndexStyle (1DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(2aboveEMA2);SetIndexDrawBegin(2,i-1);
  
SetIndexLabel (2"EMA2");
  
SetIndexStyle (2DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(3belowEMA2);SetIndexDrawBegin(3,i-1);
  
SetIndexLabel (3"EMA2");
  
SetIndexStyle (3DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(4aboveEMA3);SetIndexDrawBegin(4,i-1);
  
SetIndexLabel (4"EMA3");
  
SetIndexStyle (4DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(5belowEMA3);SetIndexDrawBegin(5,i-1);
  
SetIndexLabel (5"EMA3");
  
SetIndexStyle (5DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(6aboveEMA4);SetIndexDrawBegin(6,i-1);
  
SetIndexLabel (6"EMA4");
  
SetIndexStyle (6DRAW_LINESTYLE_SOLID4Red);
 
 
  
SetIndexBuffer(7belowEMA4);SetIndexDrawBegin(7,i-1);
  
SetIndexLabel (7"EMA4");
  
SetIndexStyle (7DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(8aboveEMA5);SetIndexDrawBegin(8,i-1);
  
SetIndexLabel (8"EMA5");
  
SetIndexStyle (8DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(9belowEMA5);SetIndexDrawBegin(9,i-1);
  
SetIndexLabel (9"EMA5");
  
SetIndexStyle (9DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(10aboveEMA6);SetIndexDrawBegin(10,i-1);
  
SetIndexLabel (10"EMA6");
  
SetIndexStyle (10DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(11belowEMA6);SetIndexDrawBegin(11,i-1);
  
SetIndexLabel (11"EMA6");
  
SetIndexStyle (11DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(12aboveEMA7);SetIndexDrawBegin(12,i-1);
  
SetIndexLabel (12"EMA7");
  
SetIndexStyle (12DRAW_LINESTYLE_SOLID4Red);
 
  
SetIndexBuffer(13belowEMA7);SetIndexDrawBegin(14,i-1);
  
SetIndexLabel (13"EMA7");
  
SetIndexStyle (13DRAW_LINESTYLE_SOLID4Lime);
 
  
SetIndexBuffer(14aboveEMA8);SetIndexDrawBegin(14,i-1);
  
SetIndexLabel (14"EMA8");
  
SetIndexStyle (14DRAW_LINESTYLE_SOLID4Red);
 
 
  
SetIndexBuffer(15belowEMA8);SetIndexDrawBegin(15,i-1);
  
SetIndexLabel (15"EMA8");
  
SetIndexStyle (15DRAW_LINESTYLE_SOLID4Lime);
 
 
 
 
  return(
0);
  }
 
 
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   
return(0);
  }
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  
int start() 
  {
 
 
  
int ishiftlimitcounted_bars IndicatorCounted();
 
     
//i=Bars
   //while(i>=0)   
 
 
      
if (counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++) 
 
 
    {
    
belowEMA1 [shift]= 9;
    
aboveEMA1 [shift]= 9;
    
double EmaValue iMA(NULL0EMA1Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValueaboveEMA1 [shift]= EMPTY_VALUE;
    if (
Close[shift]<EmaValuebelowEMA1[shift]= EMPTY_VALUE;
    }
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
 
    {
    
belowEMA2[shift] = 8;
    
aboveEMA2[shift] = 8;
    
double EmaValue2 iMA(NULL0EMA2Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue2aboveEMA2[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue2belowEMA2[shift] = EMPTY_VALUE;
    }
 
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
    {
    
belowEMA3[shift] = 7;
    
aboveEMA3[shift] = 7;
    
double EmaValue3 iMA(NULL0EMA3Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue3aboveEMA3[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue3belowEMA3[shift] = EMPTY_VALUE;
    }
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
 
    {
    
belowEMA4[shift] = 6;
    
aboveEMA4[shift] = 6;
    
double EmaValue4 iMA(NULL0EMA4Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue4aboveEMA4[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue4belowEMA4[shift] = EMPTY_VALUE;
    }
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
    {
    
belowEMA5 [shift]= 5;
    
aboveEMA5 [shift]= 5;
    
double EmaValue5 iMA(NULL0EMA5Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue5aboveEMA5 [shift]= EMPTY_VALUE;
    if (
Close[shift]<EmaValue5belowEMA5[shift]= EMPTY_VALUE;
    }
 
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
    {
    
belowEMA6[shift] = 4;
    
aboveEMA6[shift] = 4;
    
double EmaValue6 iMA(NULL0EMA6Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue6aboveEMA6[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue6belowEMA6[shift] = EMPTY_VALUE;
    }
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
 
    {
    
belowEMA7[shift] = 3;
    
aboveEMA7[shift] = 3;
    
double EmaValue7 iMA(NULL0EMA7Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue7aboveEMA7[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue7belowEMA7[shift] = EMPTY_VALUE;
    }
 
      if (
counted_bars<0) return;
      if (
counted_bars>0counted_bars--;
      
counted_bars Bars counted_bars;
      for (
shift=0shift<counted_barsshift++)  
 
 
    {
    
belowEMA8[shift] = 2;
    
aboveEMA8[shift] = 2;
    
double EmaValue8 iMA(NULL0EMA8Period0MA_Methodapplied_priceshift);
    if (
Close[shift]>EmaValue8aboveEMA8[shift] = EMPTY_VALUE;
    if (
Close[shift]<EmaValue8belowEMA8[shift] = EMPTY_VALUE;
    }
 
 
 
        return(
0);
  }
 
 
//+------------------------------------------------------------------+ 
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stochastic system - Error tradetrade Trading Systems 11 07-26-2006 07:14 AM
coding error? Scicronys MetaTrader and ZeroCode 1 11-07-2005 07:24 AM
What is this error ? sulz MetaTrader and ZeroCode 5 07-27-2005 04:50 PM


All times are GMT. The time now is 03:53 PM.
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0

Registered members have access to special online forex currency trading tools, software, mt4 expert advisors and indicators. Register now

Main Menu

Economic Forecast