[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 650

 

I need help with closing orders)) there is a trade on each bar. The tester opens many, many orders, and the correct way is to send an order on the current bar and close it on the next bar.

Tell me what's wrong...

 if (OrdersTotal()!=0)
   {
     OrderSelect(OrderTicket(),SELECT_BY_TICKET);
     if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
     if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
   }
 

It's not like that...

Who taught you to do this?

where's the order loop?

what happens if the order is not "select" ???

where is the search for the time of opening and closing of the last order ???? ?

where is the prohibition to continue opening orders on the same bar if all orders are closed according to the RIGHT conditions (which you do not have) ...

 
FAQ:

It's not like that...

Who taught you to do this?

where's the order loop?

what happens if the order is not "select" ???

where is the search for the time of opening and closing of the last order ???? ?

where is the prohibition to continue opening orders on the same bar if all orders are closed according to the RIGHT conditions (which you do not have) ...

Why the overlap cycle if there is always one order open?
 
orb:

I need help with closing orders)) there is a trade on each bar. The tester opens many, many orders, and the correct way is to send an order on the current bar and close it on the next bar.

Tell me what's wrong...

OrderSelect(OrderTicket(),SELECT_BY_TICKET);

"select order with the ticket of the currently selected order" how is that?

 

Then...

Go to Igor Kim's thread, type in the functions you need and use them, and see how to do it right.

 
(man, I'm stupid.)
 
7sintez:
Hi all! Guys..., a hint for a newbie...! I want to make it so that under certain conditions only one trade would open above the candle!!! I have a lot of trades opening for some reason... Not immediately, but gradually... I.e. let's say over a 5 minute candlestick during all 5 minutes deals are opened! And I need to make it so that only one trade is opened! And so that on the next candlestick under certain conditions, only one deal was also opened, etc.


Thank you!

I did it this way. I look through the orders and if there is an open order on the currency pair, I compare its opening time with the time of the current bar opening. If the time of the order is longer, I exit. If there is a new bar, its open time becomes longer than the time of the order which blocked the trade on the previous bar, and you can trade on the new bar.
if (OrdersTotal()>0)
   {  for (i=OrdersTotal()-1; i>=0; i--)
      {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {  if (OrderSymbol()==Symbol() && OrderOpenTime()>iTime(NULL,0,0))
            {   Sleep(5*1000); return(0);
   }  }  }  }
 
Qwertee:

Technically it's simple: buysell !="buy" - so the following Alert(1) is not executed.

What buysel variable contains at that moment is found out by print: Print (buysell); after the first alert.

------------------------------------------------------------------------------------------------------------------------------------------------

That's the problem, if I put Print(buysell) instead of Alert(1) in the code, then buysell returns the value buy, so what's the problem?

To be sure of the method of deafening a cockroach by tearing off its legs, you should tear off all its legs one by one, each time giving the command "Crawl" - this is the fate of all experimenters. Try to put something else in the second Alert() command, for example Alert ("1"), or Alert ("Mama, don't grieve!") - watch what happens. ;)))
 
paladin80:
I have done it this way. If there is an open order on the currency pair of interest, I compare its open time with the time the current bar starts to open. If the time of the order is longer, we exit. If there is a new bar, its open time is longer than the time of the order which blocked the transaction on the previous bar and we can trade on the new bar.
If you tell a small child to call his mother "Daddy", he will do so until someone "laughs at him"...

If prompting a beginner, get it right away RIGHT! Construction:

if (OrdersTotal()>0)

This will work as long as the trader does not run several Expert Advisors on the same account, and this will happen sooner or later! Which means, An advisor without a MAGIC is "like a Bird without a wing, like a Man without Money"...

By the way and

iTime(NULL,0,0)

it's more correct to write it as Time[0].
And Sleep (5*1000) = 5 seconds. And what are we waiting for?

 
7sintez:
Hi all! Guys..., a tip for a newbie...! I want to make it so that under certain conditions only one trade would open above the candle!!! I have a lot of deals opening for some reason... Not immediately, but gradually... I.e. let's say over a 5 minute candlestick during all 5 minutes deals are opened! And I need to make it so that only one trade is opened! And so that on the next candle under certain conditions, too, only one deal is opened, etc.


Thanks!

Compare the opening time of the order with the start of the 5 minute candle, e.g. like this:

if (iBarShift (NULL, 5, OrderOpenTime()) == iBarShift (NULL, 5, iTime (NULL, 5, 0))) return (0);
или
if (OrderOpenTime() >= iTime (NULL, 5, 0)) return (0);
Reason: