[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 56

 
Sergstuddek:


(The class is good, but there's still a problem)))

I understand it theoretically, but in practice it does not work, can you look at my code and tell me what's wrong

I understand that this is a very simple EA, but I am just starting my journey)))) and I already have a problem

// The essence of the Expert Advisor is that first it opens the first Buy order
// then puts stops in two directions
// in one side as a continuation of an open order
// on the other side twice more in case of chart reversal
// stops are placed in relation to the last order opened by the advisor
// with each new opening of a new pending order, all the previous ones are deleted
// and new pending stops are already open relative to a new open order.


Stops can be understood as two things - stop orders (Take Profit and Stop Loss) and stop orders (Bystop and Sell Stop). What is meant by "stops" here is probably only understood by you. Please be precise with the terms. The computer has to be given precise instructions. The description must also be as precise as possible
 
drknn:
Stops can be understood to mean two things - stop orders (Take Profit and Stop Loss) and stop orders (Bystop and Sell Stop). What is meant by "stops" here is probably only understood by you. Please be precise with the terms. You have to give precise instructions to the computer. The description must also be as precise as possible

I am sorry for the inaccuracy, but the stop orders are stop orders (Buy Stop and Sell Stop)
 
Sergstuddek:

I apologize for the inaccuracy: I mean stop orders (Buy Stop and Sell Stop).
void DeleteStopOrders()
{
  int res;
  for(int i=0;i<OrdersTotal();i++)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
    {
      if(OrderType()==OP_SELLSTOP)
        res=OrderDelete(OrderTicket());
      if(OrderType()==OP_BUYSTOP)
        res=OrderDelete(OrderTicket());
     }
  }
}


This function is written incorrectly. Orders should be searched from last to first in the order list. Your method will cause 1 order to be skipped because after it is deleted the order list will move by its positions. The loop should be organised as follows:

for (int i=OrdersTotal()-1;i>=0;i--){

Further, if the order is not selected, you don't need to make a brek - you don't need to exit the cycle - you need to find out the reason why the order is not selected. That is as follows:

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
  Print("При выборе ордера № ",i," произошла ошибка № ",GetLastError());

res=OrderDelete(OrderTicket()); - this is also not correct enough. The OrderDelete() function has a boolean type. And along with giving an order to delete the order, we also need to handle the situation if the order cannot be deleted. In other words, it goes like this:

res=OrderDelete(OrderTicket());
if(!res){
  Print("Ордер № ",OrderTicket()," удалить не получилось - ошибка № ",GetLastError());
}

I'll look at the rest later.

 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  if (CalculateCurrentOrders1(Symbol())==0)
   OpenBuy();
  if (CalculateCurrentOrders2(Symbol())<=1)
  DeleteStopOrders();
  if (CalculateCurrentOrders2(Symbol())<=1)
   OpenStops();
//----
   return(0);
}

The start function code is not written correctly.

With the first function you add up buy and sell orders. You need to count buy orders separately and sell orders separately. Here is the point. If there is 1 buy order in the market, then the buy stop should be set with a larger lot. Right? And if there is a sell order in the market, then the buystop should be set with a normal lot and sell stop with a larger one. How do you detect which order is open in the market if you sum both Buy and Sell orders in one function? Try to redo the code in the light of these facts.

 

Can you tell me how to automatically download the history from the broker? It's a bit inconvenient to press home for an hour.

 
_dude_:

Can you tell me how to automatically download the history from the broker? It's a bit inconvenient to press home for an hour.

Vadim Junko has taken care of it for you. Script for loading the history. There are a few more in the base (Scripts section).
 
gince:

Question about the indicator.

The indicator is a cross indicator. It draws a lot of arrows to one side, then a lot to the other. How to make only the first ones to be drawn. I have tried it in the way described in the code, but the arrows change when I switch Frames.

Please advise how to do it correctly.


I would have to look at the indicator. Maybe there is a solution
 
nemo811:
Please help me to correct my Expert Advisor. You need to make it work with orders (own and opened by the user) of the currency pair on the chart of which it is installed. We mean the time of fixing of profit or loss. In the current version, when a condition (catching of a deposit %) occurs, it tries to close all positions (with MAGIC=0) for all currency pairs and I do not need it. It is necessary to completely delimit all currency pairs. My thanks in advance.

The same thing you have to do in different message boards - this is spam, and you may get a ban.
 
Vinin:

And writing the same thing in different threads - it's spam and can get a ban

I apologise - as always I want to do everything at once))
 

Thank you for your attention and understanding ))

Was able to solve the problem myself:

Inserted a tricky line if(OrderSymbol()!=SMB || OrderMagicNumber()!=MAGIC) continue;

to an equally tricky place. After that, everything worked as intended.

Thanks for the tip with the magician. I'm not a programmer, so sometimes and not thinking of something for lack of knowledge.

Reason: