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

 
T-G:
Yes, but the point of the question is that the previous order was closed with a minus. The function does not have time to show this, first the order is opened after a couple of ticks and only then the function shows the last loss but the order has already been opened.
I wrote a code skeleton with check
 
I did so once again say does not have time to check first it passes as if there is no moose opens a deal and then it comes to him that there was a moose
 
artmedia70:

Why not use the Expiration pending order parameter.

There is of course a possibility that this parameter cannot be used.

On some trade servers, the expiration time of pending orders may be prohibited. In this case, an error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated when trying to set a non-zero value in the expiration parameter.

That's the only way, of course...

I changed the line as you suggested and the Expert Advisor stopped working...

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+PriceDistance*Point,3,Ask+PriceDistance*Point-StopLoss*Point,Ask+PriceDistance*Point+TakeProfit*Point, "PD",1,TimeCurrent()+10*60,Green);

At the same time I know for sure there is no ban.

Please advise where the error may be.

 
T-G:
I did so once again say does not have time to check first it passes as if there is no moose opens a deal and then it comes to him that there was a moose
Miracles don't happen. You should see a telepath...
 
OlegArH:

I made changes to the line as you suggested, and the Expert Advisor stopped working...

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+PriceDistance*Point,3,Ask+PriceDistance*Point-StopLoss*Point,Ask+PriceDistance*Point+TakeProfit*Point, "PD",1,TimeCurrent()+10*60,Green);

At the same time I know for sure there is no ban.

Please advise where the error may be.

It's unlikely to have stopped working, but your criteria is likely to be flawed. Without the code, it's hard to think of a reason why the EA isn't working...
 
artmedia70:
It is unlikely that it has stopped working, but your criteria are likely to be lame. Without the code, it's hard to think of a reason why the EA doesn't work...

This is all I've "scribbled" so far:

extern double TakeProfit = 50;
extern double StopLoss=100;
extern double PriceDistance = 50;
extern double Lots = 1;
extern double TrailingStop = 50;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;

total=OrdersTotal();
if(total<1)
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+PriceDistance*Point,3,Ask+PriceDistance*Point-StopLoss*Point,Ask+PriceDistance*Point+TakeProfit*Point, "PD",1,0,Green);
Sleep (10000);
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-PriceDistance*Point,3,Bid-PriceDistance*Point+StopLoss*Point,Bid-PriceDistance*Point-TakeProfit*Point, "PD",2,0,Red);
}

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(1!=1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(1!=1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}

// the end.

It works like this.... But, accordingly, opens trades indefinitely, the creeper.

Thanks in advance!

 
OlegArH:

Here's all I've scribbled so far:

extern double TakeProfit = 50;
extern double StopLoss=100;
extern double PriceDistance = 50;
extern double Lots = 1;
extern double TrailingStop = 50;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;

total=OrdersTotal();
if(total<1)
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+PriceDistance*Point,3,Ask+PriceDistance*Point-StopLoss*Point,Ask+PriceDistance*Point+TakeProfit*Point, "PD",1,0,Green);
Sleep (10000);
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-PriceDistance*Point,3,Bid-PriceDistance*Point+StopLoss*Point,Bid-PriceDistance*Point-TakeProfit*Point, "PD",2,0,Red);
}

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(1!=1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(1!=1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}

// the end.

It works like this.... But, accordingly, opens trades indefinitely, the creeper.

Thanks in advance!


Learn how to insert code - read it all.
 
Roman.:

Learn how to insert code - read it all.

Roman, thank you for the answer!
What I have to do is to get my robot to open trades for a certain period of time from their automatic opening.

For example, the robot opens a TARGET trade, automatically sets expiry time +600 sec from the current one and that's it....

In this case, the option when he removes them himself does not fit, since TC on which I "train" there are restrictions on the modification of the pending orders if the price came closer than 10 points + Spread to the opening price, including those not yet open order.

Besides, the point is that if an order is already open, it should not be deleted, but it should be allowed to "play through" and fail. And if we set orderdelite, the function will also close the orders that have already triggered. (?)

As for the textbook - well, I'm not a programmer by temperament, I am a brilliant humanitarian - I draw, model, compose, and do not sharpen for anything else!)

I've been trying to get into it in good faith. Some of it made sense and some of it did not.

That's why I'm here.....

 
OlegArH:

Roman, thank you for the reply!
It's just a matter of getting the robot to open trades on time from the moment they are automatically opened.

For example, the robot opens a TARGET trade, automatically sets expiry time +600 sec from the current one and that's it....

In this case, the option when he removes them himself does not fit, since TC on which I "train" there are restrictions on the modification of the pending orders if the price came closer than 10 points + Spread to the opening price, including those not yet open order.

Besides, the point is that if an order is already open, it should not be deleted, but it should be allowed to "play through" and fail. And if we set orderdelite, the function will also close the orders that have already triggered. (?)

As for the textbook - well, I'm not a programmer by temperament, I am a brilliant humanitarian - I draw, model, compose, and do not sharpen for anything else!)

I've been trying to get into it in good faith. Some of it made sense and some of it did not.

That's why I'm here.....

Try to describe in words what you've written here:

extern double TakeProfit = 50;
extern double StopLoss=100;
extern double PriceDistance = 50;
extern double Lots = 1;
extern double TrailingStop = 50;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
   int cnt, ticket, total;

   total=OrdersTotal();
   if(total<1) {
      ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+PriceDistance*Point,3,Ask+PriceDistance*Point-StopLoss*Point,
                       Ask+PriceDistance*Point+TakeProfit*Point,"PD",1,0,Green);
      Sleep (10000);
      ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-PriceDistance*Point,3,Bid-PriceDistance*Point+StopLoss*Point,
                       Bid-PriceDistance*Point-TakeProfit*Point,"PD",2,0,Red);
      }

   for(cnt=0;cnt<total;cnt++) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&                         // check for opened position
         OrderSymbol()==Symbol()) {                      // check for symbol
         if(OrderType()==OP_BUY) {                       // long position is opened
            if(1!=1) {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
               return(0);                                // exit
               }
                                                         // check for trailing stop
            if(TrailingStop>0) {
               if(Bid-OrderOpenPrice()>Point*TrailingStop) {
                  if(OrderStopLoss()<Bid-Point*TrailingStop) {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                     }
                  }
               }
            }
         else {                                          // go to short position
                                                         // should it be closed?
            if(1!=1) {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0);                                // exit
               }
                                                         // check for trailing stop
            if(TrailingStop>0) {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                     }
                  }
               }
            }
         }
      }
   return(0);
}

Personally for me at the very first glance it turned out to be a puzzle your idea: If one is not equal to one, then close the order...

I didn't watch the rest after that...

ZS and don't try, don't even think that it is possible to write a normal EA in one cycle...

 
OlegArH:

...And if you put orderdelite, the function will also close orders that have already been triggered. (?)

...


No. Take a closer look. A triggered pending order becomes a market order - this function has nothing to do with it.

"Deletes a previously set pending order. Returns TRUE if function completed successfully. Return FALSE

if the function has not been completed successfully. Call GetLastError() to get error information."

Reason: