Lesson 16 - Your First Expert Advisor (Part 4) - page 2

 
DojiSan:
Hi Guru, Could you make a small tutorial on how to open orders at the same time when eA is attached to different pairs? (the tutorial trades only one at a time.) I would like to trade many at a time, is this possible?

Please check this article:

http://www.metatrader.info/node/124

 

Thank you Codersguru. I am learning a lot from your lessons.

There is one question I would like to ask you.

Looks like your Expert Advisor is opening order at any time when 8/13ema cross takes place.

My question is what to do to force EA to open order exactly at the end of the candle, when the cross is really confirmed?

Regards

Govinda

 
govinda:
Thank you Codersguru. I am learning a lot from your lessons.

There is one question I would like to ask you.

Looks like your Expert Advisor is opening order at any time when 8/13ema cross takes place.

My question is what to do to force EA to open order exactly at the end of the candle, when the cross is really confirmed?

Regards

Govinda

Hi Govinda,

Thanks for you interest!

Use the cross of the previous bars:

trend1 = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,1);

trend2 = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,2);

trend3 = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,1);

trend4 = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,2);

bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;

if(trend1 > trend2 && trend3 < trend4)

{

BuyCondition = true;

CloseSellCondition = true;

}

if(trend1 trend4)

{

SellCondition = true;

CloseBuyCondition = true;

}

 

Thank you very much for your fast reply.

I will have to digest and implement this peace of code... It may take some time...

 
 

Amazing course but needs updated link index

An amazing course codersguru.

If you want to make the course even more accessible and useful, I would suggest an index of links to all lessons and appendices at the start of the thread (or maybe at https://www.mql5.com/en/forum ) - kept up to date.

https://www.mql5.com/en/forum/172969/page2 contains an index to Lesson 14 and Appendices 1 and 2 but doesn't includes Lessons 15-18.

And there's probably more to come!

Thanx for all your hard work

JRtrader

 

In the below function every time I start the EA it immediately takes a position.

If the current_direction is either 1 or 2 and the last direction is zero they will always not equal on the first call and that will return a direction change and therefore always take a position when the EA is started. What am I missing on this?

Thanks for any clarification.

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 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);

}

}

Reason: