Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 219

 
bambastik:
It is all absolutely, but according to the type of chart on which the script is based, so that the script should be as simple as possible. I do not use Expert Advisors, I am only trialling now, I do not plan any activities in my life in the next month, that is why I decided to take a look at forex.

So it is the processing of trading errors that makes the difference between a good script and a tutorial in this case. Do you want to learn from it or do you want it to work 100%?

If you just want the principle, here it is:

//-----------------------------------------------------------------------------+
void start() {
   string sy=Symbol();
   int    i, k=OrdersTotal()-1;

   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderSymbol()!=sy)  continue;
         if (OrderType()>1)      continue;
         if (OrderType()==OP_BUY)   OrderClose(OrderTicket(),OrderLots(),Bid,5,Blue);
         if (OrderType()==OP_SELL)  OrderClose(OrderTicket(),OrderLots(),Ask,5,Red);
         }
      }
   return;
}
//-----------------------------------------------------------------------------+

It closes both Buy and Sell.

There is absolutely no error handling. You may close only Buy or only Sell for yourself - remove one line.

Well... only Buy:

//-----------------------------------------------------------------------------+
void start() {
   string sy=Symbol();
   int    i, k=OrdersTotal()-1;

   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderSymbol()!=sy)  continue;
         if (OrderType()==OP_BUY)   OrderClose(OrderTicket(),OrderLots(),Bid,5,Blue);
         }
      }
   return;
}
//-----------------------------------------------------------------------------+

For Sell:

//-----------------------------------------------------------------------------+
void start() {
   string sy=Symbol();
   int    i, k=OrdersTotal()-1;

   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderSymbol()!=sy)  continue;
         if (OrderType()==OP_SELL)  OrderClose(OrderTicket(),OrderLots(),Ask,5,Red);
         }
      }
   return;
}
//-----------------------------------------------------------------------------+
 

Thank you very much. That's just what I need. But what are red and blue and what is it for, it probably shows the reset point of each order, right? When I try it, I will add it to codebase at once by artmedia70. And by the way, why do we need processing of a normal if the script is accurate and the developer is confident in it?

And maybe I do not need to add them by the way and the developer himself that is artmedia70 will add to the codebase, they will turn out to be needed there, and I have no account there, and to the comments will not be able to answer a word, eh?

 
bambastik:

Thank you very much. But that's just what I need. But what are red and blue and what is it for, it probably shows the reset point of each order, right? When I try it, I will add it to codebase at once by artmedia70.

No, not in the codebase, not in any way. I'm used to making reliable things, not tutorials :)

If I had shown you a normal script, you would have told me that I, like everyone else, wrote all sorts of 'errors' again... But... you can't do without them. This is work with our money.

Blue and Red are the colour of the closure mark.

 
artmedia70:

No, there's no need for a catbase. I'm used to making reliable things, not tutorials :)

If I showed you a normal script, you'd tell me that I, like everyone else, wrote all sorts of rip-offs again... But... you can't do without them. This is a job with our money.

Blue and Red are the colour of the closing icon.


I understand everything about the cattobase and about red and blue too, in general once again thank you very much for your help, but I will not start to yak out unless very rarely, the Internet must be beyond the curtsy and flattery and carry only thought and by the way you alone can be a hundred times more respectful than thousands of you, but that's lyric) in general artmedia70 thanks a lot, very script helped and in the cattobase with it I will not go. I have a lot of them in the history who thought so and where they are now. imho, the money will be canceled soon, will leave a virtual and lime it, so everyone could have an account with strictly identifiable not more than a certain amount, the rest in the budget, etc. so i'm cool with them, but the process from their activities is yes, interesting. p.s. apologize for verbosity.
 
bambastik:

By the way, why do you need to process a regular script if it is clear and the developer is confident in it?

The developer will only be confident in his program if his program will handle the errors returned by the trading server. If no error handling is done, the program may stumble at the first error. The error is NOT a program error, but an error returned by the trade server. For example - the above script does not get fresh data. So the server may return an error about the wrong price. For this, one should try to receive the most recent trade environment before closing - please execute RefreshRates() command or, instead of the Ask or Bid closing price, use the price obtained using MarketInfo(Symbol(),MODE_ASK) or MarketInfo(Symbol(),MODE_BID);

Then the script will take this form (for Sell):

//-----------------------------------------------------------------------------+
void start() {
   string sy=Symbol();
   int    i, k=OrdersTotal()-1;
   
   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderSymbol()!=sy)  continue;
         if (OrderType()==OP_SELL)  {
            double pp=MarketInfo(sy,MODE_ASK);
            OrderClose(OrderTicket(),OrderLots(),pp,5,Red);
            }
         }
      }
   return;
}
//-----------------------------------------------------------------------------+

And if you try to process other errors returned by the server, it will grow to those values when you say - "you've done it again..." :)

 

Now I get it and yes, it's important. The internet is no good here, the hardware is young too, so it's not really wise to rely on them for the full two hundred percent, but risk is a noble thing =) but thanks again for the addition, I will add it to both buy and sell.

Is it right for buy?

void start() {
string sy=Symbol();
int i, k=OrdersTotal()-1;

for (i=k; i>=0; i--) {
if (OrderSelect(i,SELECT_BY_POS)) {
if (OrderSymbol()!=sy) continue;
if (OrderType()==OP_BUY) {
double pp=MarketInfo(sy,MODE_BID);
OrderClose(OrderTicket(),OrderLots(),pp,5,Blue);
}
}
}
return;
}

And if I need to remove only 3 buy orders out of 5 buy ones out of all available, which value is the biggest, will the script get bigger in size? And one more question, if I'm not bothering to ask, because these checks take all the time, I wonder which script has a higher probability of slippage than the one with checks or the one without checks for errors?

 
bambastik:

Now I get it and yes, it's important. Internet is no good here, it's a fact, hardware is young too, so it's not really wise to rely on them for the full two hundred percent, but risk is a noble thing =) but thanks again for the addition, I will add it to both buy and sell.

Is this correct for buy?

Yes. But that is not all... ;)

This script, in addition to unprocessed similar errors, will also touch "alien" orders. I.e., if you have an EA working on this symbol, the script will close its positions, and the EA will open them again. This is how they will "fight" with each other.

To avoid this, it is necessary to limit the script in terms of magic. I.e., add a line if (OrderMagicNumber()>0) continue; then the script will only work with orders opened manually.

For Sell:

//-----------------------------------------------------------------------------+
void start() {
   string sy=Symbol();
   int    i, k=OrdersTotal()-1;
   
   for (i=k; i>=0; i--) {
      if (OrderSelect(i,SELECT_BY_POS)) {
         if (OrderMagicNumber()>0)  continue;
         if (OrderSymbol()!=sy)     continue;
         if (OrderType()==OP_SELL)  {
            double pp=MarketInfo(Symbol(),MODE_ASK);
            OrderClose(OrderTicket(),OrderLots(),pp,5,Red);
            }
         }
      }
   return;
}
//-----------------------------------------------------------------------------+

And there is a lot more to refine for "normal" reliability. It will come in time, don't doubt. ;)

 
artmedia70:

Yes. But that's not all... ;)

This script, apart from the remaining unprocessed similar errors, will also touch "alien" orders. I.e., if you have an EA working on this symbol, the script will close its positions, and the EA will open them again. This is how they will "fight" with each other.

To avoid this, it is necessary to limit the script in terms of magic. I.e. add a line if (OrderMagicNumber()>0) continue; then the script will only process manually opened orders.


I don't know how to do it, I will never get to expert advisors, indicators, signals and the rest, so I just get bored playing Dota and start poking at the chart, I love looking at the movement of it, it's very beautiful, so I'm just so, for general development and now I understand what a magik order that is opened by non-automatic and non-advisor, although they are probably the same people ;)
 
can you write: a script/advisor to close two opposite orders in n*pips in profit?
 
spec01:
can you write: a script/advisor to close two opposite orders for profit in n*pips?

With this kind of request here