[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 304

 
Chiripaha:

: )))))))) Yes - that's right. All reproaches accepted! - For that again, I apologise. - It's all the consequences of a strongly developed (by special exercises)

creative, imaginative, poetic etc. side - all the same, there are two hemispheres in a human being: creative and rational. My fault is that I saw it and did not correct it.

So all your claims are to the point and I am guilty.

But only the question remains unresolved...

How to resolve it in the end?

If you think I haven't heard something, please clarify. I understand the feedback technique (for being able to "hear"), but I haven't seen a solution yet.

How to get the right number without rounding in Double, up to 3rd decimal place, for example in the value of Ask = 1,20667 ?- A solution like "StrToDouble(DoubleToStr(Ask,3)) = 1,2100 // 1,2100 is the result (i.e. rounding)" didn't work.

Thank you in advance for your tolerance and understanding.

DoubleToStr(Ask, 3) !!! - That was something to see.

And the solution is in the file (it's a test script).

Files:
test_ind.mq4  2 kb
 
alsu:

Looked at your code.... You are too confused))))

I don't quite understand, why we need to accumulate ticks, because it is enough to store in memory (or even not to store, because the current bar must be written in HST - otherwise the chart will not be updated) parameters of the current bar - six numbers TOHLCV, and to update them as needed at tick receipt, and to make bars cutoff by a given condition (TimeCurrent()-O>1).

Try to rework the code in this way, it will be reduced by 8 times, I guarantee it (I've checked it:)


Like this? Reworked the algorithm, removed the accumulator, converted it to Expert Advisor, added gradation of ticks to bearish-bullish, added candlestick tails using a different algorithm, commented everything. I have nothing to check it with, there are no ticks at the weekend. As for the volume - it seems to me, it was in FileFlush, it works with the buffer. For the future I refuse to put anything between FileSeek and FileFlush...
Files:
elz.jp.mq4  23 kb
 
IgRU4ek:

DoubleToStr(Ask, 3) !!! - this should have been seen.

And the solution is in the file (it's a test script).


Thank you very much.

I still don't understand the mechanism - why my version didn't work and why "DoubleToStr(Ask,3) != DoubleToStr(Ask,Digits)" - Apparently, not all features of functions are disclosed in the reference book.

Your function was parsed - I understood the way it was solved. But I was sure that there must be a "simpler" way to solve it, because the set of functions in a programming language is designed for solving typical problems with them, rather than create these typical functions for each user himself. I naively assumed that DoubleToStr() solves just this problem. - I don't understand the point of using it then (what are its nuances). I'm an ordinary user, not a programmer, to "get down to such details". When to use creation products in this case, if all the time will be spent on detailed programming.

Thanks again. I will now try to put it all into the code. Hopefully it will all work.

 
Chiripaha:

Thank you very much.

I still do not understand the mechanism - why my version did not work and why "DoubleToStr(Ask,3) != DoubleToStr(Ask,Digits)" - Apparently, not all features of functions are disclosed in the reference book.

Your function was parsed - I understood the way it was solved. But I was sure that there must be a "simpler" way to solve it, because the set of functions in a programming language is designed for solving typical problems with them, rather than create these typical functions for each user himself. I naively assumed that DoubleToStr() solves just this problem. - I don't understand the point of using it then (what are its nuances). I'm an ordinary user, not a programmer, to "get down to such details". When to use creation products in this case, if all the time will be spent on detailed programming.

Thanks again. I will now try to put it all into the code. Hopefully it will all work.

DoubleToStr() performs a conversion with a number in two steps: first it rounds (according to the rules of mathematics) the number to the right sign and then converts it to a string.
 

Try for your case

double x = MathFloor(y*1000)/1000;

 
IgRU4ek:
DoubleToStr() performs conversion to a number in two steps: first it rounds (by mathematical rules) the number to the right sign and then converts it to a string.


Thanks for the clarification. I didn't know that, of course, and was blaming StrToDouble() in this case. But after your clarification I now assume that they are both rounding :(

Why rounding is not clear. If rounding was required, it would be better in this case, firstly, to use some rounding function (as required) - the same normalization. Then there would be both possibilities with rounding and without. Otherwise, we would have unnecessary clutter. Moreover, I don't understand why it rounds when I just need to make an existing number a different type. I already got it (a number), why should I make it up additionally.

 
Roger:

Try for your case

double x = MathFloor(y*1000)/1000;


Exactly! A nice solution. I've seen it before, but missed something in my case. Thank you, Alexander, very much, too! - Now I will have 2 solutions! : )) (For the cartoon "Prostokvashino")
 

Such a theoretical question. Is the close price, in terms of tick, a bid or ask of the last tick in the candle? I've noticed that if the bid is written in Close[0], then the quote on the runner is the same as on the minutes.

Thought about it... Bid in the idea...

 
Zhunko:
Lots of errors. Maybe you should look at an example and do it by analogy?


Basically the same thing. My understanding, although there is nothing at all about it in the tutorial, is that the inclusion is needed only as a link between the Expert Advisor and the library.

The function is imported in the inline, and the functions to be imported are declared. You put a . sign between the declarations;

Here I wrote an inlude and a library (with only one function, but it's just for testing).

The inclusion is here:

//+------------------------------------------------------------------+
//|                                       HozIncludeToScalper_M1.mqh |
//|                                                              hoz |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""

#import "Scalper_M1_lbr.ex4"

//+-------------------------------------------------------------------------------------+
//| Получаем машку с заданными параметрами                                              |
//+-------------------------------------------------------------------------------------+
double GetMA(int typeOfMA);

// Очередная функция

// Очередная функция

// Очередная функция

#import

When all necessary (used by specific owl) functions are declared, put#import at the end

Here is the library itself:

//+-------------------------------------------------------------------------------------+
//|                                                                  Scalper_M1_lbr.mq4 |
//|                                                                                 hoz |
//|                                                                                     |
//+-------------------------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""
#property library

//+-------------------------------------------------------------------------------------+
//| Получаем машку с заданными параметрами                                              |
//+-------------------------------------------------------------------------------------+
double GetMA(int typeOfMA)
{
   switch (typeOfMA)
   {
      case 1:      return (iMA(NULL, i_fastMATF, i_fastMAPeriod, i_fastMAShift, i_fastMAMethod, i_fastMAApplied, i_fastMAIndex));
      case 2:      return (iMA(NULL, i_slowMATF, i_slowMAPeriod, i_slowMAShift, i_slowMAMethod, i_slowMAApplied, i_slowMAIndex));
      case 3:      return (iMA(NULL, i_filtrMATF, i_filtrMAPeriod, i_filtrMAShift, i_filtrMAMethod, i_filtrMAApplied, i_filtrMAIndex));
   }
}

It doesn't even compile.

'i_fastMATF' - variable not defined     E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 38)
'i_fastMAPeriod' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 50)
'i_fastMAShift' - variable not defined  E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 66)
'i_fastMAMethod' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 81)
'i_fastMAApplied' - variable not defined        E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 97)
'i_fastMAIndex' - variable not defined  E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (17, 114)
'i_slowMATF' - variable not defined     E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 38)
'i_slowMAPeriod' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 50)
'i_slowMAShift' - variable not defined  E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 66)
'i_slowMAMethod' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 81)
'i_slowMAApplied' - variable not defined        E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 97)
'i_slowMAIndex' - variable not defined  E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (18, 114)
'i_filtrMATF' - variable not defined    E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 38)
'i_filtrMAPeriod' - variable not defined        E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 51)
'i_filtrMAShift' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 68)
'i_filtrMAMethod' - variable not defined        E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 84)
'i_filtrMAApplied' - variable not defined       E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 101)
'i_filtrMAIndex' - variable not defined E:\Insall'd soft's\Forex\MetaTraderForProgramming\experts\libraries\Scalper_M1_lbr.mq4 (19, 119)
18 ошибок, 0 предупреждений     

You don't declare anything in the library and have no errors, but I do for some reason. I didn't see any difference.

 

Victor, you have a lot of variables in your function and none declared.

The compiler said:

variable not defined

A variable is not defined. There are 18 of them.

==============

Judging by the function's design, it is a highly specialized function. Why would you put it in the library? Especially since it will probably be called in the loop on every bar.

You were saying something about speed and optimization. You are creating a very slow code. In MQL4 you should not put functions in a loop. The fewer function calls in a loop, the faster the code runs.

==============

Long time ago, when I started writing in MQL4, I wrote my first forex index indicator. There were functions there as well, operations with strings... What a mess... It took me 5 minutes to switch TFs.

Then I sat and thought, eliminated all functions and opened them right in the loop block. Eliminated work with strings, replacing them with identifiers. Everything that could be calculated in advance and that didn't change - that's how I calculated it (optimization). Moved code to Expert Advisor. As a result, the heaviest calculation when switching TFs was 15 seconds. Then I transferred the calculations to DLL. Now it takes about 5 seconds.

Reason: