Questions from Beginners MQL4 MT4 MetaTrader 4 - page 212

 
Aleksei Stepanenko:

It is even better to make a structure

don't forget to zero out the elements before you start using them

and then increase the count where needed

then compare

You have now made a loop around the previous 10 candles on each new cand le. This is not rational. You should always get rid of unnecessary cycles by remembering the results of the calculations of the previous values. In your case, when a new candle arrives, just increase the count when the condition is fulfilled, and if the condition is not fulfilled, then subtract it. And check if there is no excess. Your cycle for 10 elements is not needed, only the main one.

Aleksei, tried to do it, but it still doesn't work right:

does not add one to the count.up

 for(int i=1;i<=10;i++)              
     {    
     count.up=0;
     count.dn=0;
     double hig10 = iMA (NULL,CP,WPER, 0, MODE_SMA, PRICE_CLOSE, i);                                     
     if (hig10>iClose(Symbol(),CP,i))
     {
     count.up++;
     }
    else
    {
    count.dn++;
    }
    }
    
    
    if (count.up>=8)
    {
    Comment("dsdsD");
    }
 

You need to remove from the loop

count.up=0;
count.dn=0;

because at each iteration you are zeroing out the previous values. Write it before the loop.

 
Aleksei Stepanenko:

You need to remove from the loop

because at each iteration you are zeroing out the previous values. Write it before the loop

Thanks a lot now it works!

However, it's weird, I was doing the same thing without the structure, but just with normal values like

  for(int i=1;i<=10;i++)              
     {    
     double hig10 = iMA (NULL,CP,WPER, 0, MODE_SMA, PRICE_CLOSE, i);                                     
     if (hig10>iClose(Symbol(),CP,i))
     {
     J=J+1;
    else
    {
    J=0;
    }
    }
    
    
    if (J>=8)
    {
    Comment("dfdf");

and it would start plusing every tick))

 

The structure will also be ticking. To work only at the start of a new candle, the time of that candle must be tracked

datetime LastTime;

if(LastTime!=Time[0])
   {
   LastTime=Time[0];
   //Здесь ваш код
   }
 
Can you advise me please. I have custom functions in separate files .mqh prescribed them through #include, I call them in the start by sequence, when the start goes to one function, then depending on the actions the program needs to access another file .mqh (for example to get the value of the order volume) and this does not happen. If I write everything in one sheet, it works or if I write the formula to calculate the lot directly in the order opening parameters. I looked through the MQL4 lessons and read the program documentation but did not find anything. I don't really understand why one .mqh function cannot interact with another .mqh function within calculations. Or, should we make the program return to start if we faced such a necessity - it would return the result to start and then start with this calculation would go back to the function opening an .mqh order? This is something rubbish... Or maybe we should somehow declare all of the existing functions in a different way so that they interact together? Thanks
 
Good afternoon!
What is the easiest way to get rid of the year (2020) and minutes in the line? TimeToStr has no other output formats yet?
TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES);
 
Nauris Zukas:
Good afternoon!
What is the easiest way to get rid of the year (2020) and minutes in the line? TimeToStr has no other output formats yet?
tm=(string)Hour();
 
Vitaly Muzichenko:

Thank you!

 
Denis Diakonov:
Can you give me a hint? I have user-defined functions in separate .mqh files and I have them written through #include. I call them at start and when start goes to one function, the program needs to call another .mqh file (for example, to get a value of order volume) and that doesn't happen. If I write everything in one sheet, it works or if I write the formula to calculate the lot directly in the order opening parameters. I looked through the MQL4 lessons and read the program documentation but did not find anything. I don't really understand why one .mqh function cannot interact with another .mqh function within calculations. Or, should we make the program return to start if we faced such a necessity - it would return the result to start and then start with this calculation would go back to the function opening an .mqh order? This is something rubbish... Or maybe we should somehow declare all of the existing functions in a different way so that they interact together? Thanks

Refer to functions, not files, from functions, if you have connected via an inline. If I understand you correctly, of course.

 
I tried to rewrite someone else's "olyakish_fractals_01" to fit my idea, mine is based on Williams' Green Bars. I've got a wrong idea, I've got a wrong MQL4, it's not looking on the chart. If anyone has a clue, help me out, if it doesn't cost you anything).
Files:
18wbguVOL.mq4  13 kb
Reason: