Here is my variant of solving the repetition search problem:
//+------------------------------------------------------------------+//| FindRetryPrices.mq5 |//| Copyright 2016, Vasiliy Sokolov. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2016, Vasiliy Sokolov."#property link"http://www.mql5.com"#property version"1.00"#include <Dictionary.mqh>
inputint RatesPeriod = 10; // Период за который ищутся повторенияinputint RoundPoints = 10; // Загрубление цены в прайсстепахclass CBar : public CObject
{
private:
MqlRates m_bar;
public:
CBar(MqlRates& bar){m_bar = bar;}
datetime Date(){return m_bar.time;}
doubleOpen(){return m_bar.open;}
doubleHigh(){return m_bar.high;}
doubleLow(){return m_bar.low;}
doubleClose(){return m_bar.close;}
};
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
// Нахождение повторяющихся баровMqlRates rates[];
int total = CopyRates(Symbol(), Period(), 0, RoundPoints, rates);
CDictionary* BarsCollections = new CDictionary(total);
for(int i = 0; i < total; i++)
{
double price = PriceToLevel(rates[i].high);
CBar* bar = new CBar(rates[i]);
if(!BarsCollections.ContainsKey(price))
BarsCollections.AddObject(price, new CList());
CList* equal_bars = BarsCollections.GetObjectByKey(price);
equal_bars.Add(bar);
}// Вывод повторов
FOREACH_DICT(BarsCollections)
{
CList* list = node;
if(list.Total() < 2)continue;
string retry_bars = "";
for(CBar* bar = list.GetFirstNode(); bar != NULL; bar = list.GetNextNode())
retry_bars += " [" + TimeToString(bar.Date()) + ", " + DoubleToString(bar.High(), Digits()) + "]";
printf("Обнаружено совпадение баров:" + retry_bars);
}
delete BarsCollections;
}
//+------------------------------------------------------------------+//| Округляет цену в соответствии с параметром RoundPoints |//+------------------------------------------------------------------+double PriceToLevel(double price)
{
double price_step = RoundPoints*Point();
double mn = MathFloor(price/price_step);
return mn * price_step;
}
//+------------------------------------------------------------------+
For the script to work, the Dictionary file must be copied into MQL5\Include
The search is performed in the one-pass for loop highlighted in yellow. The resulting list contains no repetitions (if A repeats B and B repeats A, one set {A, B} will be output instead of two {A, B} and {B, A}). ).
Here is my version of the solution to the repetition search problem:
Thank you all very much!!! I will try to figure it all out today. It is important not just to copy a piece of code into Expert Advisor, but to understand why it is written this way, so maybe I will ask more questions.
// строку int searchPeriod=(Search_Period<1)?1:Search_Period;// можно расписать так:inputint Search_Period=10; // Количество копируемых свечей ... эту строку вы видите в настройкахint searchPeriod; // Сюда будем записывать входной параметрif(Search_Period<1) searchPeriod=1; // Если во входном параметре ввели ноль или меньше нуля, то параметр будет равен нулюelse searchPeriod=Search_Period; // иначе примем входной параметр// соответственно и строку int delta=(Delta<0)?0:Delta;// можно расписать точно так же
Am I correct in assuming this is a typo? It should be 0 instead of 1.
like this:int searchPeriod=(Search_Period<1)?0:Search_Period;
and further in the executable script:
int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // the number of candles to copy
In this case, we should probably already use a variable: searchPeriod. right?
------
Another question, what does this line do? I found that each element of the structure resets to zero. And I don't understand what we are zeroing here if we seem to have just written this data and should use it further.
ZeroMemory(dataCandle); // Zeroing data in the structure
Am I correct in assuming this is a typo? It should be 0 instead of 1.
like this:int searchPeriod=(Search_Period<1)?0:Search_Period;
and further in the executable script:
int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // the number of candles to copy
In this case, we should probably already use a variable: searchPeriod. right?
------
Another question, what does this line do? I found that each element of the structure resets to zero. And I don't understand what we are zeroing here if we seem to have just written this data and should use it further.
ZeroMemory(dataCandle); // clearing the data in the structure
No, it's not. This is how you have it (literally): if Search_Period set by the user in the settings is less than one, then searchPeriod will be equal to zero; otherwise, searchPeriod will be equal to the value of Search_Period set by the user in the settings. This is not correct. We don't need a search range that equals zero. So, if this range is set by the user to 0 or less than zero (less than one), then we'll set this range equal to the minimum - one.
"int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // number of candlesticks to copy here we should already use the variable: searchPeriod. right? "
Yes, that's right, there's a typo.
"Another question, what does this line do? What is it for? I found that it resets each element of the structure to zero. And here I cannot understand why and what we are zeroing if we have just written this data and should use it further. ZeroMemory(dataCandle); // Zeroing the data in the structure".
We do this before filling the structure with data. First we zero it, and then we fill it. Look - we zero it before the loop. And then in the loop we fill the structure with data.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Here is my variant of solving the repetition search problem:
For the script to work, the Dictionary file must be copied into MQL5\Include
The search is performed in the one-pass for loop highlighted in yellow. The resulting list contains no repetitions (if A repeats B and B repeats A, one set {A, B} will be output instead of two {A, B} and {B, A}). ).
The output of this script showed the following:
From the reference:
Here is my version of the solution to the repetition search problem:
Please help me find a function to calculate the standard RSI, the requirements are simple:
1. Return RSI value at a given bar
2. Calculate index only for those bars (if necessary), which are requested (desirable)
3. To be able to calculate on the specified TF
4. Works at the expense of point 2 faster than the indicator
I want to integrate the function into the Expert Advisor, if anyone has a ready one, please share it with me.
I am asking as the indicator is very common and is not a mystery.
Please help me find a function to calculate the standard RSI, the requirements are simple:
1. Return RSI value at a given bar
2. Calculate index only for those bars (if necessary), which are requested (desirable)
3. To be able to calculate on the specified TF
4. Works at the expense of point 2 faster than the indicator
I want to integrate the function into the Expert Advisor, if anyone has a ready one, please share it with me.
I am asking as the indicator is very common and is not a mystery.
What's wrong with the standard iRSI? Not secret enough?
There are my changes that I will need to make to the function...
Take a ready-made one then and modify it according to your requirements:
Take a ready-made one then and modify it according to your requirements:
Here is my variant of solving the problem of searching for repetitions:
Vasily, when I open#include <Dictionary.mqh>, it opens the same as in the EA body. It should be like this, or there should be some other code inside?
Because in the code, that I see, it's not clear how it searches for repetitions ((
Am I correct in assuming this is a typo? It should be 0 instead of 1.
like this:int searchPeriod=(Search_Period<1)?0:Search_Period;
and further in the executable script:
int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // the number of candles to copy
In this case, we should probably already use a variable: searchPeriod. right?
------
Another question, what does this line do? I found that each element of the structure resets to zero. And I don't understand what we are zeroing here if we seem to have just written this data and should use it further.
ZeroMemory(dataCandle); // Zeroing data in the structure
Am I correct in assuming this is a typo? It should be 0 instead of 1.
like this:int searchPeriod=(Search_Period<1)?0:Search_Period;
and further in the executable script:
int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // the number of candles to copy
In this case, we should probably already use a variable: searchPeriod. right?
------
Another question, what does this line do? I found that each element of the structure resets to zero. And I don't understand what we are zeroing here if we seem to have just written this data and should use it further.
ZeroMemory(dataCandle); // clearing the data in the structure
"like this:int searchPeriod=(Search_Period<1)?0:Search_Period;"
No, it's not. This is how you have it (literally): if Search_Period set by the user in the settings is less than one, then searchPeriod will be equal to zero; otherwise, searchPeriod will be equal to the value of Search_Period set by the user in the settings. This is not correct. We don't need a search range that equals zero. So, if this range is set by the user to 0 or less than zero (less than one), then we'll set this range equal to the minimum - one.
"int copy_bars=(int)fmin(Search_Period,Bars(Symbol(),Period())); // number of candlesticks to copy
here we should already use the variable: searchPeriod. right? "
Yes, that's right, there's a typo.
"Another question, what does this line do? What is it for? I found that it resets each element of the structure to zero. And here I cannot understand why and what we are zeroing if we have just written this data and should use it further. ZeroMemory(dataCandle); // Zeroing the data in the structure".
We do this before filling the structure with data. First we zero it, and then we fill it. Look - we zero it before the loop. And then in the loop we fill the structure with data.