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

 
vovan-gogan:
People, help me out with the code: Why doesn't this EA put out a pendulum when the MA is crossed.


Is that what you have in mind?

if (OrdersTotal()<= 1)
   return;
It will only open orders starting from the second. Not even from the second, but from the third.
 
DhP, Roman, thanks!!!!!!
 
Dimka-novitsek:
DhP, Roman, thanks!!!!!!

Was the cleaning successful?
 
Hello, could you please give me a hint? In the following code, I get the closing time of the last order for a particular security:

for(j=0; j<OrdersHistoryTotal(); j++)
if (OrderSelect(j,SELECT_BY_POS,MODE_HISTORY))
if (OrderSymbol()==Symbol())
{
datetime ctm=OrderCloseTime();
break;
}

I would like the next order on this security to be opened only after three bars, i.e. on the fourth bar, but not before. How can I make a check?
 
first_may:
Hello, could you give me a hint? In the following code, I get the closing time of the last order for a particular security:

for(j=0; j<OrdersHistoryTotal(); j++)
if (OrderSelect(j,SELECT_BY_POS,MODE_HISTORY))
if (OrderSymbol()==Symbol())
{
datetime ctm=OrderCloseTime();
break;
}

I want to open the next order on this security after three bars, i.e. on the fourth bar, but not before. How can I make a check?

Are you sure it's the last one closed? What if it's the first one you meet? You're falling out of the loop.

 
artmedia70:

Are you sure it's the last one closed? What if it's the first one you meet? You're falling out of the loop, aren't you?




I'm going through the history, aren't all the warrants there?
 
first_may:

I'm going through the history, aren't all orders there?

you go through the history up to the first order on the symbol, after which break - you drop out of the loop.

If you had 100 orders you will only see one
.

 
first_may:

I am going through the history, all orders are there?

Here. The function will return you the bar number of the last bar closed by this EA:

int BarLastClosePose() {
datetime t;
for (int i=0; i<OrdersHistoryTotal(); i++) {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
      if (OrderMagicNumber()!=Magic)   continue;
      if (OrderSymbol()!=Symbol())     continue;
      if (OrderType()>1)               continue;
      if (t<OrderCloseTime()) t=OrderCloseTime();
      }
   }
   return(iBarShift(Symbol(), Period(), t, True));
}

You call, for example, int BarClose=BarLastClosePose();

The BarClose variable will store the number of the bar of the last closed position, or -1 (if there is no bar). Magic - EA magic - write your variable there.
Or, delete this line if you want to check all orders (even those that have been placed by another EA or that have been manually opened by yourself)
And then you can check when the next order can be opened (after how many bars).

 
Generally, the goal is to open an order only after at least three bars, i.e. on the fourth bar, but not before, after the last closed order on the security. To do this, I go through the history and if I see an order on this security from the history, I consider it closed and last. Am I wrong in thinking that orders will be selected in chronological order?
 
first_may:
Generally, the goal is to open an order only after at least three bars, i.e. on the fourth bar, but not before, after the last closed order on the security. To do this, I go through the history and if I see an order for this security from the history, I consider it closed and last. Am I wrong in thinking that the orders will be selected in chronological order?
You are wrong in not wanting to study the example above