how do i get my ea to trade from the change of the color on the histogram

 

the following is the ea code. what i need to do know or do is how do i get my ea to trade from the change of the color on the macd histogram only.

also above is a picture of the indicator as you can see there is no signal line i took it out

can someone help me fix this ea please

thanks.

hustlerscreed

/+------------------------------------------------------------------+
//| EA based off of MACD1.mq4 |
//|
//| http://www.mtcoding.com |
//+------------------------------------------------------------------+


extern double LotSize=0.1;
extern int SL=50,
TP=30;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5)
{
SL*=10;
TP*=10;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double macd1=iCustom(Symbol(),0,"macd3",120,80,1,2,1);
double macd2=iCustom(Symbol(),0,"macd3",120,80,1,2,2);
double macd3=iCustom(Symbol(),0,"macd3",120,80,1,2,3);
static int trade_bar;
if(macd1<macd2 && macd2>=macd3 && TOOC()==0 && Bars-trade_bar>0){OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,NULL,0,0,Green);trade_bar=Bars;}
if(macd1>macd2 && macd2<=macd3 && TOOC()==0 && Bars-trade_bar>0){OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,0,0,NULL,0,0,Red);trade_bar=Bars;}
//----
SetSLTP();
//----
return(0);
}
//+------------------------------------------------------------------+

int TOOC()
{
int tooc;
for(int a=0;a<OrdersTotal();a++)
if(OrderSelect(a,0,0))
if(OrderSymbol()==Symbol())
tooc++;
return(tooc);
}
void SetSLTP()
{
for(int a=0;a<OrdersTotal();a++)
if(OrderSelect(a,0,0))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
RefreshRates();
if(OrderStopLoss()==0)OrderModify(OrderTicket(),OrderOpenPrice(),Bid-SL*Point,OrderTakeProfit(),0,Yellow);
RefreshRates();
if(OrderTakeProfit()==0)OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid+TP*Point,0,Yellow);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
if(OrderStopLoss()==0)OrderModify(OrderTicket(),OrderOpenPrice(),Ask+SL*Point,OrderTakeProfit(),0,Yellow);
RefreshRates();
if(OrderTakeProfit()==0)OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask-TP*Point,0,Yellow);
}
}
return;
}
 

here the indicator code

//+------------------------------------------------------------------+

//| Custom MACD.mq4 |

//| Copyright © 2004, MetaQuotes Software Corp. |

//| http://www.metaquotes.net/ |

//+------------------------------------------------------------------+

//

// ?????????? ?? ???????????? ???D

// 1. ?????????? ? ????? ??/??

// 2. ???????? ?? ??????????? ???????? ????

//

// Difference from ???D of standart

// 1. color of style of AC/AO

// 2. unvisible null bar

#property copyright "Aleksandr Pak,Almaty, 2006"

#property link "ekr-ap@mail.ru"

#property link "http://www.metaquotes.net/"

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_color3 Silver

#property indicator_width1 2

#property indicator_width2 2

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double MacdBuffer[], MacdBufferUp[], MacdBufferDown[];

double SignalBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- drawing settings

IndicatorBuffers(4);

SetIndexBuffer (0,MacdBufferUp);

SetIndexStyle (0,DRAW_HISTOGRAM);

SetIndexBuffer (1,MacdBufferDown);

SetIndexStyle (1,DRAW_HISTOGRAM);

SetIndexBuffer (2,SignalBuffer);

SetIndexStyle (2,DRAW_LINE);

SetIndexDrawBegin(2,SignalSMA);

SetIndexBuffer (3,MacdBuffer);

SetIndexStyle (3,DRAW_NONE);

SetIndexLabel (0,"Buffer 0");

SetIndexLabel (1,"Buffer 1");

SetIndexLabel (2,"Signal");

IndicatorDigits(Digits+3);

IndicatorShortName("MACD_color("+FastEMA+","+SlowEMA+","+SignalSMA+")");

return(0);

}

//+------------------------------------------------------------------+

//| Moving Averages Convergence/Divergence |

//+------------------------------------------------------------------+

int start()

{

int limit,i;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer

for(i=0; i<limit; i++)

{

MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

}

for(i=0; i<limit; i++)

{

MacdBufferDown[i]=0.0; MacdBufferUp[i]=0.0;

if(i>=1) //??? ????? ?? ??????????? ???????? ???? //break the null bar

{

if(MacdBuffer[i]-MacdBuffer[i]>=0)MacdBufferDown[i]=MacdBuffer[i]; //??????? ???????? //condition of color

else MacdBufferUp[i]=MacdBuffer[i];}

}

for(i=0; i<limit; i++) SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

return(0);

}

//+------------------------------------------------------------------+

 
can some help me
 

Different indicator index buffers are used -- when a value is present in one of the buffers, one draws red, one draws green.

Observe the values in each buffer using the DataWindow, then use iCustom() to determine when red is active and when it is active.

The color itself is not an accesible value.

 

i dont understand how do i get to the datawindow... and also i dont know how to programm mql4 or programming period this is why im asking someone to help me and fix the code for me... i would be greatly helpful and im willing to share my settings with anyone whos able to help me with this programm code...

thanks

hustlerscreed

 

This is one way you could do it

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double macd1=iCustom(Symbol(),0,"macd3",120,80,1,0,1);
double macd2=iCustom(Symbol(),0,"macd3",120,80,1,0,2);
double macd3=iCustom(Symbol(),0,"macd3",120,80,1,1,1);
double macd4=iCustom(Symbol(),0,"macd3",120,80,1,1,2);
static int trade_bar;
if(macd1>0 && macd2==0 && TOOC()==0 && Bars-trade_bar>0){OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,NULL,0,0,Green);trade_bar=Bars;}
if(macd3>0 && macd4==0 && TOOC()==0 && Bars-trade_bar>0){OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,0,0,NULL,0,0,Red);trade_bar=Bars;}
//----
 
thanks for the help fxcourt but that did not work all it does it place buys 3 bars after the histogram changes to up about the neutral line .. and it places no sales
 
phy:

Different indicator index buffers are used -- when a value is present in one of the buffers, one draws red, one draws green.

Observe the values in each buffer using the DataWindow, then use iCustom() to determine when red is active and when it is active.

The color itself is not an accesible value.


i think what your saying is the way to go but i dont know how to do it
 

Menu -- View -- DataWindow

That window shows various values for the bar that you manually point at with the mouse.

Values for the indicator indexes for the indicators in use are also shown.

From that window you can determine which indicator buffer is used to draw the green bars, and which is used to draw the red bars.

That information is helpful for programming the iCustom() command in the EA to collect that information.

You are not a programmer? I am not a teacher.

---

fxcourt (above) took a different tack, instead of reading the MACD indicator, he calculates the MACD values directly.

 

perfect i understand the values changes, Thanks much Phy

now can someone he me programm them in to the ea using icustom()

much thanks,

hustlerscreed

 

ok found the function i need to use

below is the function

heres the deal i need to

buy when buffer 0 is greater than -0.00000 && buffer 1 is absolute 0.00000

sell when buffer 0 is absolute 0.00000 && buffer 1 is greater then -0.00000

bool SetIndexBuffer( int index, double array[])
Binds the array variable declared at a global level to the custom indicator pre-defined buffer. The amount of buffers needed to calculate the indicator is set with the IndicatorBuffers() function and cannot exceed 8. If it succeeds, TRUE will be returned, otherwise, it will be FALSE. To get the extended information about the error, one has to call the GetLastError() function.

Parameters:

index - Line index. Must lie between 0 and 7.
array[] - Array that stores calculated indicator values.

Sample:
  double ExtBufferSilver[];
  int init()
    {
      SetIndexBuffer(0, ExtBufferSilver); // first line buffer
      // ...
    }
Reason: