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

 
Removed bars, added pending orders in X increments from price, the only thing left is to open closed orders immediately individually instead of waiting for all 4 orders to close and lot calculation depending on % equity, help me fix these 2 nuances
Here's what it looks like now:

//+------------------------------------------------------------------+
//| mo_bidir.mq4
//| Works best in 5M timeframe |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010 - Monu Ogbe"

#define MAGIC 1234
#define IDENT "mo_bidir"

extern double lots = 1;
extern double stop_loss = 76; //
extern double take_profit = 750; //
extern int steps = 5; // Pending order step

int start(){

if (OrdersTotal() == 0){
OrderSend(Symbol(), OP_BUY, lots,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
OrderSend(Symbol(), OP_SELL, lots,Bid, 3, Bid + take_profit * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
OrderSend(Symbol(), OP_BUYSTOP, 0.5*lots,Ask+steps*Point, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);
OrderSend(Symbol(), OP_SELLSTOP, 0.5*lots,Bid-steps*Point, 3, Bid + take_profit * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
}
return(0);
}
Files:
 
belck:
Looking for a code Breakeven on the history. may have. share.
I have a Breakeven code, but it works on the basis of open orders.
I have an EA that closes the loss-making at the opposite signal, and opens on a signal. and now you need to have this Breakeven code to remember how much into deficit and passed the information on, so that the second, etc. orders have already seen on the chart the line of zero profit, taking into account past losses. The Expert Advisor does not have a stop loss, which means that a losing trade will not be closed by a stop loss.


Every time you move it to the required price (breakeven with a close), and do not delete it (the line) when you close an order and see the old price in the next order
 
belck:
Looking for a history breakeven code. maybe someone has one. please share.
I have a Breakeven code, but it's based on open orders.
I have a good working order when there is a loss on an order and it should open when the order reaches zero. The orders have already seen the zero line on the profit line on the chart taking into account the previous losses. The Expert Advisor does not have a stop loss, which means the closing of a losing trade is not by a stop loss.

If I understand correctly, part of your question is the accounting of total losses on consecutive losing trades of your EA for further comparison with the profit level on current market orders to set the breakeven line?
 
FAQ:

Every time you move it to the required price (breakeven at the close), and do not delete it (the line) when you close the order and see the old price in the next order

this is not easy.

I cannot implement it myself.

I want the line to appear on losing trades so that I would be able to close when it is reached.

I.e., I need a line that will be drawn only when there are losing orders, but this line will be drawn based on the lot of an open trade and the previous history of losing trades.
 
Roman.:
If I understand correctly, the part of your question is to take into account the total loss of successive losing trades of your EA and compare it with the profit level of current market orders to set the breakeven line?

I have no stop lines, i.e. no stop loss and no take profit.

I want to see the price line, where I have to go to close the deal in such a way that the previous closed orders are overlapped.

i need a block behind the start block that will count and transfer information to the start block, and i will use this information to close the deal when it reaches this price line.

 
You need a global variable, make it a global Terminal, or graph object - then it will only be visible on this graph, write it to a file if needed, or to the registry, or to memory directly. There are many options.
 
FAQ:
You need a global variable, make it a global Terminal, or graph object - then it will only be visible on this graph, write it to a file if needed, or to the registry, or to memory directly. There are many variants.
is this your answer to me?
 
belck: But I can't write the Breakeven block by history itself.

Here is my code section - responsible for accounting of total loss of consecutive losing trades of this particular EA (according to magician). I made it for my variant of netting Avalanche - you can edit it to your needs - the code is commented out...

Global Variables

double Current_Loss, Sum_Loss;     // текущий и суммарный убыток
int start()    // -----------------------СТАРТ ЭКСПЕРТА---------------
{

//---------------------расчет по истории ордеров номера очередной итерации----------------------------------------------- 
  Iteration = 0; // зануляем инерации перед их учетом в цикле по истории
  Sum_Loss = 0;  // суммарный убыток по этим итерациям

datetime 
Time_at_History_Current = 0,
Time_at_History_Previos = 0;     
 
 if(OrdersHistoryTotal() != 0)
   {
    for(int counter = OrdersHistoryTotal()-1; counter >= 0; counter--)
      {
       OrderSelect(counter, SELECT_BY_POS, MODE_HISTORY);
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
          if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
             if(OrderProfit() < 0) // если убыток по выбранному ордеру, то считаем суммарный и записываем время закрытия ордера
                                   // для последующего его анализа при подсчете количества итераций
                {
                 double lastLoss = OrderProfit();
                 Sum_Loss=Sum_Loss+lastLoss;  // считаем общий убыток по закрытым подряд убыточным ордерам
                 Time_at_History_Current = OrderCloseTime();
                } 
             
             //Print(" Time_at_History_Current_в цикле = ", TimeToStr(Time_at_History_Current, TIME_DATE|TIME_SECONDS));
             //Print(" Time_at_History_Previos_в цикле = ", TimeToStr(Time_at_History_Previos, TIME_DATE|TIME_SECONDS));
             
             if(Time_at_History_Current != Time_at_History_Previos) // если они не равны, то считаем итерации и делаем их равными
               {
                Time_at_History_Previos = Time_at_History_Current ;
                Iteration++;
                //Print("Iteration at History в условии сравнения  = ",  Iteration);
               }   
             else // они равны, то проверяем, дополнительно, наличие профита по выбранному следующему ордеру и выходим из цикла
               {
                if(OrderProfit() >= 0)
                  break;
               }
            }
         }
      }
   }
 //Print("Iteration at History = ",  Iteration, " Time_at_History_Current = ", TimeToStr(Time_at_History_Current, TIME_DATE|TIME_SECONDS),
 //      " Time_at_History_Previos = ", TimeToStr(Time_at_History_Previos, TIME_DATE|TIME_SECONDS));
...
...
}// конец старт   

After this code section, you also loop through the open orders of this very EA and calculate their total profit. Then you compare this value with the variable

Sum_Loss

and make a decision.

 
belck:
Looking for a history breakeven code. maybe someone has one. please share.
I have a Breakeven code, but it's based on open orders.
I have a good working order when there is a loss on an order and it should open when the order reaches the break-even point. The orders have already seen the zero line on the profit line on the chart taking into account the previous losses. The Expert Advisor does not have a stop loss, which means that a losing trade will not be closed by a stop loss.

Calculate the total profit of all closed trades and save it in a variable, for example, TotalCloseProfit. And then use the following piece of code, without any graphics or other contrivances:

if (TotalCloseProfit) < 0.0) { // Имеем убыток по закрытым позам
  if ((AccountEquity() + TotalCloseProfit) >= AccountBalance()) { // Достигли безубытка
    // Здесь какой-то код, который необходимо выполнить при достижении безубытка
  }
}
 
utyff:


I took a look at the log.

That seems to be the reason, but I don't know what it means. Can anyone explain? And how to fix it?

It's not an error. Errors in the log are marked with red, not yellow icons.