# Only 2 trade per day, how?

71
Hi,

I hope someone can help me with my problem.
I'm trying to create an EA which only open max 2 positions per day.

Let say the trade is triggered by MA Cross and I only want the EA open max 2 position per day.
Which one is the best technic? Using GlobalVariable or checking history ? Or is there any other technic?

Sample code will be appreciated.

Aldhy

*I'm sorry for my bad english.
2646

int start()
{

if(CheckTodaysOrders() >= 2){

return(0); // abort

}

//...

//... EA code...

//...

return(0);

}

// function

int CheckTodaysOrders(){

int TodaysOrders = 0;

for(int i = OrdersTotal()-1; i >=0; i--){

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

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

OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

return(TodaysOrders);

}

71

phy:

int start()
{

if(CheckTodaysOrders() >= 2){

return(0); // abort

}

//...

//... EA code...

//...

return(0);

}

// function

int CheckTodaysOrders(){

int TodaysOrders = 0;

for(int i = OrdersTotal()-1; i >=0; i--){

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

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

OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

return(TodaysOrders);

}

Phy,

Thank you very much.
I really appeciate it.
You are the man ;)
I see you always try your best to help people in this forum.

Aldhy
2646

Just giving a little back... Might get tired soon...
591

phy:
Just giving a little back... Might get tired soon...

phy,

Your in-depth knowledge of and creative, unique style in MQL4 coding is very much appreciated. if you do get tired soon, please return once in awhile.

2646

Thank you for the compliment.
304

phy:
Thank you for the compliment.

phy,

i never thought it very easy to code it, u solved my problem..thanks a lot :D

regards,

MANSTIR

367

phy:
Just giving a little back... Might get tired soon...

It will be a loss for the forum if such thing happens! Lots of great ideas and perfect coding comming from you phy...

[Deleted]
phy:

int start()
{

if(CheckTodaysOrders() >= 2){

return(0); // abort

}

//...

//... EA code...

//...

return(0);

}

// function

int CheckTodaysOrders(){

int TodaysOrders = 0;

for(int i = OrdersTotal()-1; i >=0; i--){

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

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

OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

return(TodaysOrders);

}

once again THANK to phy

[Deleted]
isdi82 wrote >>

once again THANK to phy

I found this to be a littler easier/simpler

Total = OrdersTotal();
OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS,MODE_HISTORY);
if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())) Total += 1;

it doesn't seem to cause any errors in this way... and on my buy signal I have

if(Total < MaxOrders) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

MaxOrders being in the beginning of the EA as an extern... in my case being 1... in this way you can adjust how many orders it places in a day

26

Hi,

I'm new here. Thank you so much for the code by phy here. But the code appears to allow only 2 trades per account per day. Is it possible to make the code trade 2 times PER CHART per day? Thanks!

phy:

int start()
{

if(CheckTodaysOrders() >= 2){

return(0); // abort

}

//...

//... EA code...

//...

return(0);

}

// function

int CheckTodaysOrders(){

int TodaysOrders = 0;

for(int i = OrdersTotal()-1; i >=0; i--){

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

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

OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);

if(TimeDayOfYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent())){

TodaysOrders += 1;

}

}

return(TodaysOrders);

}