Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 698

 
Vitaly Muzichenko:

Until you get tired of writing them

seriously?))
 
multiplicator:
seriously?))

Yeah. But as a rule you don't write more than three, because such code is hard to read afterwards, especially if it's been a long time since it was written. It is better to divide these many nested ifs into separate functions. Or use switch operator ... case

 
Artyom Trishkin:
MessageBox()

is there any way to make if I click after a new tick comes in, a new window won't appear, but the values of the first window will be used?

void OnTick()
  {
 if (Orders()<1 && (1==message || !use_MessageBox)){
   ticket=OrderSend(Symbol(), OP_SELL, lot, Bid, slippage, Ask+stopLoss*Point, Bid-takeProfit*Point, "", magic, 0, Red); message=0; 
 } 
 if (Orders()<1 && (message==0 || message==2) && use_MessageBox){
 if(use_PlaySound) PlaySound ("tick");
 message=-2;
 message =MessageBox("Текст, содержащий сообщение для отображения", "Необязательный текст для отображения в заголовке", IDOK);
   }
if (Orders()<1 && (1==message || !use_MessageBox)){
   ticket=OrderSend(Symbol(), OP_SELL, lot, Bid, slippage, Ask+stopLoss*Point, Bid-takeProfit*Point, "", magic, 0, Red); message=0; 
 }

}
 
void Trailing()
{
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
         {
            if (OrderType() == OP_BUY)
            {
               if (Bid - OrderOpenPrice() > TrailingStop*Point)
               {
                  if (OrderStopLoss() < Bid-Point*(TrailingStop+TrailingStep) || OrderStopLoss() == 0)
                  {
                     if (!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue))
                        Print("error order modify");
                  }
               }
            }
         }
      }
   }
   
   if (OrderType() == OP_SELL)
   {
      if (OrderOpenPrice() - Ask > TrailingStop*Point)
      {
         if (OrderStopLoss() > Ask + Point * (TrailingStop+TrailingStep) || OrderStopLoss() == 0 )
         {
            if (!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red))
               Print("error order modify");
         }
      }
   }
}
//--------------------------------------------------------

Good afternoon, in tests trailing works as expected, but in real life does not, or only once in a while, from time to time spams with error OrderModify error 4108, I can not understand what is wrong, please correct it, I understand that the EA does not correctly select orders for modification.

I would like to describe my EA:

When two MAs cross, open 2 positions, one short and one long by magik. The short one closes either at Takei or at the MA crossing over, the long one should trawl. Selection of a long position for a trawl is done on magic number.

Perhaps I made an error in some part of code on position opening:

//BUY
   if (fast1>slow1&&fast2<slow2)
     {
      if (StopLoss_1>0)   sl=NormalizeDouble(Bid-StopLoss_1*Point,Digits);   else sl=0;
      if (TakeProfit_1>0) tp=NormalizeDouble(Ask+TakeProfit_1*Point,Digits); else tp=0;
      closeshrts();
      OrderSend(Symbol(),OP_BUY,Lts,NormalizeDouble(Ask,Digits),5,sl,tp,NULL,0,0,Blue);
     }
   //BUY_2
   if (fast1>slow1&&fast2<slow2)  
     {
      if (StopLoss_2>0)   sl=NormalizeDouble(Bid-StopLoss_2*Point,Digits);   else sl=0;
      if (TakeProfit_2>0) tp=NormalizeDouble(Ask+TakeProfit_2*Point,Digits); else tp=0; 
      closeshrts();
      OrderSend(Symbol(),OP_BUY,Lts,NormalizeDouble(Ask,Digits),5,sl,tp,NULL,MagicNumber,0,Blue);
     }  
     
   //SELL
   if(fast1<slow1&&fast2>slow2)
     {
      if (TakeProfit_1>0) sl=NormalizeDouble(Ask+StopLoss_1*Point,Digits);   else sl=0;
      if (StopLoss_1>0)   tp=NormalizeDouble(Bid-TakeProfit_1*Point,Digits); else tp=0;
      closelongs();
      OrderSend(Symbol(),OP_SELL,Lts,NormalizeDouble(Bid,Digits),5,sl,tp,NULL,0,0,Red);
     }
   //SELL_2
   if(fast1<slow1&&fast2>slow2)
     {
      if (TakeProfit_2>0) sl=NormalizeDouble(Ask+StopLoss_2*Point,Digits);   else sl=0;
      if (StopLoss_2>0)   tp=NormalizeDouble(Bid-TakeProfit_2*Point,Digits); else tp=0;
      closelongs();
      OrderSend(Symbol(),OP_SELL,Lts,NormalizeDouble(Bid,Digits),5,sl,tp,NULL,MagicNumber,0,Red);
     } 

I don't know, maybe I should open orders via a loop? And how to correctly write this code so that correct stops and Take Profits would be set? As I've written it - it works for Sell only, for Buy it sets Stop at 0.

(Please, help me on the right track))

 
Hello, a friend of mine asked me a question about the MQL4 alphabet:
So are the Cyrillic alphabet Russian letters part of the alphabet?
And the question mark ???? is included in the set of characters of the alphabet?????
and the backslash \\\\\\\, is it part of the alphabet or not?
 
enters.
 
Alexander Zhmurenko:
) comes in.

Can you elaborate on what goes in? What I wrote was a quote from an acquaintance. I just copied it and pasted it in. He's trying to teach me MQL. I'm racking my brains, so please write down what goes in.

a ) question mark ( ?)

b) backslash (\ )

 
Zvezdochet:

Can you elaborate on what goes in? What I wrote was a quote from an acquaintance. I just copied it and pasted it in. He's trying to teach me MQL. I'm racking my brains, so please write down what goes in.

a ) a question mark ( ?)

b ) backslash ( \ )

The use of Cyrillic characters is an undocumented feature

Characters that can be used in an ID are: digits 0-9, lowercase and uppercase letters a-z and A-Z, recognizable as different characters, underscore character (_). The first character cannot be a number.

syntax.

 
int OnInit()
  {
//---
   color желтый = clrAqua;
//---
   return(INIT_SUCCEEDED);
  }
the variables can also be
 

Hello, could you please tell me why ZigD[0] is not output in sommente?

   for(ww = 0; ww <= Bars-1; ww++)
  {
      zzz = iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, ww);
      
           if(zzz > 0.0)   
           {
           ZigM[kk]=zzz;
            kk++; 
           ZigD[dd]=ww;
            dd++;  
            }
   }   
Reason: