Need Help for this Expert Advisor "FirefilyEA

Please can someone assist me review this EA i just design but still having error and takes too long to start like 5 miniutes please i need your help if you can edit you can send the code to me e-mail: hamabdul11@yahoo.com thanks

code:

//+------------------------------------------------------------------+
//| FireFly EA.mq4 |
//| Copyright © 2008, SuperHamza |
//| hamabdul11@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, SuperHamza"
#property link "hamabdul11@yahoo.com"

extern int
MagicNumber = 12345,
Slippage = 2,
TakeProfit = 40,
StopLoss = 20,
TrailingStop = 20,
TSMinProfit = 0;
extern double
Lots = 0.1;
extern bool
WaitForBarClose = true,
OneEntryPerBar = true;

datetime entrytime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int ticket = 0;
int shift = 0;
if(WaitForBarClose)
{
shift = 1;
}

double Stoch = iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN, shift);
double Envy = StochEnvyVal(shift);
double StochLast = iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN, shift+1);
double EnvyLast = StochEnvyVal(shift+1);

double RSI = iRSI(Symbol(),0,3,PRICE_CLOSE, shift);
Comment("Stoch: "+Stoch+" |RSI: "+RSI+" |Envy: "+Envy);

//----------------------- TRAILING STOP
if(TrailingStop>0 && subTotalTrade()>0)
{
int total = OrdersTotal();
for(int cnt=0;cnt {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber)
{
subTrailingStop(OrderType());
}
}
}
if(!OneEntryPerBar)
{
entrytime = 0;
}
if(subTotalTrade()<1)
{
//OP_BUY
if((Stoch>Envy&&StochLast50)&&entry time!=iTime(Symbol(),0,0))
{
ticket = subOpenOrder(OP_BUY, Lots, StopLoss, TakeProfit,MagicNumber);
if(ticket>0)entrytime=iTime(Symbol(),0,0);
}
//OP_SELL
if((StochEnvyLast&&RSI<50)&&entry time!=iTime(Symbol(),0,0))
{
ticket = subOpenOrder(OP_SELL, Lots, StopLoss, TakeProfit,MagicNumber);
if(ticket>0)entrytime=iTime(Symbol(),0,0);
}
}

if((subTotalTrade()>0)&&entrytime!=iTime(Symbol(), 0,0))
{
//CLOSE_SELL
if(Stoch>Envy)
{
subCloseOrder(OP_SELL);
}
//CLOSE_BUY
if(Stoch {
subCloseOrder(OP_BUY);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
double StochEnvyVal(int shift)
{
double stoch[];
ArrayResize(stoch, Bars);
ArraySetAsSeries(stoch,true);
for(int i=Bars; i>=0; i--)
{
stoch[i]=iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN ,i+shift);
}
double envy = iEnvelopesOnArray(stoch, 0, 41, MODE_LWMA, 0, 70, MODE_LOWER, 0) ;
return(envy);
}

int subOpenOrder(int type, double Lotz, int stoploss, int takeprofit,int MagicNumber)
{
int NumberOfTries = 15;
string TicketComment = "FireFly EA";
int
ticket = 0,
err = 0,
c = 0;

double
aStopLoss = 0,
aTakeProfit = 0,
bStopLoss = 0,
bTakeProfit = 0;

if(stoploss!=0)
{
aStopLoss = NormalizeDouble(Ask-stoploss*Point,4);
bStopLoss = NormalizeDouble(Bid+stoploss*Point,4);
}

if(takeprofit!=0)
{
aTakeProfit = NormalizeDouble(Ask+takeprofit*Point,4);
bTakeProfit = NormalizeDouble(Bid-takeprofit*Point,4);
}

if(type==OP_BUY)
{
for(c=0;c {
ticket=OrderSend(Symbol(),OP_BUY,Lotz,Ask,Slippage ,aStopLoss,aTakeProfit,TicketComment,MagicNumber,0 ,Green);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
}
if(type==OP_SELL)
{
for(c=0;c {
ticket=OrderSend(Symbol(),OP_SELL,Lotz,Bid,Slippag e,bStopLoss,bTakeProfit,TicketComment,MagicNumber, 0,Red);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
}
return(ticket);
}
//----------------------- CLOSE ORDER FUNCTION
void subCloseOrder(int TYPE)
{
int
NumberOfTries=10,
cnt,
total = 0,
ticket = 0,
err = 0,
c = 0;

total = OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==TYPE&&OrderSymbol() == Symbol() &&
OrderMagicNumber()==MagicNumber)
{
switch(OrderType())
{
case OP_BUY :
for(c=0;c {
ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Sl ippage,Violet);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
break;

case OP_SELL :
for(c=0;c {
ticket=OrderClose(OrderTicket(),OrderLots(),Ask,Sl ippage,Violet);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
break;

case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT:
case OP_SELLSTOP :
OrderDelete(OrderTicket());
}
}
}
}
int subTotalTrade()
{
int
cnt,
total = 0;

for(cnt=0;cnt {
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber) total++;
}
return(total);
}
void subTrailingStop(int Type)
{
if(Type==OP_BUY) // buy position is opened
{
//----------------------- AFTER PROFIT TRAILING STOP

if(Bid-OrderOpenPrice()>Point*TSMinProfit &&
OrderStopLoss() {
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}

}
if(Type==OP_SELL) // sell position is opened
{
//----------------------- TRAILING STOP AFTER PROFIT

if(OrderOpenPrice()-Ask>Point*TSMinProfit)
{
if(OrderStopLoss()>Ask+Point*TrailingStop || OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}

}
}

//+------------------------------------------------------------------+
//End End End End End End End End End End End End|
//+------------------------------------------------------------------+

Hi hamabdul11, i was tried

Hi hamabdul11, i was tried but there is some error. Maybe you can paste again the code.

Compiling 'FirefilyEA.mq4'...

'StochLast50' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (87, 17)

'entry' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (87, 31)

'time' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (87, 37)

'StochEnvyLast' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (93, 5)

'entry' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (93, 29)

'time' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (93, 35)

'Slippag' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (185, 44)

'e' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (185, 52)

'Sl' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (231, 49)

'ippage' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (231, 52)

'Sl' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (255, 49)

'ippage' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (255, 52)

'Poi' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (321, 48)

'nt' - variable not defined C:\Program Files\Interbank FX Trader 4 - offline\experts\FirefilyEA.mq4 (321, 52)

14 error(s), 0 warning(s)

====================================================================

FAQ | Ask to FAQ Privacy policy | Term of use |

Today Content *

Our sponsor*

Visit this page : FAQ | Ask a question | Privacy policy | Term of use | Risk warning | Contact Us
© 2008 AutoTradingFx.com, All rights reserved.