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

 

@Konstantin Nikitin It's easier for you! You're an expert! I'm learning!

if(!OrderSelect(i,SELECT_BY_POS)) continue;
     if(OrderSymbol()!=Symbol()) continue;
А это как прочитать? Если (Ордер не выбран) продолжить;
                     Если (Текущий Символ не равен Символу) продолжить; Так? Или как?
 

Rewerpool:

How do you read this? If (Order is not selected) continue;

If (Current Symbol is not equal to Symbol) continue; Right? Or how?

Operator continue

 

@Konstantin Nikitin Got it, so: Correct me if anything!

if(!OrderSelect(i,SELECT_BY_POS)) continue;
Если (Ордер не выбран ордер) начать цикл снова; //(Вернутся в начало функции)
if(OrderSymbol()!=Symbol()) continue;
Если (ОрдерСимвола не равен текущему Графику)начать цикл снова; //(Вернутся в начало функции)


And here's another question: !OrderSelect - does it mean: No Order or No Order selected?

 
Rewerpool:

Got it, so: Correct me if there's anything!

If no order is selected, the next element of the loop is selected

Also, here's a question: !OrderSelect - does it mean: Not an Order or Not an Order selected?

Operations and expressions and look at logical operations there

 
@Konstantin Nikitin Put it together like this:
 void STOP_TAKE()
   int tip,Ticket;
   double OOP,OSL,OTP;
   int SPREAD    = (int)MarketInfo(Symbol(),MODE_SPREAD);
   if (stoploss<STOPLEVEL) stoploss=0; 
   if (takeprofit<STOPLEVEL) takeprofit=0; 

for(int i=0; i<OrdersTotal(); i++)
{
     if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
     if(OrderSymbol()!=Symbol()) continue;
     
     int tip = OrderType();
     if(tip!=OP_BUY && tip!=OP_BUYSTOP && tip!=OP_BUYLIMIT) continue;
     
     // переменные которые будут использоваться в любых ордерах
     int Ticket = OrderTicket();
     double OOP = OrderOpenPrice();
     
     //---
     switch( OrderMagicNumber() )
     {
          case Magic:    //----------Если Ордера Советника
               {
                if(tip<2)
           {
            OSL = OrderStopLoss();
            OTP = OrderTakeProfit();
            if ((OSL==0&&stoploss!=0)||(OTP==0&&takeprofit!=0))
            {  
              if (tip==OP_BUY || tip==OP_BUYSTOP || tip==OP_BUYLIMIT)             
               {
                  if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                  if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;       
                  if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                  else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
               }                                         
               if (tip==OP_SELL || tip==OP_SELLSTOP || tip==OP_SELLLIMIT)        
               {
                  if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                  if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                  if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                  else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
               } 
            }
         }
               }
               break;

          default:       //----------Если Ордера Оператора 
               {
                 {
                if(tip<2)
           {
            OSL = OrderStopLoss();
            OTP = OrderTakeProfit();
            if ((OSL==0&&stoploss!=0)||(OTP==0&&takeprofit!=0))
            {  
              if (tip==OP_BUY || tip==OP_BUYSTOP || tip==OP_BUYLIMIT)             
               {
                  if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                  if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;       
                  if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                  else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
               }                                         
               if (tip==OP_SELL || tip==OP_SELLSTOP || tip==OP_SELLLIMIT)        
               {
                  if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                  if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                  if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                  else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
               } 
            }
         }
               }
               }
     }
}
Right?
 

added more like this:


6

 

Why even write it that way?

if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
     if(OrderSymbol()!=Symbol()) continue;

If you only put the EA on one symbol, but it will work on all of them? And the magician will see his own!

Completely confused!

 

My friends, who knows how to implement: EA can get the absolute value of indicator, for example iStohastic(). How can I tell if the indicator has left overbought or oversold zone?

Visually, like a Stochastic indicator with levels 80 and 20.

 

Rewerpool: Well, there you go, no mistakes.

void STOP_TAKE(void)
{
   int SPREAD    = (int)MarketInfo(Symbol(),MODE_SPREAD);
   if (stoploss<STOPLEVEL) stoploss=0; 
   if (takeprofit<STOPLEVEL) takeprofit=0;

     for(int i=0; i<OrdersTotal(); i++)
     {
          if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if(OrderSymbol()!=Symbol()) continue;
     
          int tip = OrderType();
          if(  tip!=OP_BUY && tip!=OP_BUYSTOP && tip!=OP_BUYLIMIT &&
               tip!=OP_SELL && tip!=OP_SELLSTOP && tip!=OP_SELLLIMIT ) continue;
     
          // переменные которые будут использоваться в любых ордерах
          int Ticket = OrderTicket();
          double    OOP = OrderOpenPrice(),
                    OSL = OrderStopLoss(),
                    OTP = OrderTakeProfit();
     
          //---
          if( OrderMagicNumber() == Magic )
          { //----------Если Ордера Советника
               switch(tip)
               {
                    case OP_BUY:
                    case OP_BUYSTOP:
                    case OP_BUYLIMIT:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         }
                         break;
                         // end case
                         
                    default:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         } // end case
               } // end switch

          }
          else
          { //----------Если Ордера Оператора
               switch(tip)
               {
                    case OP_BUY:
                    case OP_BUYSTOP:
                    case OP_BUYLIMIT:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;       
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         }
                         break;
                         // end case
                         
                    default:
                         {
                              if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
                              if (stoploss!=0)   SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;             
                              if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL,"   TP ",OTP," -> ",TP);
                              else Print(Symbol()," Error STOP_TAKE",GetLastError(),"  Ticket ",Ticket);
                         } // end case
               } // end switch
          } // end if
     } // end for
} // end STOP_TAKE
Although you have exactly the same logic when modifying EA and other orders. Why exactly you need to distinguish them is not quite clear. But I think the principle is useful.
 
@Konstantin Nikitin USEK POWERFUL!!! THANK YOU for the breakdown!!!
Reason: