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

 
hoz:


:) Why not implement this as a new bar function? You need it to recalculate once a day, i.e. starting from 0.00 o'clock. So we do it simply. At start of course:

In my opinion, this is the right way although it is primitive!
Vinin, your namesake, told me that it should change by itself, but it never did, only with compilation. Thanks for the idea of using bar control! Put one variant on one chart, your variant on the other. I'll see what works tomorrow.
 
hoz:


It's not either, it's E. There's a && sign.

OR. Because AND condition is not fulfilled when at least one of the operands is false (first OR second) - in boolean logic this is called"De Morgan's law".

I get it. But the point is this:

Variableindex in general by code has value Bar - IndicatorCounted().

I.e. it is 1 on the current bar and 2 on the new one.

It enters the IsUpFractal() function with the value either 1 or 1 if the bar is not yet new, right?

So, the i variable will have a fixed value since the input parameter index is also fixed. So the loop will always break after the first iteration. What is the purpose of the loop then?

At each cycle step, the variable i is decremented by 1 (i--), so i runs all values from index+g_center-1 to zero. In addition, notice that when indicator first starts, IndicatorCounted() gives 0, i.e. index will run on all bars, so i is assigned index+g_center-1 each time and then runs down until it reaches 0 bar OR until cnt equals g_center, i.e. until loop condition is not satisfied (well, or until return, located in loop body itself, is called).
 
alsu:

OR. Because the AND condition is not fulfilled when at least one of the operands is false (first OR second) - in Buda logic this is called"De Morgan's law".

Wow. What a mess. How many times have I used these operators... and here it's like"I'm looking at a new gate". I read the law, it's written in a weird way. It describes a denial situation. I take it this technique only applies to denial situations? I mean if any of boolean variables is not equal toTrue.

I realised as I went along that I didn't stick it in. The bottom line is that the difference here is as follows. It's an indicator, which is why I'm not used to thinking this way. This means that at first call of the indicator, the bars are not calculated and index will be equal to the number of bars in the chart or to the value of some variable limitReCalcBar, if the conditions of calculation of bars are limited.

As a matter of fact, variable g_center = 2 based on the code.limitReCalcBar = 5000 also based on external variables.

When first running the indicator in the function:

//+-------------------------------------------------------------------------------------+
//| Определение наличия верхнего фрактала на указанном баре                             |
//+-------------------------------------------------------------------------------------+
bool IsUpFractal(int index)
{
   double centerHigh = High[index + g_center];     // За точку отсчета берется средний..
                                                   // ..бар на участке из i_fractalPeriod
                                                   // ..баров
// - 1 - == Поиск максимумов справа от центрального бара ================================
   int cnt = 0, i = index + g_center - 1;
   for (; i >= 0 && cnt < g_center; i--)           // Справа от центрального бара должно
   {                                               // ..быть g_center-1 баров с низшим..
      if (centerHigh <= High[i])                   // ..максимумом. Не позволяется..
         return (false);                           // ..наличие баров с большим или..
      cnt++;                                       // ..равным максимумом.
   }
   
   if (i < 0)                                      // g_center-1 низших максимумов не..
      return (false);                              // ..найдено. Фрактала нет
// - 1 - == Окончание блока =============================================================

// - 2 - == Поиск максимумов слева от центрального бара =================================
   cnt = 0;
   i = index + g_center + 1;
   int total = Bars - 1;
   for (; i < total && cnt < g_center; i++)        // Слева от центрального бара должно
   {                                               // ..быть g_center-1 баров с низшим..
      if (centerHigh == High[i])                   // ..максимумом. Не позволяется..
         continue;                                 // ..наличие баров с большим..
      if (centerHigh < High[i])                    // ..максимумом. Равный - позволяется
         return (false);
      cnt++;                                    
   }
   
   if (i >= total)                                 // g_center-1 низших максимумов не..
      return (false);                              // ..найдено. Фрактала нет
// - 2 - == Окончание блока =============================================================
                                                   
   return (true);                                  // Фрактал найден                 
}

is passed the value of 5000 accordingly.

i = index + g_center - 1 = 5000 + 2 - 1 = 5001

Let's look into the loop:

for (; i >= 0 && cnt < g_center; i--)

We need to calculate 5000 bars. After the first two bars i.e. 0 and 1 the conditioncnt < g_center is false. How can we then calculate all 5000 bars? This is the point I want to master. It seems to be elementary for a pro, but I don't get it. Of course, if we take the && operator as an OR, everything will fall into place... But it somehow contradicts what I have already used in Expert Advisors and have ever met.

Well, when everything is calculated, everything will be simple. 0 and 1 will be passed at every tick through index, conditions will be fulfilled in a loop and there are no difficulties, as I see.

 

Dear programmers! Can you please tell me if it is possible to write a script that monitors open positions and when a position reaches a certain level of loss, it closes part of the position. The loss threshold should be set in either the deposit currency, or in points. Thus, if the price goes against us, we reduced the loss and if the price turned to the profit, then instead of the loss we may get some profit or even smaller loss, depending on TP set. The script has to work all the time in EA mode, it is an assistant to any trading system or Expert Advisor.

 
destan:

Dear programmers! Can you please tell me if it is possible to write a script that monitors open positions and when a position reaches a certain level of loss, it closes part of the position. The loss threshold should be set in either the deposit currency, or in points. Thus, if the price goes against us, we reduced the loss and if the price turned to the profit, then instead of the loss we may get some profit or even smaller loss, depending on TP set. The script should always work in the EA mode, it is an assistant to any trading system or Expert Advisor.

Perhaps. There is help here.

 
valeryk:

Maybe. There is help here.


There's a thing called a stop loss!!!
 

Hello, I have a question. There are several equal windows in the terminal, each of them has the same Expert Advisor, but with different settings. Can you tell me if there is a function or a ready algorithm in MQL4 that can detect which window a market order is opened from?

 
badbadboy:

Hello, I have a question. There are several identical windows in the terminal, each of them has the same Expert Advisor, but with different settings. Can you tell me if there is a function or a ready algorithm in MQL4 that allows you to determine which window a market order is open?

It makes more sense to make copies of the EA, naming them differently and you'll see in the log everything, which spear and, therefore, in which window you'll find it!
 
borilunad:
It makes more sense to make copies of the EA, naming them differently, and you will see in the logbook which copy and in which window you will be able to figure it out!

I will figure it out, but how do I inform the Expert Advisor about it?
 
borilunad:
It makes more sense to make copies of the EA, naming them differently, and you will see in the log everything, which spear and, accordingly, in which window you already know!

I need this so that the Expert Advisor can start making calculations on its own.