MA DoubleCross

Post Reply
User avatar
dynel14
Trader
Posts: 37
Joined: Wed Nov 16, 2011 1:38 am
Location: Cologne/Germany

MA DoubleCross

Post by dynel14 »

Hi @ll,

hope everyone is doing well...

I have a problem with the indicator I've made, well I've tried it :? .

Here is the code:

Code: Select all

/*------------------------------------------------------------------------------------
   Name: MA DoubleCross.mq4
   Copyright ©2012, dynel14
   
   Description: MA DoubleCross
	          
   Change log: 
       2012-11-28. dynel14, v1.00 
          - First Release 
-------------------------------------------------------------------------------------*/
// Indicator properties
#property copyright "Copyright © 2012, dynel14"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Crimson
#property indicator_width1 4
#property indicator_width2 4
#property indicator_maximum 1
#property indicator_minimum 0

// Constant definitions
#define INDICATOR_NAME "MA DoubleCross Signal"
#define INDICATOR_VERSION "v1.00"

// Indicator parameters
extern string Version_Info = INDICATOR_VERSION;
extern string Moving_Average_Settings = "——————————————————————————————";
extern int       MA_Period1 = 10;
extern int       MA_Period2 = 20;
extern string    Method = "0=SMA, 1=EMA, 2=SMMA, 3=LWMA";
extern int       MA_Method1 = MODE_SMA;
extern int       MA_Method2 = MODE_SMA;
extern string    Price1 = "0=Close, 1=Open, 2=High, 3=Low";
extern string    Price2 = "4=Median, 5=Typical, 6=Weighted";
extern int       MA_Price1 = PRICE_CLOSE;
extern int       MA_Price2 = PRICE_CLOSE;

// Global module varables
double TrendUP[];
double TrendDOWN[];
double C[], MA1[], MA2[];


//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init() 
   {
   IndicatorBuffers(8);
   IndicatorDigits(Digits);
   SetIndexBuffer(0, TrendUP);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(1, TrendDOWN);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(2, MA1);
   SetIndexBuffer(3, MA2);
   SetIndexBuffer(4, C);
   IndicatorShortName(INDICATOR_NAME);
   return(0);
}


//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit() {
   return (0);
}


///----------------------------------------------------------------------------
// function: start()
// Description: Custom indicator iteration function.
//-----------------------------------------------------------------------------
int start() {
   int i, iNewBars, iCountedBars;

   // Get unprocessed ticks
   iCountedBars = IndicatorCounted();
   if(iCountedBars < 0) return(-1);
   if(iCountedBars > 0) iCountedBars--;
   iNewBars = Bars - iCountedBars; 

   for(i = 0; i < iNewBars ; i++) {
     MA1[i] = iMA(NULL, 0, MA_Period1, 0, MA_Method1, MA_Price1, i);
     MA2[i] = iMA(NULL, 0, MA_Period2, 0, MA_Method2, MA_Price2, i);
     C[i] = iClose(NULL, 0, i);

     if( (C[i] > MA1[i]) && (C[i] > MA2[i]) ) {
         TrendUP[i] = 1;
         TrendDOWN[i] = 0;
     }
     else if( (C[i] < MA1[i]) && (C[i] < MA2[i]) ) {
         TrendUP[i] = 0;
         TrendDOWN[i] = 1;
     }
   }
   return(0);
  }
//+------------------------------------------------------------------+
The problem is that sometimes the bars are not "refreshing". Maybe there is something wrong with the buffers, I don't know. Thats why I'm asking for help.

Thank you very much.

Regards,
dynel
Post Reply

Return to “Indicators”