[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 125

 
pyatka__ASD:
Can you tell me if anyone has a piece of software that has a high and low zig zag extremum connection. Thanks

I don't know which connection you need, but... This is how I determine in the EA which zigzag extremum is available - low or high, hopefully you will find what you need:

//-----------------------------------------------------------------------------------------------------------------   
   if (op==OP_BUY)
      {
         for (m=1; m<=CalcBarsLimit; m++)                      // Найдём первый перелом ЗЗ слева от первого бара
            {
               zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, m); // Берём данные 0 буфера ЗЗ с бара m
               if (zz!=0 &&                                    // Если первый экстремум верхний
                  NormalizeDouble(zz, dg)==NormalizeDouble(iCustom(sy, tf, "ZigZag", dp, dv, bs, 1, m), dg))
                     return(false);                            // Валим отсюда
               else if (zz!=0 &&                               // Если первый экстремум нижний
                        NormalizeDouble(zz, dg)==NormalizeDouble(iCustom(sy, tf, "ZigZag", dp, dv, bs, 2, m), dg)) 
                  {
                     if (MathRound((KLevel-zz)/pt)>=DistanceMIN &&         // Если расстояние от ZZ до KLevel ...
                         MathRound((KLevel-zz)/pt)<=DistanceMAX)           // ... в заданных пределах
                        {
                           if (Open[1]<KLevel && 
                               Close[1]>KLevel &&
                               pa>KLevel)
                              {
                                 Fibo0_PriceB=zz;                                   // Сохраним цену излома ZZ
                                 Fibo23_PriceB=pa;                                  // Сохраним цену 23 фибы
                     
                                 nmKLB=DoubleToStr(Time[m], 4);                     // имя метки
                                 SetArrow(5, DeepSkyBlue, nmKLB, Time[m], zz, 1);   // Отмечаем излом ЗЗ на графике
                                 return(true);
                              }
                        }       
                  }
            }
      }
//-----------------------------------------------------------------------------------------------------------------   
   if (op==OP_SELL)
      {
         for (m=1; m<=CalcBarsLimit; m++)                      // Найдём первый перелом ЗЗ слева от первого бара
            {
               zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, m); // Берём данные 0 буфера ЗЗ с бара m
               if (zz!=0 &&                                    // Если первый экстремум нижний
                  NormalizeDouble(zz, dg)==NormalizeDouble(iCustom(sy, tf, "ZigZag", dp, dv, bs, 2, m), dg))
                     return(false);                            // Валим отсюда
               else if (zz!=0 &&                               // Если первый экстремум верхний
                        NormalizeDouble(zz, dg)==NormalizeDouble(iCustom(sy, tf, "ZigZag", dp, dv, bs, 1, m), dg)) 
                  {
                     if (MathRound((zz-KLevel)/pt)>=DistanceMIN &&         // Если расстояние от ZZ до KLevel ...
                         MathRound((zz-KLevel)/pt)<=DistanceMAX)           // ... в заданных пределах
                        {
                           if (Open[1]>KLevel && 
                               Close[1]<KLevel &&
                               pb<KLevel)
                              {
                                 Fibo0_PriceS=zz;                                // Сохраним цену излома ZZ
                                 Fibo23_PriceS=pb;                               // Сохраним цену 23 фибы
                     
                                 nmKLS=DoubleToStr(Time[m], 4);                  // имя метки
                                 SetArrow(5, BurlyWood, nmKLS, Time[m], zz, 1);  // Отмечаем излом ЗЗ на графике
                                 return(true);
                              }
                        }       
                  }
            }
      }

   return(false);
}
//-------------------------------------------------------------------------------

ZS... The code is rough and unoptimized. I hope you know it's better to subtract two normalized values and check the result for zero...

 
alsu:

You can. Return to the parameters.

how? if a variable is declared inside start, can you assign it to return_value1?
 
eddy:
how? if a variable is declared inside start, you can assign it to return_value1?

Yes. This is called passing a parameter by reference. If a function is declared normally, its call causes all variables, passed as formal parameters, to be copied to the local variables of the function and handled. The copying is not performed when parameters are passed by reference, i.e., the function operates with their originals, not with their copies. Accordingly, all changes made in the function code with these parameters, remain effective after returning from the function code.

To pass a parameter by reference, indicate this method in the function declaration by putting the & sign before the identifier of the required parameter.

 

Example (compile as a script and check)

void Func1(double a)
{
   a=a*2;
}

void Func2(double &a)
{
   a=a*2;
}

int start()
{
   double a=5;

   Func1(a);
   
   Print(a); //выведет 5

   Func2(a);
   
   Print(a); //выведет 10
}
 
eddy:
5*5=5?))
is not multiplied by 5, but by 2. In the first case, the parameter a is passed "by value" and its content is not saved after exiting the function, in the second case it is passed by reference (double &a), so the changed value, i.e. 5*2=10 will be contained in the variable a after exiting the Func2 function.
 

cool:)

How about this?

double a=5;

   Print(Func2(a));
 
eddy:


How about this?

that would be ten. It's quicker to check than to ask, by the way)))
 

The computer is busy with calculations, so I can't check it myself at the moment.

There is a piece of code like this:

   if(DecreaseFactor>0){
      for(int cnt=OrdersHistoryTotal()-1; cnt>=0; cnt--){
        if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)){ 
          if(OrderMagicNumber()==Magic){
            if(OrderSymbol()==Symbol()){
              if(OrderType()<2){ 
                  if(OrderProfit()>0) break;
                  if(OrderProfit()<0) losses++;
       } } } } } 
      if(losses>1) Lot=NormalizeDouble(Lot-Lot*losses/DecreaseFactor,1);
    }

Google has found several repetitions of this code, so I conclude that it works.

However, this line

Lot=NormalizeDouble(Lot-Lot*losses/DecreaseFactor,1);

is confusing.

If DecreaseFactor=3 and losses=3, then according to the formula we get Lot=0 !!!

If losses>3, we getLot<0!!!

Is it possible?

 
well, what is the losses and DecreaseFactor then?
 
eddy:

cool:)

How about this?

it won't do anything. The function Funk2 - does not return any value. it is void