MACD with 2 Colour Histogram + 2 Lines
MACD with 2 Colour Histogram + 2 Lines
13 Jul 2013, 12:34
Hello,
Could anyone help with this MACD 2 Colour Histogram with 2 MA - I had it in MT4.
Replies
algotrader
14 Jul 2013, 02:01
RE:
I tried it with 2calgo.com and it doesn't. It only converts 40% of MT4 EA's - and why would I trust and automated code converter?
Could you post your indicator here?
@algotrader
Mocean
14 Jul 2013, 02:14
Thanks algotrader, any help is appeciated.
//+------------------------------------------------------------------+
//| MACD_ColorHist_Alert.mq4 |
//| Copyright © 2006, Robert Hill |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Robert Hill"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
//---- indicator parameters
extern bool SoundON=False;
extern bool EmailON=false;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double HistogramBufferUp[];
double HistogramBufferDown[];
int flagval1 = 0;
int flagval2 = 0;
//---- variables
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
// IndicatorBuffers(3);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(0,ind_buffer1);
SetIndexDrawBegin(0,SlowEMA);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(1,ind_buffer2);
SetIndexDrawBegin(1,SignalSMA);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(2,HistogramBufferUp);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(3,HistogramBufferDown);
// SetIndexDrawBegin(2,SlowEMA + SignalSMA);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"Histogram");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
double temp;
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;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
ind_buffer1[i]=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 buffer
for(i=0; i<limit; i++)
ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
// ind_buffer2[i] = alpha*ind_buffer1[i] + alpha_1*ind_buffer2[i+1];
for(i=0; i<limit; i++)
{
HistogramBufferUp[i] = 0;
HistogramBufferDown[i] = 0;
temp = ind_buffer1[i] - ind_buffer2[i];
if (temp >= 0)
HistogramBufferUp[i] = temp;
else
HistogramBufferDown[i] = temp;
if (i == 1)
{
if (HistogramBufferUp[i] > 0 && HistogramBufferDown[i + 1] < 0)
// if (HistogramBufferUp[i] > HistogramBufferUp[i + 1])
{
// Cross up
if (flagval1==0)
{
flagval1=1;
flagval2=0;
if (SoundON) Alert ("Macd Cross Up! ",Symbol()," ",Period()," @ ",Bid);
if (EmailON) SendMail("MACD Crossed up", "MACD Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
}
}
else if (HistogramBufferDown[i] < 0 && HistogramBufferUp[i + 1] > 0)
// else if (HistogramBufferUp[i] < HistogramBufferUp[i + 1] )
{
// Cross down
if (flagval2==0)
{
flagval2=1;
flagval1=0;
if (SoundON) Alert ("Macd Cross Down! " ,Symbol()," ",Period()," @ ",Bid);
if (EmailON) SendMail("MACD Crossed down","MACD Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
}
}
}
}
//---- done
return(0);
}
@Mocean
algotrader
14 Jul 2013, 02:43
I removed send email functionallity from your code (not supported yet).
Convert this code:
//+------------------------------------------------------------------+ //| MACD_ColorHist_Alert.mq4 | //| Copyright © 2006, Robert Hill | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Robert Hill" //---- indicator settings #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 Lime #property indicator_color4 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 //---- indicator parameters extern bool SoundON=False; extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double ind_buffer1[]; double ind_buffer2[]; double HistogramBufferUp[]; double HistogramBufferDown[]; int flagval1 = 0; int flagval2 = 0; //---- variables //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings // IndicatorBuffers(3); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID); SetIndexBuffer(0,ind_buffer1); SetIndexDrawBegin(0,SlowEMA); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID); SetIndexBuffer(1,ind_buffer2); SetIndexDrawBegin(1,SignalSMA); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(2,HistogramBufferUp); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(3,HistogramBufferDown); // SetIndexDrawBegin(2,SlowEMA + SignalSMA); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")"); SetIndexLabel(0,"MACD"); SetIndexLabel(1,"Signal"); SetIndexLabel(2,"Histogram"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { int limit; double temp; 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; //---- macd counted in the 1-st buffer for(int i=0; i<limit; i++) ind_buffer1[i]=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 buffer for(i=0; i<limit; i++) ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i); // ind_buffer2[i] = alpha*ind_buffer1[i] + alpha_1*ind_buffer2[i+1]; for(i=0; i<limit; i++) { HistogramBufferUp[i] = 0; HistogramBufferDown[i] = 0; temp = ind_buffer1[i] - ind_buffer2[i]; if (temp >= 0) HistogramBufferUp[i] = temp; else HistogramBufferDown[i] = temp; if (i == 1) { if (HistogramBufferUp[i] > 0 && HistogramBufferDown[i + 1] < 0) // if (HistogramBufferUp[i] > HistogramBufferUp[i + 1]) { // Cross up if (flagval1==0) { flagval1=1; flagval2=0; if (SoundON) Alert ("Macd Cross Up! ",Symbol()," ",Period()," @ ",Bid); } } else if (HistogramBufferDown[i] < 0 && HistogramBufferUp[i + 1] > 0) // else if (HistogramBufferUp[i] < HistogramBufferUp[i + 1] ) { // Cross down if (flagval2==0) { flagval2=1; flagval1=0; if (SoundON) Alert ("Macd Cross Down! " ,Symbol()," ",Period()," @ ",Bid); } } } } //---- done return(0); }
@algotrader
algotrader
14 Jul 2013, 03:20
RE:
3 Errors - Unreachable code?
it is warnings, build is succeeded
@algotrader
algotrader
14 Jul 2013, 03:23
just add instance of indicator, regardless compilation warnings
@algotrader
Mocean
14 Jul 2013, 03:34
Thanks 2calgo - are you interested in some paid programming? Do you have a direct contact, email?
I am hoping Spotwre will get it right with this "Advanced Protection" feature coming out in the next version release, but chances are they only get some of the fetures needed.
@Mocean
algotrader
14 Jul 2013, 03:40
( Updated at: 21 Dec 2023, 09:20 )
RE:
Thanks 2calgo - are you interested in some paid programming? Do you have a direct contact, email?
I am hoping Spotwre will get it right with this "Advanced Protection" feature coming out in the next version release, but chances are they only get some of the fetures needed.
Thank Mocean for your proposal, but I am not interested in paid programming.
Regarding your MACD indicator: I tried to add it to MetaTrader, but it works exactly as converted one:
Could you please check that your code is for corresponding indicator?
@algotrader
Mocean
14 Jul 2013, 04:17
Opps - Sorry about that algotrader - here is the corerct code, but again I tried it in 2algo.com and it ddn't work. I did a search for the email routine but couldn't find it?
//+------------------------------------------------------------------+
//| MACD_OsMA_ColorLH.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| mod. Variable MA settings http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
// 2008forextsd mtf keris f-la ki
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 C'83,0,0' //Maroon
#property indicator_color4 C'0,66,0' //DarkGreen
#property indicator_color5 DodgerBlue
#property indicator_color6 Chocolate
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
//---- indicator buffers
extern int TimeFrame = 0;
extern int FastMA_Period=12;
extern int SlowMA_Period=26;
extern int SignalMA_Period=9;
extern int FastMA_Mode=1;
extern int SlowMA_Mode=1;
extern int SignalMA_Mode=0;
extern int FastMA_Price=0;
extern int SlowMA_Price=0;
//extern int SignalMA_Price=0; // ma on array - price Close only
extern double OsmaMultiplier = 2.5;
extern bool ShowOsMA_Histo = true;
extern bool ShowMACD_Histo = false;
extern int MaxBarsToCount = 1500;
extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string note_AppliedPrice = "0C,1O 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string note_MA_Mode = "SMA0 EMA1 SMMA2 LWMA3";
extern string note_defaults = "AO:34,5;SMA;PriceMedian(4);MACD 12 26 9 EMA Close;SignalLinePrice- Close only(MaOnArray) ";
double ind_buffer1[], ind_buffer1s[];
double ind_buffer2[], ind_buffer2s[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- additional buffer used for counting.
IndicatorBuffers(8);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,SlowMA_Period);
SetIndexDrawBegin(1,SlowMA_Period);
SetIndexDrawBegin(2,SlowMA_Period);
SetIndexDrawBegin(3,SlowMA_Period);
SetIndexDrawBegin(4,SlowMA_Period);
SetIndexDrawBegin(5,SlowMA_Period);
//---- indicator buffers mapping
SetIndexBuffer(0,ind_buffer1) ;
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer1s) &&
!SetIndexBuffer(2,ind_buffer2) &&
!SetIndexBuffer(3,ind_buffer2s) &&
!SetIndexBuffer(4,ind_buffer3) &&
!SetIndexBuffer(5,ind_buffer4) &&
!SetIndexBuffer(6,ind_buffer5) &&
!SetIndexBuffer(7,ind_buffer6))
Print("cannot set indicator buffers!");
switch(TimeFrame)
{
case 1: string TimeFrameStr = "M1"; break;
case 5 : TimeFrameStr = "M5"; break;
case 15 : TimeFrameStr = "M15"; break;
case 30 : TimeFrameStr = "M30"; break;
case 60 : TimeFrameStr = "H1"; break;
case 240 : TimeFrameStr = "H4"; break;
case 1440 : TimeFrameStr = "D1"; break;
case 10080 : TimeFrameStr = "W1"; break;
case 43200 : TimeFrameStr = "MN1"; break;
default : TimeFrameStr = "TF0";
}
//---- name for DataWindow and indicator subwindow label
SetIndexLabel(0,"");
SetIndexLabel(1,"");
SetIndexLabel(2,"");
SetIndexLabel(3,"");
SetIndexLabel(4,"MACD");
SetIndexLabel(5,"SigL");
IndicatorShortName("MACD_OsMA ["+TimeFrameStr+"] ("+FastMA_Period+","+SlowMA_Period+","+SignalMA_Period+") ");
if (TimeFrame < Period()) TimeFrame = Period();
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Awesome Oscillator |
//+------------------------------------------------------------------+
int start()
{
double prev,current;
datetime TimeArray[],TimeArray1[];
int i,limit,y=0,counted_bars=IndicatorCounted();
//----
ArrayCopySeries(TimeArray, MODE_TIME,Symbol(),TimeFrame);
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit= Bars-counted_bars;
limit= MathMax(limit,TimeFrame/Period());
limit= MathMin(limit,MaxBarsToCount);
for(i=0,y=0; i<limit; i++)
{
if (Time[i]<TimeArray[y]) y++;
ind_buffer3[i]=iMA(NULL,TimeFrame,FastMA_Period,0,FastMA_Mode,FastMA_Price,y)-
iMA(NULL,TimeFrame,SlowMA_Period,0,SlowMA_Mode,SlowMA_Price,y);
ind_buffer5[y]= ind_buffer3[i];
}
limit = MathMin(limit, MaxBarsToCount-SignalMA_Period);
for(y=0,i=0; i<limit; i++)
{
if (Time[i]<TimeArray[y]) y++;
ind_buffer4[i]=iMAOnArray(ind_buffer5,0,SignalMA_Period,0,SignalMA_Mode,y);
ind_buffer6[i]= (ind_buffer3[i]- ind_buffer4[i])*OsmaMultiplier;
}
//---- dispatch values between 2 buffers
bool up=true;
for (i=limit;i>=0;i--)
{
ind_buffer1[i] =0.0;
ind_buffer1s[i]=0.0;
ind_buffer2[i] =0.0;
ind_buffer2s[i]=0.0;
if (ShowOsMA_Histo)
{
current=ind_buffer6[i];
prev=ind_buffer6[i+1];
}
if (ShowMACD_Histo)
{
current =ind_buffer3[i];
prev =ind_buffer3[i+1];
}
if(current>prev) up=true;
else up=false;
if(up)
{
if(current > 0)
{
ind_buffer1[i]=current;
ind_buffer1s[i]=0.0;
ind_buffer2[i] =0.0;
ind_buffer2s[i]=0.0;
}
else
{
ind_buffer1[i] =0.0;
ind_buffer1s[i]=current;
ind_buffer2[i] =0.0;
ind_buffer2s[i]=0.0;
}
}
else
{
if(current < 0)
{
ind_buffer1[i] =0.0;
ind_buffer1s[i]=0.0;
ind_buffer2[i] =current;
ind_buffer2s[i]=0.0;
}
else
{
ind_buffer1[i] =0.0;
ind_buffer1s[i]=0.0;
ind_buffer2[i] =0.0;
ind_buffer2s[i]=current;
}
}
}
for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-MaxBarsToCount+SignalMA_Period);
//---- done
return(0);
}
@Mocean
algotrader
14 Jul 2013, 04:46
Last indicator uses Multi-time frame feature.
Unfortunatelly, cAlgo doesn't support Multi-time frame at the moment. Regarding /forum/cbot-support/1191 cAlgo will support multi-time frame in 3 months.
As soon as cAlgo will support multi-time frame, 2calgo will support such indicators.
@algotrader
algotrader
13 Sep 2013, 08:15
Mocean, now your indicator is supported by http://2calgo.com
@algotrader
algotrader
13 Jul 2013, 23:43
You can convert it with 2calgo.com
@algotrader