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

 

Hello.

Can you tell me what the following situation may be related to (the tester first gave error ticket 15, but then it still closed this order)? Should I pay more attention to it?

Thank you in advance.

 
nemo811:

Should I pay closer attention to her?


of course. there should be no errors.
 

Please help me.

Is there an error here? (The code returns a ticket of the last market SELL order)

int OrdTicketSell_b(int MAGIC)
 {
  string SMB=Symbol();
  int OrdTicketSell=0;
  int i;
  for(i=0;i<OrdersTotal();i++)
   {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
     {
      if(OrderSymbol()==SMB)
       {
        if(OrderMagicNumber()==MAGIC || OrderMagicNumber()==777)
         {
          if(OrderType()==OP_SELL)
           {
            OrdTicketSell=OrderTicket();
           }  
         }  
       }          
     }
   }
   if(OrderTicket()!= OrdTicketSell) OrderSelect(OrdTicketSell, SELECT_BY_TICKET);
   return(OrdTicketSell);
 }

Thank you in advance.

 
int OrdTicketSell_b(int MAGIC)
 {
  string SMB=Symbol();
  int OrdTicketSell=-1;
  int i;
  for(i=0;i<OrdersTotal();i++)
   {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
     {
      if(OrderSymbol()==SMB)
       {
        if(OrderMagicNumber()==MAGIC || OrderMagicNumber()==777)
         {
          if(OrderType()==OP_SELL)
           {
            OrdTicketSell=OrderTicket();
           }  
         }  
       }          
     }
   }
   if(OrderTicket()!= OrdTicketSell && OrdTicketSell>=0) OrderSelect(OrdTicketSell, SELECT_BY_TICKET);
   return(OrdTicketSell);
 }
 

Good afternoon.

Interesting point: in mql4 the variable at the end of { int var; } block is not destroyed, hence the question if it is correct to declare the variable in a loop ???

Example:

for(int i = 0; i < 500; i ++)

{

int var; // what happens to the variable during iteration?

}

Thank you.

 
sergeev:

Nah - doesn't seem to be at the bull's-eye yet. The same error is creeping up.

There is one last part of the code left, which may be related to it:

     int SchSell=SchSell_b(MAGIC);
     int OrdTicketSell=OrdTicketSell_b(MAGIC);
     double MinLot=MarketInfo(SMB,MODE_MINLOT);

     if(ChastZakr)
      {
       if(SchSell>1)
        {  
         OrderClose(OrdTicketSell,OrderLots(),MarketInfo(OrderSymbol(), MODE_ASK),Proskalz,CLR_NONE);
         Alert(SMB,": произведено частичное закрытие Sell-позиции, тикет: ",OrdTicketSell,".");
        }   
       else
        {  
         if(SchSellLots>MinLot)
          { 
           OrderClose(OrdTicketSell,NormalizeDouble(OrderLots()/2,2),MarketInfo(OrderSymbol(), MODE_ASK),Proskalz,CLR_NONE);
           Alert(SMB,": произведено частичное закрытие Sell-ордера, тикет: ",OrdTicketSell,".");
          }  
        }  
      }

The most interesting thing is that the error occurs when trying to close an order that was previously a limit order, but subsequently triggered and became a market order. If an order which was originally a market order is closed, the error does not occur.

 

Found a mistake, here's the way out:

     int SchSell=SchSell_b(MAGIC);
     double MinLot=MarketInfo(SMB,MODE_MINLOT);

     if(ChastZakr)
      {
       int OrdTicketSell=OrdTicketSell_b(MAGIC);
       if(SchSell>1)
        {  
         OrderClose(OrdTicketSell,OrderLots(),MarketInfo(OrderSymbol(), MODE_ASK),Proskalz,CLR_NONE);
         Alert(SMB,": произведено частичное закрытие Sell-позиции, тикет: ",OrdTicketSell,".");
        }   
       else
        {  
         if(SchSellLots>MinLot)
          { 
           OrderClose(OrdTicketSell,NormalizeDouble(OrderLots()/2,2),MarketInfo(OrderSymbol(), MODE_ASK),Proskalz,CLR_NONE);
           Alert(SMB,": произведено частичное закрытие Sell-ордера, тикет: ",OrdTicketSell,".");
          }  
        }  
      }
 
nemo811:

Found a mistake, here's the way out:


Can I ask you a silly question? Some kind of weird normalisation

OrderClose(OrdTicketSell,NormalizeDouble(OrderLots()/2,2),MarketInfo(OrderSymbol(), MODE_ASK),Proskalz,CLR_NONE);

I can't figure out why it's done that way.

 
Vinin:


May I ask you a silly question? It's a strange normalization

I cannot understand why this is done.

This is in case a 0.03 lot is involved, with a minimum allowable 0.01. If you divide 0.03 by 2, you get 0.015, which, as far as I understand, is unacceptable. Therefore I have made such a normalization.

Don't judge harshly - I'm just learning )). But if it's a mistake - correct me, please.

 
artmedia70:
Start doing it and we'll help. This looks like "do it for me". There's pretty much everything you need in there. All that's left to do is to set take and stop points for your orders in the loop.

this is how orders are opened:

                ticketSell = OpenPendingOrderSell(1, Lots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTradesSell, MagicNumber, 0, HotPink);
                if (ticketSell < 0)
                {
                        Print("Error: ", GetLastError());
                        return (0);
                }

I want to make the script calculate a lossless script like this:

if

if (totalBuy > 1)
{ то ордерам ticketBuy присвоить цену без убытка + TakeProfitBuy, при достижении этой цены или ниже, закрыть ордера}

я думаю, что можно что то в роде такого сделать:

if (totalBuy > 1 && (без убыток + TakeProfitBuy) >= Bid)
{
CloseAllBuy();
}

if

if (totalSell > 1 && (без убыток + TakeProfitSell) <= Ask)
{
CloseAllSell();
}

if

if (totalSell > 1 && totalBuy > 1 && (без убыток + TakeProfitSell) >= Ask)
{
CloseAllBuy();
CloseAllSell();
}

how to properly insert this no-loss line definition code into the EA:

int start()
{
   int b,s;
   double price,price_b,price_s,lot,lot_s,lot_b,SLb,SLs;
   for (int i=0; i<OrdersTotal(); i++)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {  if (OrderSymbol()==Symbol())
         {
            price = OrderOpenPrice();
            lot   = OrderLots();
            if (OrderType()==OP_BUY ) 
               {price_b = price_b+price*lot; b++;  lot_b=lot_b+lot;}
            if (OrderType()==OP_SELL) 
               {price_s = price_s+price*lot; s++;  lot_s=lot_s+lot;}
   }  }  }
   ObjectDelete("SLb");
   if (b!=0) 
   {  SLb = price_b/lot_b;
      ObjectCreate("SLb",OBJ_ARROW,0,Time[0],SLb,0,0,0,0);                     
      ObjectSet   ("SLb",OBJPROP_ARROWCODE,6);
      ObjectSet   ("SLb",OBJPROP_COLOR, Navy);
   }
   ObjectDelete("SLs");
   if (s!=0) 
   {  SLs = price_s/lot_s;
      ObjectCreate("SLs",OBJ_ARROW,0,Time[0],SLs,0,0,0,0);                     
      ObjectSet   ("SLs",OBJPROP_ARROWCODE,6);
      ObjectSet   ("SLs",OBJPROP_COLOR, Maroon);
   }
}