[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 206

 
Roman.:


Thank you Roman!
 
alsu:
It's not "should be of type double" but "will be stored in a global variable as double". Feel

Good afternoon. I tried to "feel the difference" and this is what came out of it... I.e. you can (with some stretch) REALLY define a GV-variable as follows. A GV-variable is a so to say "box" into which you can store a variable of any type (except string, because a GV-variable is of double type only, while the typecasting rule does not permit type reduction, i.e. you cannot make a string a double). And this variable, which we'll insert into a GV-variable, "will take the form of this box" (i.e. it will be casted from source type to double type)... Anyway, it's like this, isn't it?

Thank you in advance for your reply.
 

Good Afternoon. The question is as follows. InS.K .'sMQL4book , inthe "Trading Operations" section, there is an example of a simple script that modifies a pending order whose declared price is higher than that of other pending orders (modifyorderprice.mq4) as follows:

//--------------------------------------------------------------------
// modifyorderprice.mq4 
// Предназначен для использования в качестве примера в учебнике MQL4.
//--------------------------------------------------------------- 1 --
int start()                                     // Спец.функция start
  {
   int Tral=10;                                 // Дист. приближения
   string Symb=Symbol();                        // Финанс. инструмент
   double Dist=1000000.0;                       // Предустановка
   double Win_Price=WindowPriceOnDropped();     // Здесь брошен скрипт
//--------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Цикл перебора ордер
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         //------------------------------------------------------ 3 --
         if (OrderSymbol()!= Symb) continue;    // Не наш фин.инструм.
         if (OrderType()<2) continue;           // Рыночный ордер  
         //------------------------------------------------------ 4 --
         if(NormalizeDouble(MathAbs(OrderOpenPrice()-Win_Price),Digits)
            < NormalizeDouble(Dist,Digits))     // Выбираем ближайший
           {
            Dist=MathAbs(OrderOpenPrice()-Win_Price);// Новое значение
            int    Tip   =OrderType();          // Тип выбранного орд.
            int    Ticket=OrderTicket();        // Номер выбранн. орд.
            double Price =OrderOpenPrice();     // Цена выбранн. орд.
            double SL    =OrderStopLoss();      // SL выбранного орд.
            double TP    =OrderTakeProfit();    // TP выбранного орд.
           }                                    // Конец if
        }                                       // Конец анализа ордера
     }                                          // Конец перебора орд.
//--------------------------------------------------------------- 5 --
   if (Tip==0)                                  // Если отложенных нет
     {
      Alert("По ",Symb," отложенных ордеров нет");
      return;                                   // Выход из программы
     }
//--------------------------------------------------------------- 6 --
   while(true)                                  // Цикл закрытия орд.
     {
Or there is an error in this script in block 5-6, because (as I see it) the line
if (Tip==0)                                  // Если отложенных нет
Should be of the form
if (Tip<2)                                  // Если отложенных нет
since all types of non-pending (market) orders have type 0 or 1, i.e. less than 2.

Or have I misunderstood something.

Question: Could you please clarify: if I have misunderstood something, what is it?

Thank you in advance for your answer.

 
7777877:

Good afternoon. I have the following question. InS.K.' sMQL4book, inthe "Trading Operations" section, there is an example of a simple script that modifies a pending order whose declared price is closer to the point where the script is attached than the prices of other pending orders(

Or there is an error in this script in block 5-6, because (as I see it) the line

should look like

this because all types of non-pending (market) orders have type 0 or 1, i.e. less than 2.

Or I misunderstood something.

Question: could you please make me clear: if I misunderstood something, what

exactly?

Thanks in advance for the answer

dear... don't write in such big letters here... you might break your eyes :-)

and that... before you ask questions... have you tried reading the BACKGROUND in MetaEditor? All of it?...for starters...so you don't ask stupid questions about types and stuff like that....

===

Type of operation for OrderSend() function. Can be any of the following values:

Constant Value Description
OP_BUY 0 Buy
OP_SELL 1 Sell
OP_BUYLIMIT 2 BUY LIMIT pending order
OP_SELLLIMIT 3 Pending SELL LIMIT order
OP_BUYSTOP 4 Pending BUY STOP order
OP_SELLSTOP 5 Pending SELL STOP order
 

but as for the type - there's nothing wrong... exactly ==0 should be...

because in the 3rd block

      if (OrderType()<2) continue;           // Рыночный ордер  

market orders are skipped...

===

and if the pending orders are found in the order list, the TYPE variable will not equal 0

---

 

Good afternoon. Can you give me a hint?

For example, we have criterion for MA pass through Level_R and Level_S:

int Criterion;
double MA_1=iMA(......,0);
double MA_2=iMA(......,1);
double MA_3=iMA(......,2);
if(MA_1 > Level_S_1 && Ma_2 <= Level_S_2 MA_3 <= Level_S_3) Criterion=1;
if(MA_1 > Level_R_1 && Ma_2 <= Level_R_2 MA_3 <= Level_R_3) Criterion=2;

Question: how do we memorise the Criterion so that it holds a value of 1 or 2 (depending on the pass) until a new pass occurs and not reset on subsequent ticks .

 
Put the variable definition outside the Start or other function... Into global variables...
 
Aleksander:
Put the variable definition outside the Start or other function... Into global variables...
I've tried that, and he's been swearing... hinting at my incompetence.
 
then if the text is small, post the whole text... 20-30 lines at most
 
int Criterion, Crit;
int start()
 {
  Crit= Fun_Criterion( Criterion); 

  switch(Crit)
   {
   /************/
   }
return(0);
 }

Fun_Criterion(int Criterion)
 {
  if(MA_1 > Level_S_1 && Ma_2 <= Level_S_2 MA_3 <= Level_S_3) Criterion=1;
  if(MA_1 < Level_R_1 && Ma_2 >= Level_R_2 MA_3 >= Level_R_3) Criterion=2;

  return(Criterion);
 }
Reason: