Eur usd mt4 daily candles

 

this is my ea.

it works

but it is slow

eur usd

daily chart

1000 pip a year?

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

//|

//|

//|

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

extern string ORDERComment="Order Comment Text";

extern int MAGICTerminal=101;

double prevtime = -1;

extern double LOTSize=0.10;

int MagicNumber = 1234;

void deinit() {

Comment("");

}

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

//| |

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

int start(){

if(Bars<100){

Print("bars less than 100");

return(0);

}

int btotal=0; int stotal=0; int ticket=0; double closelots=0; bool xbool;

double diclose = iClose(NULL,0,1);

double biclose = iClose(NULL,0,2);

double MA = iMA(NULL, 0, 340, 0, MODE_EMA, PRICE_OPEN, 1);

double MAA = iMA(NULL, 0, 340, 0, MODE_EMA, PRICE_OPEN, 2);

if((diclose>MA) && (biclose<MAA) )

{

if (prevtime==Time[0]) return(0);

closesSELL();

// ticket=OrderSend(Symbol(),OP_BUY,LOTSize,Ask,5,30,50,ORDERComment,0,0,Magenta);

ticket=OrderSend(Symbol(),OP_BUY,LOTSize,Ask,5,0,0,ORDERComment,0,0,Magenta);

prevtime=Time[0];

}

if((dicloseMAA))

{

if (prevtime==Time[0]) return(0);

closesBUY();

// ticket=OrderSend(Symbol(),OP_SELL,LOTSize,Bid,5,30,50,ORDERComment,0,0,Lime);

ticket=OrderSend(Symbol(),OP_SELL,LOTSize,Bid,5,0,0,ORDERComment,0,0,Lime);

prevtime=Time[0];

}

}

// }

void closesBUY()

{

int total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

break;

//Close opened short positions

//case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

}

if(result == false)

{

//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

Sleep(0);

}

}

}

void closesSELL()

{

int total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

//Close opened long positions

//case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

break;

}

if(result == false)

{

//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

Sleep(0);

}

}

}

/*

int My_Orders()

{

int

Order_Count = 0;

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

if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)){

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

}

}

return(Order_Count);

}

*/

 

i retested it and the results suck.

i don't know what i changed.

but it seems i chnaged something.

 

If current price is higher than last MA (period 340 omg) and old price was lower that previous MA, open buy/close sell (and buy, if any). Same thing with sell.

Next time I recommend attaching mq4 file instead of posting its code.

PS: why close both buys and sells when new buy/sell signal received? I usually only close buy when receiving sell signal, close sell when receiving buy signal...