Jump to content

MACD2line3color


cubicrey

Recommended Posts

Hi,

 

Another MACD, color change when they r crossed. Added Price_Apply_to.

 

cheers.

 

:)

 

#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  DarkGray
#property  indicator_color2  Blue
#property  indicator_color3  Red
#property  indicator_color4  Maroon
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  2

extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern string Price_Apply_to = "0=close,1=open,2=high,3=low,4=median_price,5=typical_price,6=weighted_close";
extern int Apply_to=0;
double     MacdBuffer0[];
double     MacdBuffer1[];
double     MacdBuffer2[];
double     SignalBuffer[];
double     MacdBuffer[];
int nexttime=0;
int init()
 {
  IndicatorBuffers(5); 
  SetIndexStyle(0,DRAW_HISTOGRAM);
  SetIndexStyle(1,DRAW_HISTOGRAM);
  SetIndexStyle(2,DRAW_HISTOGRAM);
  SetIndexStyle(3,DRAW_LINE);
  SetIndexStyle(4,DRAW_NONE);
  IndicatorDigits(Digits+1);
  SetIndexBuffer(0,MacdBuffer0);
  SetIndexBuffer(1,MacdBuffer1);
  SetIndexBuffer(2,MacdBuffer2);
  SetIndexBuffer(3,SignalBuffer);
  SetIndexBuffer(4,MacdBuffer);
  IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
  SetIndexLabel(0,"MACD");
  SetIndexLabel(1,"MACD");
  SetIndexLabel(2,"MACD");   
  SetIndexLabel(3,"Signal");
  return(0);
 }

int start()
 {
  int limit;
  int counted_bars=IndicatorCounted();
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars;
  for(int i=0; i<limit; i++)
     MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,Apply_to,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,Apply_to,i);
  for(i=0; i<limit; i++)
     SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
  for(i=0; i<limit; i++)
   {
     if(MacdBuffer[i]>0 && MacdBuffer[i]>=SignalBuffer[i]) 
        {MacdBuffer1[i]=MacdBuffer[i]; MacdBuffer2[i]=0;MacdBuffer0[i]=0;}
     if(MacdBuffer[i]<0 && MacdBuffer[i]<=SignalBuffer[i]) 
        {MacdBuffer2[i]=MacdBuffer[i]; MacdBuffer1[i]=0;MacdBuffer0[i]=0;}
     if((MacdBuffer[i]>0 && MacdBuffer[i]<SignalBuffer[i])||(MacdBuffer[i]<0 && MacdBuffer[i]>SignalBuffer[i]))
        {MacdBuffer0[i]=MacdBuffer[i]; MacdBuffer1[i]=0;MacdBuffer2[i]=0;}
   }
   return(0);
 }
 

All that is necessary for evil to triumph is for good men/women to do nothing. Sharing is caring
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...