# Placing several trades a day

199

Hey guys,

I was wondering if someone can help me with a the coding here. I want to place Max orders. I am going to place 4 pending orders a day and after those trades are placed I want the next 4 orders to be placed the next day.

I tought of counting the trades by selecting the trades if they had the same day of the year but I don't think the code is working. Can you help me?

```int total = 0;

for(int i = 0; i < OrdersTotal(); i++)
{
if( DayOfYear() == OrderOpenTime())         <-------///// ?????????
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
total += 1;
}
}

}```
Moderator
18025

rori4:

Hey guys,

I was wondering if someone can help me with a the coding here. I want to place Max orders. I am going to place 4 pending orders a day and after those trades are placed I want the next 4 orders to be placed the next day.

I tought of counting the trades by selecting the trades if they had the same day of the year but I don't think the code is working. Can you help me?

Can you explain your code . . .

```   for(int i = 0; i < OrdersTotal(); i++)    //  OrdersTotal() is the number of Open orders . . .
{
OrderSelect(i,MODE_TRADES,MODE_HISTORY);  //  MODE_HISTORY is selecting from Closed orders . . .```

and . . .

`if( DayOfYear() == OrderOpenTime())     // DayOfYear() returns a int, OrderOpenTime() returns a datetime . . .`
6383

199

Ok... so i fount this code on the forum that makes more sense. And now it works :)

I put this at the end of my EA after the close of the int start() 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);

}```

Whit it I want to check the orders for the day that have been placed. After that I place an if function before the OrderSend() and it seem to work just fine right now :)

```if(CheckTodaysOrders() > MaxOrders){

OrderSend() ....

}```
Moderator
18025

RaptorUK:

Can you explain your code . . .

and . . .

Can you ? if you ignore my simple question why should I answer yours ?
199

RaptorUK:
Can you ? if you ignore my simple question why should I answer yours ?

Sorry about that... It was late yesterday and I was tired and decided to post only how I resolved my problem

So here is my explanation

```   for(int i = 0; i < OrdersTotal(); i++)    //  OrdersTotal() is the number of Open orders . . .
```

The code above is the order loop that goes through the open orders if I understand this correctly. Correct me if I'm wrong.

I select the open orders. After that:

`       OrderSelect(i,MODE_TRADES,MODE_HISTORY);  //  MODE_HISTORY is selecting from Closed orders . . .`

I should only select the open trades. So yes the MODE_HISTORY is unnecessary. And that is why I should split the code in two (one for the open trades and one for the closed)

After that:

`if( DayOfYear() == OrderOpenTime())     // DayOfYear() returns a int, OrderOpenTime() returns a datetime . . . `

With this code I tried to select only if the trade was opened today and if it was so, only then to count it to total. Obviously as you pointed out the DayOfYear() returns a int, OrderOpenTime() returns a datetime so I cannot compare them. So thanks for pointing that out :)

After that I wanted to make this as a condition to be verified before opening a trade as I did with the code above

```if(total() > MaxOrders){

OrderSend() ....
}```

I hope I answered your question. I am a newbie in coding so please correct me if I'm wrong in any of my comments :)

Moderator
18025

rori4:

I hope I answered your question. I am a newbie in coding so please correct me if I'm wrong in any of my comments :)

Yes you have, and in doing so you will have learned some important things.