Anyone convert Macdonchart metatrader to Amibroker

aggy

Active Member
#1
//+------------------------------------------------------------------+
//| #!MACDonchart.mq4 |
//| Copyright @2011, Rockyhoangdn |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright @2011, Rockyhoangdn"
#property link "[email protected]"

#property copyright "Copyright 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Green
#property indicator_color2 Coral
#property indicator_color3 Aqua
#property indicator_color4 Red
#property indicator_color5 Magenta
#property indicator_color6 DeepPink
#property indicator_color7 Aqua

#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 2
#property indicator_width7 2

//---- indicator parameters
extern int FastEMA=8;
extern int SlowEMA=50;
extern int SignalSMA=9;

//---- indicator buffers
double ind_buffer3a[];
double ind_buffer3b[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
double ind_buffer7[];
double ind_buffer8[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(7);
//---- drawing settings

SetIndexStyle(0,DRAW_NONE);
SetIndexDrawBegin(0,SignalSMA);
SetIndexLabel(0,"Up Trend");
SetIndexStyle(1,DRAW_NONE);
SetIndexDrawBegin(1,SignalSMA);
SetIndexLabel(1,"Down Trend");
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,ind_buffer4);

SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(3,ind_buffer6);

SetIndexStyle(4,DRAW_SECTION);
SetIndexBuffer(4,ind_buffer6);
SetIndexLabel(4,"Zigzag value");
SetIndexStyle(5,DRAW_ARROW);
SetIndexBuffer(5,ind_buffer7);
SetIndexLabel(5,"Short Entry");
SetIndexArrow(5, 222);
SetIndexStyle(6,DRAW_ARROW);
SetIndexBuffer(6,ind_buffer8);
SetIndexLabel(6,"Long Entry");
SetIndexArrow(6, 221);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

//---- 5 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer3a) &&
!SetIndexBuffer(1,ind_buffer3b) &&
!SetIndexBuffer(2,ind_buffer4) &&
!SetIndexBuffer(3,ind_buffer5) &&
!SetIndexBuffer(4,ind_buffer6))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD ("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
int start()
{
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;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ind_buffer4=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)
-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ind_buffer5=iMAOnArray(ind_buffer4,Bars,SignalSMA,0,MODE_EMA,i);
//---- main loop
double value=0;
for(i=0; i<limit; i++)
{
ind_buffer3a=0.0;
ind_buffer3b=0.0;
value=ind_buffer4-ind_buffer5;
if (value>0) ind_buffer3a=value;
if (value<0) ind_buffer3b=value;
if ( value == 0)ind_buffer6=value;
}
for(i=0; i<limit; i++)
{
if ( ind_buffer3a[i+1]!= 0 && ind_buffer3b!=0)
{
ind_buffer6=Open;
ind_buffer7=Open;
}
else
{
ind_buffer7=0;
}
if ( ind_buffer3b[i+1]!= 0 && ind_buffer3a!=0)
{
ind_buffer6=Open;
ind_buffer8=Open;
}
else
{
ind_buffer8=0;
}
}

//---- done
return(0);
}
//+------------------------------------------------------------------+


thanks in advance