[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 104

 

The number of the day of the month is added to the order comment. How can I calculate how many orders (closed) there were during the day with this day's comment?

I don't know how to do it.

comment = Day();

int OpenOrdersDayHistory(string symbol, int type, int magic, string comment)
{
int n;
int f = 0;
int total = OrdersHistoryTotal();
for (n = total - 1; n >= 0; n--)
{
OrderSelect(n,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol() == symbol && OrderType() == type && OrderMagicNumber() == magic && OrderComment() == comment)
{
f++;
}
}
Print("order count = ",f,");
return(f);
}

 
To serega393
Is your comment behind the function a string or an integer?
The function seems to be composed correctly. Put a printout of all incoming variables inside to see a clear picture.
 
serega393 писал(а) >>

The number of the day of the month is added to the order comment. How can I calculate how many orders (closed) there were during the day with this day's comment?

I don't know how to do it.

comment = Day();

int OpenOrdersDayHistory(string symbol, int type, int magic, string comment)
{
int n;
int f = 0;
int total = OrdersHistoryTotal();
for (n = total - 1; n >= 0; n--)
{
OrderSelect(n,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol() == symbol && OrderType() == type && OrderMagicNumber() == magic && OrderComment() == comment)
{
f++;
}
}
Print("order quantity = ",f,");
return(f);
}

comment = TimeDay(iTime(Symbol(),Period(),0)) ;
And the same thing when sending orders!
 
StatBars >> :
And the same when sending orders!

>> It's better this way:

   comment = TimeDay(TimeCurrent());
It's faster, easier and more reliable.
 

bool UseTF = true;


int start()
{

string comment = TimeDay(TimeCurrent());

if (OpenOrdersDayHistory(Symbol(), OP_SELL, 123, comment) > 0)
{
UseTF = false;
Print("No");
}
else
{
UseTF = true;
Print("Yes");

}

if (UseTF == true)
{
int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, Ask+10*Point, comment, 123, 0, Green);
}
return(0);
}

int OpenOrdersDayHistory(string symbol, int type, int magic, string comment)
{
int n;
int f = 0;
int total = OrdersHistoryTotal();
for (n = total - 1; n >= 0; n--)
{
OrderSelect(n,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol() == symbol && OrderType() == type && OrderMagicNumber() == magic && OrderComment() == comment)
{
f++;
}
}
Print("order count = ",f,");
return(f);
}

Here you try it. It doesn't read orders in history.

 

Good afternoon to all.

I have not managed to properly "score" opening of pending orders in my code. I have read the tutorial, help and other stuff. The answer is probably there, but I just can't figure it out...


Here's the problem. I have a period of time during which I look for the max and min price and assign these values to two global variables. Then we need to open a pending order at that price. I cannot decide the price point. I want to correctly specify the interval of the current price.

1.Question - how does the price function of the current bar look like, for example, at 6 am?

2 How do I specify the ticket parameter in order to close the order?

Or another way to close one of the two previously opened orders?

I have to try it this way...


for (int i=1; i<=OrdersTotal(); i++)

{

if(OrderSelect(i,SELECT_BY_POS)==true)

{

int T=OrderTicket();

int Cur_Hour2=Hour(); // server time in hours

double Cur_Min2=Minute(); // Server time in minutes

double Cur_time2=Cur_Hour2 + Cur_Min2/100; // Server time

Alert(Cur_time2);

if (Cur_time2>=Time_of_buy_sell_2)

OrderClose(T,1,Ask,3,Red);

}

return; // Exit from start()


Please don't judge strictly:)

 
TheXpert писал(а) >>

It's better this way:

And quicker, and easier, and more reliable.

I agree, but my emphasis was more on the other.

 
serega393 писал(а) >>

Try this. It doesn't read orders in history.

It reads everything normally. Check what comment you have after closing. Some brokers add their own entries to the comment when an order is closed.

 
int start()
{
   string comment = TimeDay(TimeCurrent());   
   if ( OpenOrdersDayHistory(Symbol(), OP_BUY, 123, comment) <3)   
   {      
      UseTF = true;      
      Print("Yes");   
   }
   else   
   {      
      UseTF = false;      
      Print("No");   
   }    
   
   if ( UseTF == true)   
   {      
      int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, Ask+100*Point, comment, 123, 0, Green);   
   }
   return(0);
}

int OpenOrdersDayHistory(string symbol, int type, int magic, string comment)
{   
   int n;   
   int f = 0;   
   int total = OrdersHistoryTotal();    
   for ( n = total - 1; n >= 0; n--)   
   {      
      OrderSelect( n, SELECT_BY_POS, MODE_HISTORY);
      Print(OrderSymbol() == symbol && OrderType() == type && OrderMagicNumber() == magic," ",StringFind(OrderComment(), comment,0)>=0);
      if (OrderSymbol() == symbol && OrderType() == type && OrderMagicNumber() == magic && StringFind(OrderComment(), comment,0)>=0)          
            f++;   
   }    
   Print("колл-во ордеров = ", f,"");   
   return( f);
} 
 
Can you suggest an EA that closes all positions (and unprofitable ones too) when a certain profit is reached and removes all unperformed pending orders ?
Reason: