Only 2 trade per day, how?

 
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.

Thank you for your help.
Aldhy

*I'm sorry for my bad english.
 

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--){

OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

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:

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--){

OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

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.
Happy trading for you :)

Aldhy
 
Just giving a little back... Might get tired soon...
 
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.

 
Thank you for the compliment.
 
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

 
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...

 
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--){

OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

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);

}

I want say THANK to phy because I have posted to five forums to ask about this, but they dont answer it

once again THANK to phy

 
isdi82 wrote >>

I want say THANK to phy because I have posted to five forums to ask about this, but they dont answer it

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

 

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--){

OrderSelect(i, SELECT_BY_POS,MODE_TRADES);

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);

}

Reason: