EA Based on Custom Indicator - 80% Job Done - Please HELP

 

Hi zere !

I downloaded a MACD type custom indicator from internet, according to which we BUY when it is above 0 and SELL when below 0.

I made an EA from Forexeadvisor.com...now the only difficulty is to get the EA recognise the custom indicator, for which your kind help is sought. I am attaching the code for your kind consideration. Can an expert please have a look at the code and tell me what to put inside the code to recognise the custom indicator (the custom indicator is already in my experts/indicators directory and an ex4 file).

The custom indicator's name is MACD v1.2 and if its above 0, we buy and below 0, we sell.

I don't know what's wrong, may be something is missing.

Here the EA code:

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

// DO NOT DELETE THIS HEADER

// DELETING THIS HEADER IS COPYRIGHT INFRIGMENT

//

// Copyright ©2011, ForexEAdvisor.com

// ForexEAdvisor Strategy Builder version 0.2

// http://www.ForexEAdvisor.com

//

// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2

// on: 1/31/2013 11:50:41 PM

// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty

// or liability obligations to you of any kind.

// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,

// FOR ANY LOMACD OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR

// ECONOMIC LOMACD OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,

// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR

// FOREXEADVISOR STRATEGY BUILDER

// Because software is inherently complex and may not be completely free of errors, you are

// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder

// license for a complete understanding of ForexEAdvisor' disclaimers.

// USE THIS EA AT YOUR OWN RISK.

//

// Before adding this expert advisor to a chart, make sure there are NO

// open positions.

// DO NOT DELETE THIS HEADER

// DELETING THIS HEADER IS COPYRIGHT INFRIGMENT z

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

extern int MagicNumber=77885;

extern double Lots =0.1;

extern double StopLoss=0;

extern double TakeProfit=0;

extern int TrailingStop=0;

extern int Slippage=3;

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

// expert start function

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

int start()

{

double MyPoint=Point;

if(Digits==3 || Digits==5) MyPoint=Point*10;

double TheStopLoMACD=0;

double TheTakeProfit=0;

if( TotalOrdersCount()==0 )

{

int result=0;

if((iCustom(Symbol(),0,0,"MACD v1.2",0)>0)) // Here is your open buy rule

{

result=OrderSend(Symbol(),OP_BUY,AdvancedMM(),Ask,Slippage,0,0,"MACD BUY",MagicNumber,0,Blue);

if(result>0)

{

TheStopLoMACD=0;

TheTakeProfit=0;

if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;

if(StopLoMACD>0) TheStopLoMACD=Ask-StopLoMACD*MyPoint;

OrderSelect(result,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoMACD,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

}

return(0);

}

if((iCustom(Symbol(),0,0,"MACD v1.2",0)<0)) // Here is your open Sell rule

{

result=OrderSend(Symbol(),OP_SELL,AdvancedMM(),Bid,Slippage,0,0,"MACD SELL",MagicNumber,0,Red);

if(result>0)

{

TheStopLoMACD=0;

TheTakeProfit=0;

if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;

if(StopLoMACD>0) TheStopLoMACD=Bid+StopLoMACD*MyPoint;

OrderSelect(result,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoMACD,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

}

return(0);

}

}

for(int cnt=0;cnt<OrdersTotal();cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL &&

OrderSymbol()==Symbol() &&

OrderMagicNumber()==MagicNumber

)

{

if(OrderType()==OP_BUY)

{

if((iCustom(Symbol(),0,0,"MACD v1.2",0)<0)) //here is your close buy rule

{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

}

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

{

if(OrderStopLoMACD()<Bid-MyPoint*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else

{

if((iCustom(Symbol(),0,0,"MACD v1.2",0)>0)) // here is your close sell rule

{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

}

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

{

if((OrderStopLoMACD()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoMACD()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

int TotalOrdersCount()

{

int result=0;

for(int i=0;i<OrdersTotal();i++)

{

OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

if (OrderMagicNumber()==MagicNumber) result++;

}

return (result);

}

double AdvancedMM()

{

int i;

double AdvancedMMLots = 0;

bool profit1=false;

int SystemHistoryOrders=0;

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

{ OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY);

if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;

}

bool profit2=false;

int LO=0;

if(SystemHistoryOrders<2) return(Lots);

for( i=OrdersHistoryTotal()-1;i>=0;i--)

{

if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))

if (OrderMagicNumber()==MagicNumber)

{

if(OrderProfit()>=0 && profit1) return(Lots);

if( LO==0)

{ if(OrderProfit()>=0) profit1=true;

if(OrderProfit()<0) return(OrderLots());

LO=1;

}

if(OrderProfit()>=0 && profit2) return(AdvancedMMLots);

if(OrderProfit()>=0) profit2=true;

if(OrderProfit()<0 )

{ profit1=false;

profit2=false;

AdvancedMMLots+=OrderLots();

}

}

}

return(AdvancedMMLots);

}

Thanks for your kind help.

 
Shunmas:
Hi zere !

I downloaded a MACD type custom indicator from internet, according to which we BUY when it is above 0 and SELL when below 0.

I made an EA from Forexeadvisor.com...now the only difficulty is to get the EA recognise the custom indicator, for which your kind help is sought. I am attaching the code for your kind consideration. Can an expert please have a look at the code and tell me what to put inside the code to recognise the custom indicator (the custom indicator is already in my experts/indicators directory and an ex4 file).

The custom indicator's name is MACD v1.2 and if its above 0, we buy and below 0, we sell.

I don't know what's wrong, may be something is missing.

Here the EA code:

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

// DO NOT DELETE THIS HEADER

// DELETING THIS HEADER IS COPYRIGHT INFRIGMENT

//

// Copyright ©2011, ForexEAdvisor.com

// ForexEAdvisor Strategy Builder version 0.2

// http://www.ForexEAdvisor.com

//

// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2

// on: 1/31/2013 11:50:41 PM

// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty

// or liability obligations to you of any kind.

// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,

// FOR ANY LOMACD OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR

// ECONOMIC LOMACD OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,

// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR

// FOREXEADVISOR STRATEGY BUILDER

// Because software is inherently complex and may not be completely free of errors, you are

// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder

// license for a complete understanding of ForexEAdvisor' disclaimers.

// USE THIS EA AT YOUR OWN RISK.

//

// Before adding this expert advisor to a chart, make sure there are NO

// open positions.

// DO NOT DELETE THIS HEADER

// DELETING THIS HEADER IS COPYRIGHT INFRIGMENT z

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

extern int MagicNumber=77885;

extern double Lots =0.1;

extern double StopLoss=0;

extern double TakeProfit=0;

extern int TrailingStop=0;

extern int Slippage=3;

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

// expert start function

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

int start()

{

double MyPoint=Point;

if(Digits==3 || Digits==5) MyPoint=Point*10;

double TheStopLoMACD=0;

double TheTakeProfit=0;

if( TotalOrdersCount()==0 )

{

int result=0;

if((iCustom(Symbol(),0,0,"MACD v1.2",0)>0)) // Here is your open buy rule

{

result=OrderSend(Symbol(),OP_BUY,AdvancedMM(),Ask,Slippage,0,0,"MACD BUY",MagicNumber,0,Blue);

if(result>0)

{

TheStopLoMACD=0;

TheTakeProfit=0;

if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;

if(StopLoMACD>0) TheStopLoMACD=Ask-StopLoMACD*MyPoint;

OrderSelect(result,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoMACD,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

}

return(0);

}

if((iCustom(Symbol(),0,0,"MACD v1.2",0)<0)) // Here is your open Sell rule

{

result=OrderSend(Symbol(),OP_SELL,AdvancedMM(),Bid,Slippage,0,0,"MACD SELL",MagicNumber,0,Red);

if(result>0)

{

TheStopLoMACD=0;

TheTakeProfit=0;

if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;

if(StopLoMACD>0) TheStopLoMACD=Bid+StopLoMACD*MyPoint;

OrderSelect(result,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoMACD,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

}

return(0);

}

}

for(int cnt=0;cnt<OrdersTotal();cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL &&

OrderSymbol()==Symbol() &&

OrderMagicNumber()==MagicNumber

)

{

if(OrderType()==OP_BUY)

{

if((iCustom(Symbol(),0,0,"MACD v1.2",0)<0)) //here is your close buy rule

{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

}

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

{

if(OrderStopLoMACD()<Bid-MyPoint*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else

{

if((iCustom(Symbol(),0,0,"MACD v1.2",0)>0)) // here is your close sell rule

{

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

}

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

{

if((OrderStopLoMACD()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoMACD()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

int TotalOrdersCount()

{

int result=0;

for(int i=0;i<OrdersTotal();i++)

{

OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

if (OrderMagicNumber()==MagicNumber) result++;

}

return (result);

}

double AdvancedMM()

{

int i;

double AdvancedMMLots = 0;

bool profit1=false;

int SystemHistoryOrders=0;

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

{ OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY);

if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;

}

bool profit2=false;

int LO=0;

if(SystemHistoryOrders<2) return(Lots);

for( i=OrdersHistoryTotal()-1;i>=0;i--)

{

if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))

if (OrderMagicNumber()==MagicNumber)

{

if(OrderProfit()>=0 && profit1) return(Lots);

if( LO==0)

{ if(OrderProfit()>=0) profit1=true;

if(OrderProfit()<0) return(OrderLots());

LO=1;

}

if(OrderProfit()>=0 && profit2) return(AdvancedMMLots);

if(OrderProfit()>=0) profit2=true;

if(OrderProfit()<0 )

{ profit1=false;

profit2=false;

AdvancedMMLots+=OrderLots();

}

}

}

return(AdvancedMMLots);

}

Thanks for your kind help.

Hello Shunmas,

Not seeing your custom indicator will take a guess to call your custom macd would be something like this

iCustom(Symbol(),0,"MACD v1.2",fastMa,slowMa,signalMa,0,1), to catch it right when it crosses zero, you would need to do something like this

if (iCustom(Symbol(),0,"MACD v1.2",fastMa,slowMa,signalMa,0,1) > 0 && iCustom(Symbol(),0,"MACD v1.2",fastMa,slowMa,signalMa,0,2) <=0) //then buy

and would be the opposite for sell.

 

Hi Mr.Tools

Thanks for your reply.

The MACD custom indicator does't have any Fast or Slow MA. Wait, I'll attach a pic of another similar indicator and you'll see what it is doing.

Also some variable must be defined, something like int or double

Can you now change the code based on this pic ? It doesn't have Fast or Slow MA.

Thanks for your help.

Files:
 
Shunmas:
Hi Mr.Tools

Thanks for your reply.

The MACD custom indicator does't have any Fast or Slow MA. Wait, I'll attach a pic of another similar indicator and you'll see what it is doing.

Also some variable must be defined, something like int or double

Can you now change the code based on this pic ? It doesn't have Fast or Slow MA.

Thanks for your help.

Shunmas, if the indicator isn't using a two separate lengths,2 separate ma's, etc then it's not really a macd, by the picture its possible that it's a solar wind type indicator, if so, not good for an Ea.

ps) the undefined variables are probably the fastMa,slowMa, and signalMa

should be put with your external variables like this

external int fastMa = 12; //can be changed to whatever

external int slowMa = 26;//can be changed to whatever

external int signalMa = 9;//can be changed to whatever

but if it isn't a macd have no idea!!

 

Hi Mr.Tools !

Thanks for your reply. Yep its not MACD and a solar-wind type indicator.

OK, if its not good, I'll look for something else.

Many many thanks again