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

 
gince:
Thank you. I've started to write according to your algorithm. But with flags, I'm as far from Peking as you are. Thanks again.


https://www.mql5.com/ru/forum/131516/page34

Down there - an early Article shared his experience. Exactly on this issue.

 
tara:


https://www.mql5.com/ru/forum/131516/page34

Down there - an early Article shared his experience. Exactly on this issue.


SPS
 

What could be the problem?

Sometimes a division by "O" error is shown during a test

double LotsOptimized()
  {
   double lot=Lots;
   double Lot;
   if (isFloatLots == true)          // если флаг true то проводится оптимизация величины лота, иначе лот неизменен
     {  
        int orders=HistoryTotal();  // history orders total
        int losses=0; // number of losses orders without a break
        double loss=0;              
//---- select lot size
        double  lot_min         = MarketInfo( Symbol(), MODE_MINLOT  ); 
        double  lot_max         = MarketInfo( Symbol(), MODE_MAXLOT  ); 
        double  lot_step        = MarketInfo( Symbol(), MODE_LOTSTEP ); 
        double  lotcost         = MarketInfo( Symbol(), MODE_TICKVALUE );       
                
        lot                             = 0.0;
        double  dollarsPerPip   = 0.0;
        
        lot = AccountBalance()*MaxR/100.0;
        dollarsPerPip = lot/SL;
                
        lot = NormalizeDouble( dollarsPerPip/lotcost, 2 );      
        
        lot = NormalizeDouble( lot / lot_step, 0 ) * lot_step;
        
        if ( lot < lot_min ) lot = lot_min;
        if ( lot > lot_max ) lot = lot_max;
        
        if ( AccountFreeMarginCheck( Symbol(), type, lot ) < 10 || GetLastError() == 134 ) 
        { 
                Alert ( "Impossible to open position with lot = ", DoubleToStr( lot, 2 ), ". Not enough money." );
                return(-1);
        }
//---- return lot size
//         if(lot<0.1) lot=0.1;
           
//---- calcuulate number of losses orders without a break
           if(DcF>0)
          {  
        for(int i=orders-1;i>=0;i--)
                  {
                 if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) 
                   { 
                        Print("Ошибка в истории!"); 
                        break;
                   }
                if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) 
                  continue;
                 if(OrderProfit()>0)  break;
                if(OrderProfit()<0) losses++;loss=loss-OrderProfit();
                  }
        if(losses>=losses_orders) {Lot=NormalizeDouble(MathAbs(loss)/FV/MarketInfo(Symbol(),MODE_TICKVALUE)/TakeProfit1,1);
         }
       }
     }  
//---- return lot size
     if (Lot>lot) lot=Lot; 
   
  return(lot);
  }
 
Stells:

What could be the problem?

Sometimes the division by "O" error is shown during a test.


Search for the "/" sign and see which variables from the user take part in the division:

SL ;

FV ;

TakeProfit1 .

Some of them may be 0.

 
Stells:

What could be the problem?

Sometimes a division by "O" error is shown during a test

Do a type test:

if(!SL==0)
   {
  dollarsPerPip = lot/SL;
   }
And so on .
 
ALXIMIKS:


Thank you again. I tried to make out your code and wrote comments. I did it for myself to understand and maybe I'll write something similar. I study and try to figure out the logic of other people's work. Then I try it myself.

Maybe you can find time to check my comments and correct them if necessary. One more question.

  if (Bufer0!=EMPTY_VALUE) 

Does it mean that the indicator buffer is not empty or does this variable mean something else? The indicator buffer would be

Bufer0[i]

All code with comments.

 int    counted_bars=IndicatorCounted();
//----
   int   a1=0,                               //преведущий фрактал (-1 ->нижний, 1 -> верхний)
         a2,                                 //нынешний фрактал  (-1 ->нижний, 1 -> верхний)
         a3,                                 //сума преведущий + нынешний
         kilkict,
         frac,                               //frac - флаг существования фракталов,
         frac1=0;                            //frac1- счетчик фракталов (+1 или 0 за цикл)
   int i;
   double Bufer0;                            //
   kilkict=iBars(NULL, 0);

   for (i=3; i<kilkict;i++){
      a2=0;frac=0;
      if(iFractals(NULL, 0, MODE_UPPER, i)>0) {            
         if (Bufer0!=EMPTY_VALUE) {          //
            a2+=1;                           //к числу фракталов добовляем 1
            frac=1;                          //флаг - фрактал есть
            frac1++;                         //счечик увеличиваем на 1
         }
      }
      if(iFractals(NULL, 0, MODE_LOWER, i)>0) {            
         if (Bufer0!=EMPTY_VALUE) {          //
            if(a2==0){
               frac1++;                      //счечик увеличиваем на 1 
               frac=1;                       //флаг - фрактал есть
            }
            a2+=-1;                          //к числу фракталов добовляем -1(т. е. уменшаем)
         }
      } 
      if (frac==0){continue;}                // если флага нет (фрактал ненайден)
      if (frac1==1){                         //если счечик равен 1,
         a1=a2; continue;
      }          
      a3=a1+a2;
      if(a3<0)           { a1=a2;continue;}//Два фрактала вниз  подряд найдено// 
      if(a3>0)           { a1=a2; continue;}//Два фрактала вверх подряд найдено //
      if(a3==0 && a1==0) { a1=a2;}// Два фрактала подряд вверх и два фрактала подряд вниз найдено //
   }

 

gince:

if (Bufer0!=EMPTY_VALUE) 

Does it mean that the indicator buffer is no longer empty or does this variable mean something else?

This line can be removed, because iFractals() returns zero, not "empty value"(EMPTY_VALUE), as absence of fractal.

My question is as follows: are you trying to make an indicator that will look for two consecutive fractals? Or are you searching in your EA for two consecutive fractals closest to the current bar? This question is not of idle curiosity because the search methods in the indicator and in the Expert Advisor are different - the indicator calculates from the end to the beginning - from past to present, and the Expert Advisor looks through the bars from present to past. Therefore, the search directions are also different for the Expert Advisor and the indicator.

One last question: what should the output result be?

 
artmedia70:

This line can be removed because iFractals() returns zero as no fractal, not "empty value" (EMPTY_VALUE).

My question is as follows: are you trying to make an indicator that will look for two consecutive fractals? Or are you searching in your EA for two consecutive fractals closest to the current bar? This question is not of idle curiosity because the search methods in the indicator and in the Expert Advisor are different - the indicator calculates from the end to the beginning - from past to present, and the Expert Advisor looks through the bars from present to past. Accordingly, the search directions are also different in the Expert Advisor and in the indicator.

And the last question: what should be the output?



The search methods in the indicator and in the EA are different - the indicator calculates from the end to the beginning - from the past to the present, while the EA looks through the bars from the present to the past .

for (i=kilkict;i>0;i--)

The result - top two -> sell (arrow down), bottom two -> buy (arrow up). The signal will appear +2 bars to the right of the fractal. That is what I would like to see visually on the history at the beginning. And probably we will need a filter.

 
ALXIMIKS:


...

something like this...

...


Tell me, explain, how does it happen that instead of "this" they write "this"?

1. Don't you know that "it" is spelled with an "e", not a "f"?

2. Too lazy to move your hand to the letter "e", it's easier to press "e"?

3. is there no "e" key on the keyboard? If not, why not?

4. Is it some kind of special ponce?

5. Some other unknown reason. What's that?

 
Integer:


Can you tell me how come instead of "it" people write "ito"?

1. Don't you know that "it" is spelt with an "e" and not with an "e"?

2. are you too lazy to move your hand to the letter "e", it's easier to press "e"?

3. is there no "e" key on the keyboard? If not, why not?

4. Is it some kind of special ponce?

5. Some other unknown reason. What is it?


I am not Russian and there are no Russian letters on the keyboard. Moreover, I use a phonetic keyboard (it's a software program). I press "p", but it says "p". The letter "e" is there too. I have to type "\".

There are grammatical mistakes, because the grammar has long been forgotten. I had to write in Russian only on forums and that after many years.

I apologize for the mistakes. Do not kick me too much.

Reason: