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

 
snail09:
Either count all left brackets, then all right brackets, then compare quantities, or comment functions one by one until you find the error. Everyone's taste and colour (source code design) is different.
there are 4 opening brackets and 4 closing brackets, all right. But how the comments can help me is not quite clear
 
Pinki:
There are 4 opening brackets and 4 closing brackets, all right. But how the comments can help me not quite understand

You can comment out custom functions first, then comment out loops, logical constructs... I can assure you that you will find a match to your bracket by sequential cutting off. Or maybe you forgot to put ";" somewhere as well...

Aren't you mistaken IF for FOR?

Sorry, I didn't notice it at once.

   // Перебор в цикле всех рыночных и отложенных ордеров
   for(int i=0;i<=OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
         // Если инструмент и магик соответствуют - значит ордер наш
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            {
            // Подсчитываем только рыночные ордера
            if(_Type==OP_BUY || _Type==OP_SELL) 
               {
               op++;
               }
            }
         }
     }

Compare it with this fragment. It's just a variant.

 
001:

Who can explain why the 6th order did not open on the candlestick and what to do to make it open?

Log.

2011.11.04 19:42:21 1999.11.04 20:00 RLB_FLAT GBPUSD,H4: open #7 sell stop 0.10 GBPUSD at 1.62233 sl: 1.64443 tp: 1.57089 ok
2011.11.04 19:42:21 1999.11.04 20:00 Tester: #6 deleted due expiration
2011.11.04 19:42:10 1999.11.04 12:00 RLB_FLAT GBPUSD,H4: open #6 sell stop 0.10 GBPUSD at 1.63373 sl: 1.64570 tp: 1.62652 ok
2011.11.04 19:42:09 1999.11.04 08:00 Tester: #5 deleted due expiration
2011.11.04 19:42:06 1999.11.04 00:00 RLB_FLAT GBPUSD,H4: open #5 sell stop 0.10 GBPUSD at 1.63622 sl: 1.64702 tp: 1.63411 ok
2011.11.04 19:42:00 1999.11.02 04:00 Tester: #4 deleted due expiration
2011.11.04 19:41:53 1999.11.01 20:00 RLB_FLAT GBPUSD,H4: open #4 sell stop 0.10 GBPUSD at 1.63365 sl: 1.64917 tp: 1.61097 ok

The fourth, fifth and sixth pending orders have been deleted due to expiry.

Increase their lifetime or set 0 (zero), see. OrderModify()

 
мmersi:

The fourth, fifth and sixth deferrals have been deleted due to their expiry date.

Increase their expiry date or set it to 0 (zero) see OrderModify(). OrderModify()


What confuses me is that before the 6th order expired (it expired at 20:00) there was a candle down at 16:00. This can be seen in the picture.
 
mersi:

1. The function finds the order with the highest ticker in the history, which means the last closed order (unless, of course, there is an exceptional case, for which your option with the maximum closing time is preferable).

2. According to the conditions , the first order is opened with the specified TP/SL and only the second order may be opened with the new TP/SL, which means that the function can return zero only if the first trade was zero, but not if there are no closed orders in the history.

One last thing. In your variant the use of j and another SELECT in the function is redundant.

it is enough:

if (t<OrderCloseTime()) {
         t=OrderCloseTime();
      Profit=OrderProfit()+OrderSwap()+OrderCommission();
  }
   return(Profit);

1. You can rely 100% on your broker (or the client's broker), about his numbering of tickets? Time is still a more stable value - here he can only change the time manually by adjusting the history. IMHO - better to use time.

2. If the client will need to change the logic, then your function may have to be rewritten.

3. Do you suggest

Profit=OrderProfit()+OrderSwap()+OrderCommission();

to use it inside a loop? What for? You can only use it once for the last order already found.

А... Your customer will not test and optimise. I see...

 

GlobalVariableSetOnCondition() - can you please explain in plain language what this function does? The description in the help is very confusing, I can not understand some points?

Sets a new value of the existing global variable if the current value of the variable is equal to the value of the third parameter check_value. If the variable doesn't exist, the function will generate error ERR_GLOBAL_VARIABLE_NOT_FOUND (4058) and return FALSE. The function will return TRUE if executed successfully, otherwise it will return FALSE. To get the error information, the function GetLastError() must be called. If the current value of the global variable is different from check_value, the function will return FALSE.
This function allows atomic access to the global variable, so it can be used to create a semaphore for concurrent communication between several Expert Advisors in the same client terminal.

 
fore-x:

GlobalVariableSetOnCondition() - can you please explain in plain language what this function does? The description in the help is very confusing, I can't understand some points?

Sets a new value to an existing global variable, if the current value of the variable is equal to the third parameter of check_value. If the variable doesn't exist, the function will generate an error ERR_GLOBAL_VARIABLE_NOT_FOUND (4058) and return FALSE. The function will return TRUE if executed successfully, otherwise it will return FALSE. To get the error information, the function GetLastError() must be called. If the current value of the global variable is different from check_value, the function will return FALSE.
This function allows atomic access to the global variable, so it can be used to create a semaphore for concurrent communication between several Expert Advisors in the same client terminal.

GlobalVariableSetOnCondition("Имя переменной", устанавливаемое значение, проверяемое значение);

Suppose you have a global variable GL_Var.

It currently has a value of 1.0.

You need to check if this variable has a value of 1.0 and, if so, set this variable to 2.0

It will be like this:

GlobalVariableSetOnCondition(GL_Var, 2.0, 1.0);

In order to handle the return values of this function, you can call it via if

if (!GlobalVariableSetOnCondition(GL_Var, 2.0, 1.0)) {
   // здесь код обработки, если функция вернула false
   // false она вернёт в случае, если переменная GL_Var не была равна 1.0 во время вызова этой функции
   // или если вообще ещё нет глобальной переменной GL_Var
   }

Before calling the function, you can check if the global variable GL_Var exists, to avoid the error ERR_GLOBAL_VARIABLE_NOT_FOUND

 

Please help in solving a small geometric problem. There is a line with coordinates p1 and p2 (shown in red in the picture). I need to find the coordinate of p3, which is 38.2% of the coordinate of p2. I have done the following:

if(p2>p1) p3=p2-(p2-p1)*0.382; true for the top of the figure

if(p1>p2) p3= p2+(p1-p2)*0.382; true for the lower part of the figure

Is there any way to write this down in one equation without "if" ?

 

Well, write it that way.

p3=p2-(p2-p1)*0.382

 
Roger:

Well, write it that way.

p3=p2-(p2-p1)*0.382


And indeed! Thank you for your help.
Reason: