Ema Cross! - page 4

 

Ema Cross Version?

SpecII:
Hi,

My foward test from EMACross D1 TF

Cheers

hello SpecII,

Thank you very much for sharing us!

What's the version of EMA_CROSS you have used?

 

Multiple pairs!

SpecII:
Hi Codersguru

i'm use version no SL but i have modified the code for multiple pairs and made bug for double lots hehe.

i will fixed the bug for double lots later.

Cheers

Thanks again ! Could I see your code for multiple pairs?

 
codersguru:
Thanks again ! Could I see your code for multiple pairs?

Hi,I'm posting the code.It's right?

Thanks

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

//| EMA_CROSS.mq4 |

//| Coders Guru |

//| https://www.forex-tsd.com |

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

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

//| TODO: Add Money Management routine |

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

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit=130;

extern double Lots=1;

extern double TrailingStop=20;

extern int ShortEma = 10;

extern int LongEma = 80;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

//Don't work in the first load, wait for the first cross!

static bool first_time = true;

if(first_time == true)

{

first_time = false;

return (0);

}

if(line1>line2)current_direction = 1; //up

if(line1<line2)current_direction = 2; //down

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0); //not changed

}

}

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

//| expert start function |

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

int start()

{

int OrdersPerSymbol=0;

//----

int cnt, ticket;

double SEma, LEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

OrdersPerSymbol=0;

for(cnt=OrdersTotal();cnt>=0;cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol()==Symbol() )

{

OrdersPerSymbol++;

}

}

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);

LEma = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,0);

static int isCrossed = 0;

isCrossed = Crossed (LEma,SEma);

// total = OrdersTotal();

if(OrdersPerSymbol < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"EMA_CROSS",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"EMA_CROSS",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

//OrderPrint();

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

/* REMOVED - Trailling stop only close

if(isCrossed == 2)

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

return(0); // exit

}

*/

// check for trailing stop

if(TrailingStop>0)

{

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

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

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

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

/* REMOVED - Trailling stop only close

if(isCrossed == 1)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position

return(0); // exit

}

*/

// check for trailing stop

if(TrailingStop>0)

{

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

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

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

return(0);

}

}

}

}

}

}

return(0);

}

//+------------------------------------------------------------------+
 
codersguru:
hello SpecII,

Thank you very much for sharing us!

What's the version of EMA_CROSS you have used?

Hi Codersguru

i'm use version no SL but i have modified the code for multiple pairs and made bug for double lots hehe.

i will fix the bug for double lots later.

Cheers

 

Inverse

To me it looks like an inverse.

The code is set to buy when the long EMA becomes greater then the short EMA

and to sell when the long EMA moves below the short EMA.

I suppose that is why it is successful - as one is taught to do the exact opposite elsewhere.

I am also getting multiple trades, on the first version of the EA, I still have to try the second version. Is this due to incorrect history data?

I will test tonight.

Thanks

 

so

so one buys when the Sema moves below the Lema

and sells when the Sema moves above the Lema

Or am I confused again?

 

when I attach ea

When I attach the ea to a chart I get a 'X' - no smilling face - on the ea or on me.

got it working - had to hit the play experts button.

 

Hello,

I am spirit to test this EA with an account demonstration. The first impressions are very good. For the moment it opens only one pair in spite of 4 open diagrams. But with each opening of Trades it is in the good positive direction and it rest. I statement attach you since yesterday.

 
BrunoFX:
Hello, I am spirit to test this EA with an account demonstration. The first impressions are very good. For the moment it opens only one pair in spite of 4 open diagrams. But with each opening of Trades it is in the good positive direction and it rest. I statement attach you since yesterday.

I modified this EA to use magic number. That will provide trade on multi pairs at one time. Change maigc param for to be difrent for every pair.

Files:
 

Hello Kalenzo,

Thank you for this modification, always also fast and effective, cheer