Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 133

 
T-G:

Professionals can't go anywhere without you.

Help with the function. Which counts the last number of losing orders in the history to a plus order.

I.e., the history shows 3 last orders in minus, then 1 in plus and 2 in minus.

This function should count the last three (before the positive order)

int Number=0;
//---
if (OrdersHistoryTotal()>0)
{  for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {  if (OrderProfit()<0.0)
         Number+=1;
         else break;
}  }  }
Orders closed only in deficit are counted here. If earnings = 0 (zero), the counting is interrupted.
 
paladin80:
Orders closed only in deficit are counted here. If earnings = 0 (zero), the counting is interrupted.
It may happen that they do not necessarily go in the order in which you read them. To be exact and unambiguous, the orders should be added up into a two-dimensional array: in the first dimension is the closing time, and in the second is the order ticket. Next, sort the array by the first dimension, trim it down to three and check them (the last three).
 
chief2000:
I want to rephrase and add to my previous question.
Below is the code for an array of 4 elements. Actually the number of items in the array is a variable.
How can I change the code so that the number of nested 'for' loops becomes variable, one 'for' per array item?
Thank you!

int start() { 

   int Array[4]                                       = {1, 2, 3, 4};
   int x1, x2, x3, x4;
   int Array_Size                                  = ArrayRange(Array,0);


   for(x1=0; x1<Array_Size; x1++) {
      Print("Combination                       = ", Array[x1]);

      for(x2=x1+1; x2<Array_Size; x2++) {
         Print("Combination                    = ", Array[x1] + "   " + Array[x2]);

         for(x3=x2+1; x3<Array_Size; x3++) {
            Print("Combination                 = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3]);

            for(x4=x3+1; x4<Array_Size; x4++) {
               Print("Combination              = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3] + "   " + Array[x4]);
            }
         }
      }
   }


   return(0);
}


Looking at this situation, I started to wonder. When a bunch of nested loops are available. How do the calculations take place? From the deepest nested one or vice versa?

I.e. the first to be calculated:

 for(x4=x3+1; x4<Array_Size; x4++) {
               Print("Combination              = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3] + "   " + Array[x4]);

Or from the other side? I want to understand how it all works.

 
how to make an EA take into account the levels of technical indicators. For example cci. If the line is above 0 level, then perform actions. How to do?
 
webip:
How to make an EA take into account levels of technical indicators. For example cci. If the line is higher than 0, then perform actions. How to do?

If cci is greater than zero, then ... If cci is less than zero. then ...

Function iCCI();

 

Gurus, tell me how to solve a problem. We need a positive number when calculating the difference between opening and closing. For example, if the price rises and subtracts the closing price from the opening price, you get a minus number.

 
artmedia70:

If cci is greater than zero, then ... If cci is less than zero. then ...

Function iCCI();



No. I know the function, but I don't know how to reflect it in the code. How about this?

 if(iCCI() > 0)
  {
    //остальной код?
  }
 
Forexman77:

Gurus, tell me how to solve a problem. We need a positive number when calculating the difference between opening and closing. For example, if price goes up and I subtract a negative number from the opening price, I get a negative number.


double MathAbs( double value)
The function returns the absolute value (modulo value) of the number passed to it
 
hoz:

Looking at this situation, I started to wonder. When a bunch of nested loops are available. How do the calculations take place? From the deepest nested one or vice versa?

I.e. the first to be calculated:

Or from the other side? I want to understand how it all works...


You can see the results I gave earlier for 4 cycles, there the innermost cycle is triggered once to get 1234.
 
webip:


I don't. I know the function, but I don't know how to reflect it in the code. How about this?

What's stopping you from trying it?
Reason: