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

 

Such a question. How do I optimise now? The skeleton of the Expert Advisor is now the following:

init(){
        //если файл истории не существовал, формируем заголовок
}

start(){
        //ловим тики
        //смотрим, сколько прошло секунд с последнего вызова start():
                //если 1 или больше, то---(блок свеч)---
                        //запоминаем, сколько прошло секунд
                        //---(блок выбора режима)---
                        //формируем RateInfo - столько раз, сколько прошло секунд
                //если 0, то---(блок теней)---
                        //редактируем RateInfo - столько раз, сколько прошло секунд в прошлый раз
}

//---(блок выбора режима)---
//флаги в экстерне - все бычьи, все медвежьи или любые
//если все бычьи, то в close всегда ask
//если все медвежьи, то в close всегда bid
//Если любые, то
        //если текущий бид меньше предыдущего, то медвежья
        //в любом другом случае бычья

I put open-close in variables and removed the second block FileSeek, which has become unnecessary, added selection of candlestick style (all bullish, all bearish, any), added shadows if the next asc or bid is higher or lower than the previous high and low, added tracing with the print, which is activated by a flag in the header, commented everything with links to line numbers, tried to make code readable for the forum. I've also added line numbers to print.

Now look:

At the top is a tick timeframe, at the bottom - seconds. The shadows (tails) are when two ticks have been caught in one second and the bid or ask differs from the previous one. The tick works like clockwork. The second tick lags, it means it spends more time to process the tick than the minimal time interval between the ticks. That's why I am asking how to optimize the code. I'm attaching the code and repeating that I've overcommented everything. If you want to check how it works - you set it as an EA on minutes, then in autonomous search and open 'sec'+instrument name.

Files:
hhi.jt.mq4  29 kb
 
david2:
How to implement this function in your EA? When a TP or SL is triggered on any of the Bay orders, all Bay orders should be closed.

If you have programming experience, a hint:

1. after opening a buy order, count the number of buy orders

2. Save their number in a global variable

On the next tick, check the conditions that the amount of buy orders is less than the previous one, then close all the buy orders.

There are functions that calculate the amount of orders by the type of an open position and by closing of positions of a selected type (buy or sell) in the Kodobase.

A lot of useful features in functions from Kim

 

About conversion of variable types.
Written the value of the coefficient double K in the line description as text (K=0.573).
During the code execution, the value of the coefficient K has changed several times.
Now I want to multiply the variable double Z by value K=0.573 after extracting the line description string ObjectDescription(string name).
Is it possible to convert a variable of type string to a variable of type double in MQL to get 0.573 again. If possible, please give me the link.
Regards. Shurkin.

 
Shurkin:

Is it possible to convert a variable of string type in MQL to a variable of double type to get 0.573 again. If possible, please give me a link.
.

https://docs.mql4.com/ru/convert/StrToDouble
 
08:05:30 Sec.TF AUDUSD,M1: 15
08:05:31 Tick.tf AUDUSD,M1: 0
08:05:33 Tick.tf AUDUSD,M1: 0
08:05:33 Tick.tf AUDUSD,M1: 0
08:05:35 Tick.tf AUDUSD,M1: 0
08:05:38 Tick.tf AUDUSD,M1: 0
08:05:39 Tick.tf AUDUSD,M1: 0
08:05:39 Tick.tf AUDUSD,M1: 0
08:05:40 Tick.tf AUDUSD,M1: 0
08:05:41 Tick.tf AUDUSD,M1: 0
08:05:42 Tick.tf AUDUSD,M1: 0
08:05:42 Tick.tf AUDUSD,M1: 0
08:05:43 Tick.tf AUDUSD,M1: 0
08:05:51 GMT AUDUSD,M1: 15062
08:05:54 Tick.tf AUDUSD,M1: 0
08:05:54 Tick.tf AUDUSD,M1: 0
08:05:55 Tick.tf AUDUSD,M1: 0
08:05:56 Tick.tf AUDUSD,M1: 0
08:05:56 Tick.tf AUDUSD,M1: 0
08:05:57 Tick.tf AUDUSD,M1: 0
08:05:58 Tick.tf AUDUSD,M1: 0
08:05:58 Tick.tf AUDUSD,M1: 16
08:05:59 Tick.tf AUDUSD,M1: 0
08:06:00 Tick.tf AUDUSD,M1: 0
08:06:06 Tick.tf AUDUSD,M1: 0
08:06:06 Tick.tf AUDUSD,M1: 0
08:06:09 GMT AUDUSD,M1: 10156
08:06:16 Tick.tf AUDUSD,M1: 0
08:06:16 Tick.tf AUDUSD,M1: 0
08:06:17 Tick.tf AUDUSD,M1: 0
08:06:18 Tick.tf AUDUSD,M1: 0
08:06:26 GMT AUDUSD,M1: 5078
08:06:27 Tick.tf AUDUSD,M1: 0
08:06:28 Tick.tf AUDUSD,M1: 0
08:06:30 Tick.tf AUDUSD,M1: 31

08:06:32 GMT AUDUSD,M1: 15

Part of the log with millisecond timer in both codes (tick and second timeframes). All I can think of so far is to remove cycles altogether, i.e. one or more ticks per second no matter how many seconds have passed since the last tick - it is always one candle. If there was a second and so on ticks per second - a candlestick with shadows. But then there will be a second TF with "holes" and by High[15] let's suppose I won't take the value of asc 15 seconds ago...

 
hoz:

I wondered how to write a function. The idea is that when N candles roll back in a certain direction, it should calculate the number of candles. BUT. For this there are several conditions, or more precisely, there will be a list of them over time.

Let's say the trend, for example, is directed downwards,... ...a pullback goes up. I want, if 5 candlesticks went up, and each candlestick was bullish, and, for example, the size of each candlestick was larger thani_sizeOfCurrBar, and some other conditions, then output the number of continuously bullish bars, and return some result from the function.

What is the best way to write it? At the moment I've started to write, and I understand that I should run it through a loop by bars, and somehow I should limit the view in the depth of history not by a fixed number of bars, but by bars, with those parameters, which we are interested in by conditions.

Here's what I have, got:

At the moment we are just going from the penultimate bar to the bar with index 6, i.e. 5 bars in a row. But I want my Expert Advisor to search only for the bars that are bullish and not for all of them in a row. How to implement it adequately?

I have sort of correctly filtered by size.

Well, when everything is already written, the counter at the bottom will already calculate the number of continuous bars with nht,etvsvb parameters and if there are enough of such bars, then some value of the function will be returned.

As always original: counting bars "from below"...

for (int i=Bars-1; i>=Bars-6; i--)
 
Zhunko:

There are a lot of different ways:

1. Through a global variable.

2. Via file.

3. Via iCustom().

4. Through the global graphic variables.

5. Mapping. You can transfer data from one terminal to another terminal. Or in one terminal to transfer data from one window to another window without limitations of MT4 global variables.


Which of these works fastest?
 
gyfto:

Which of these works fastest?
5. Mapping.
 
hoz:
In print it has a value of 1 and 2... What the fuck is going on here anyway?
Print("i = ", i, "; up = ", cnt, "; cnt = ", cnt);

Just inattention. In general, the bool here is 4-byte, which does not oblige it to take 0 and 1 values only. C++ boolearn is 1-byte. I personally use bool in binary arithmetic in switch(), if I need to make multiple choices, trusting that it's always 0 or 1)) Like this:

bool f1, f2, f3, f4//флаги

switch(8*f4+4*f3+2*f2+f1){
   case 0:
   ...
   case 15:
}//без default
 
gyfto:

Such a question. How do I optimise now? The skeleton of the Expert Advisor is now the following:

I put open-close in variables and removed the second block FileSeek, which has become unnecessary, added selection of candlestick style (all bullish, all bearish, any), added shadows if the next asc or bid is higher or lower than the previous high and low, added tracing with the print, which is activated by a flag in the header, commented everything with links to line numbers, tried to make code readable for the forum. I've also added line numbers to print.

Now look:

Above is a tick timeframe, below is a second timeframe. The shadows (tails) are when two ticks have been caught in one second and the bid or ask differs from the previous one. The tick works like clockwork. The second tick lags, it means it spends more time to process the tick than the minimal time interval between the ticks. That's why I am asking how to optimize the code. I'm attaching the code and repeating that I've overcommented everything. If you want to check how it works - you set it as an EA on minutes, then in autonomous search and open 'sec'+instrument name.

I haven't got into the logic, but something tells me there are some extra calculations. A year and a half ago I was solving the same problem with quotes gathering and forming M1 candlesticks with clear cutting at the beginning of the astronomical minute.
If you will be interested, you may take a look at some moments of pure optimization of your code (file). Really, if we seriously talk about optimization, you need to measure the code's runtime. ;)
Files:
hhi.jt_c_.mq4  23 kb
Reason: