Questions from Beginners MQL4 MT4 MetaTrader 4 - page 206

 
a.lxrn:

This is a question from a beginner) condition in the code for an example, help please.

How to make a message at the true condition was output once, that is price>ma output one message (and not multiply), I think you know what I mean.

How to properly prescribe the counter?

if(Work==false) // Критическая ошибка
     {
      if(AlertWork==false)   // Если Алерта еще не было
        {  Alert("Критическая ошибка. Эксперт не работает."); AlertWork=true; }
      return;
     }                        

How so, but you have not once need to display the alert, respectively, the flag will have to reset.

 

Hi, could you tell me how to program a custom indicator so that extra lines (buffers) are not displayed when the indicator is attached to the chart?


 
Alexey Kazmin:

Hi, could you tell me how to program a custom indicator so that extra lines (buffers) are not displayed when the indicator is attached to the chart?


use these properties

#property indicator_buffers 5
#property indicator_plots   1
 
Vitaly Muzichenko:


Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL4 MT4 MetaTrader 4

Vitaly Muzichenko, 2020.06.14 16:29

Works in MT5, but I got silence in MT4 with the same settings

Build 1260


Strange things. Yesterday and today my sending did not work, and just now it has worked and the message has been sent. Didn't change or rebuild anything at all.

 
Igor Makanu:

use these properties

Thanks, I'll give it a try.

 
I'm confused about graphical objects, I can't figure out how to get X Y coordinates High[0] in pixels from CORNER_RIGHT_UPPER? What would be the functions to calculate int X and int Y?
 
Valeriy Yastremskiy:

Somehow, but you have to display the alert more than once, so the flag will have to be reset.

   if(sizeBar && maxmin)
     {
      
                   while(true)
                   {
                         int ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 5, sl, tp);
                         if(ticket>0) break;                        
                   }      
             
     }

I still don't understand

Suppose there is a condition for opening a position, say the price should be above the wrist and a Buy order is opened.

This condition will be true over a long time and at each iteration an order will be opened by this code

How should I make one order be opened by this condition and that will be it?

 
a.lxrn:

I don't get it.

Let's assume there is a condition for opening a position, let's assume the price should be higher than the wrist and a buy order will be opened.

This condition will be true over a long time and at each iteration an order will be opened by this code

How should I make one order be opened by this condition and that will be it?

If the open order condition is true and the open order flag is false, then open an order and set the open order flag to true.
 
a.lxrn:

I don't get it.

Let's assume there is a condition for opening a position, let's assume the price should be higher than the wrist and a buy order will be opened.

This condition will be true over a long time and at each iteration an order will be opened by this code

How should I make one order be opened by this condition and that will be it?

If the open order condition is true and the open order flag is false, then open an order and set the open order flag to true.
 

OrderDelete

Please help me find a bug in the code. Neither compiler nor tester shows an error, but limits are not deleted...

void OnTick()
            
      if (Low[1] < val2 && BUY() == 0 && BUYLIMIT1() == 0 && BUYLIMIT2() == 0)

      {
      
      SL = NormalizeDouble(Ask - StopLoss*Point, 5);
      TP = NormalizeDouble(Ask + TakeProfit*Point, 5); 
          
      ticket = OrderSend(Symbol(), OP_BUY, Lots, price, 3, SL, TP, "EU buy", Magic, 0, Red);
      
      if(ticket<0)
         Print("Не удалось открыть ордер");
      }
            
      {
      if (BUY() == 1 && BUYLIMIT1() == 0 && BUYLIMIT2() == 0)
      {
      
      SL = NormalizeDouble(price1 - StopLoss1*Point, 5);
      TP = NormalizeDouble(price1 + TakeProfit1*Point, 5); 
     
      ticket1 = OrderSend(Symbol(), OP_BUYLIMIT, Lots1, price1, 3, SL, TP, "EU buy", Magic1, 0, Red);
      

            {
            if (BUY() == 0 && BUYLIMIT1() == 1)
            {
            for(int i=OrdersTotal()-1; i>=X; i--)
            if(OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES)&&
               OrderType() == OP_BUYLIMIT &&
               OrderMagicNumber()==Magic1)
               {
            res=OrderDelete(OrderTicket(),clrWhite);
               Print("OrderDelete error ",GetLastError());
               }
              return;}
      } } }
      
      {
      if (BUYLIMIT1() == 1 && BUYLIMIT2() == 0)
      {
      
      SL = NormalizeDouble(price2 - StopLoss2*Point, 5);
      TP = NormalizeDouble(price2 + TakeProfit2*Point, 5); 

      ticket2 = OrderSend(Symbol(), OP_BUYLIMIT, Lots2, price2, 3, SL, TP, "GU buy", Magic2, 0, Red);
      

            {
            if (BUY1() == 0 && BUYLIMIT2() == 1)
            {
            for(int i=OrdersTotal()-1; i>=X; i--)
            if(OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES)&&
               OrderType() == OP_BUYLIMIT &&
               OrderMagicNumber()==Magic2)
               {
            res=OrderDelete(OrderTicket(),clrWhite);
               Print("OrderDelete error ",GetLastError());
               }
              return;}
      } } }     
      
                               
}


//+------------------------------------------------------------------+
int BUY()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i>=X; i--)
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
         OrderMagicNumber() == Magic &&
         OrderType() == OP_BUY)
         {
         count++;
         }

     }
     return(count);
}

//+------------------------------------------------------------------+
int BUYLIMIT1()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i>=X; i--)
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
         OrderMagicNumber() == Magic1 &&
         OrderType() == OP_BUYLIMIT)
         {
         count++;
         } 
     }
     return(count);
}

//+------------------------------------------------------------------+
int BUY1()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i>=X; i--)
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
         OrderMagicNumber() == Magic1 &&
         OrderType() != OP_BUYLIMIT)
         {
         count++;
         } 
     }
     return(count);
}

//+------------------------------------------------------------------+
int BUYLIMIT2()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i>=X; i--)
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
         OrderMagicNumber() == Magic2 &&
         OrderType() == OP_BUYLIMIT)
         {
         count++;
         }
     }
     return(count);
}

//+------------------------------------------------------------------+
int BUY2()
{
   int count = 0;
   for(int i=OrdersTotal()-1; i>=X; i--)
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
         OrderMagicNumber() == Magic2 &&
         OrderType() != OP_BUYLIMIT)
         {
         count++;
         }
     }
     return(count);
}