Scorp1978>>: rid спасибо хорошая идея (от тиков придется тогда отказываться), фильтр от сильных убыточных движений ты имеешь ввиду "если сумарный профит меньше чего то, то закрыть все позиции".......
No. I meant the initial entry - "/if //the size of the first candle is greater than the set value, no trading is allowed..."
Good afternoon to all! Happy Holidays to all who consider the day a holiday! //--------------------------------------- A question has arisen. Here is a function, which outputs (calculates) the average spread between instruments for the last NBars.
double CalculateAvarageSpread(string Symbol_1, string Symbol_2,
int Timeframe, int NBars)
{
int k;
double N = 0;
double Sum = 0;
for(k = 0; k < iBars(Symbol_1,Timeframe); k++)
{
if(N == NBars)
break;
int symb2Shift = iBarShift(Symbol_2,Timeframe,iTime(Symbol_1,Timeframe,k),true);
if(symb2Shift != -1)
{
Sum += iClose(Symbol_1,Timeframe,k) - iClose(Symbol_2,Timeframe,symb2Shift);
N++;
}
}
double avarageSpread = Sum / N;
return(avarageSpread);
}
Please tell me how to set //------------- int k; double N = 0; double Sum = 0; for(k = 0; k < iBars(Symbol_1,Timeframe); k++) { if(N == NBars) //------------------------ so that the function returns the average spread value not for all NBars bars, but for NBars except the last bar. In other words, I want the latest bar to be excluded from the calculation ! Or even a given number of most recent bars should not be included in the calculation. Is there any way to "organise" this ? (In return, I can give a good market entry on Monday, May 3. With a high probability of subsequent profitable closing!)
double CalculateAvarageSpread(string Symbol_1, string Symbol_2,
int Timeframe, int NBars, int NBarsSkip)
{
int k;
double N = 0;
double Sum = 0;
if(NBars > iBars(Symbol_1,Timeframe)) NBars=iBars(Symbol_1,Timeframe); // если н больше чем баров на графике то обрезаем
if(NBarsSkip >= NBars) NBarsSkip=0; // если пропускаем баров больше/равно чем NBars, то ничего не пропускаем
for(k = NBarsSkip; k < NBars; k++)
{
int symb2Shift = iBarShift(Symbol_2,Timeframe,iTime(Symbol_1,Timeframe,k),true);
if(symb2Shift != -1)
{
Sum += iClose(Symbol_1,Timeframe,k) - iClose(Symbol_2,Timeframe,symb2Shift);
N++;
}
}
double avarageSpread = Sum / N;
return(avarageSpread);
}
NBarsSkip sets the number of missed bars that will not participate in the calculation. c NBarsSkip by NBars will participate in the calculation.
Thank you, NCI ! I'll send you a prospective entry in a moment. One more question. I just had an idea. How about to make it even simpler. Set it like this: Instead of for(k = 0; k < iBars(Symbol_1,Timeframe); k++) set for(k = M; k < iBars(Symbol_1,Timeframe); k++), whereM is the number of bars excluded from calculation. Will it work ?
I honestly did not notice at first that NBars should only consider bars existing on two instruments at the same time, then the code I posted does not meet this logic. andthe constructionwithM would not be correct either. in this case you could do the following:
double CalculateAvarageSpread(string Symbol_1, string Symbol_2,
int Timeframe, int NBars, int NBarsSkip)
{
int k;
double N = 0;
int NReal = 0;
double Sum = 0;
for(k = 0; k < iBars(Symbol_1,Timeframe); k++)
{
if(N == NBars)
break;
int symb2Shift = iBarShift(Symbol_2,Timeframe,iTime(Symbol_1,Timeframe,k),true);
if(symb2Shift != -1)
{
N++;
if(N>NBarsSkip)
{
Sum += iClose(Symbol_1,Timeframe,k) - iClose(Symbol_2,Timeframe,symb2Shift);
NReal++; // счетчик Н которые не пропущены и посчитаны
}
}
}
if(NReal==0) return(0); // так как у нас не получилось рассчитать ни одного бараelse
{
double avarageSpread = Sum / NReal;
return(avarageSpread);
}
}
Thank you. For some reason my code didn't compile at first, it returned an error (bracket) Until I moved from the function name "...., int NBarsSkip " to the external parameters of the EA extern int NBarsSkip =2 I don't know why there was an error. But when I moved it, everything was fine.
I have read this branch from cover to cover - all 145 pages. thanks to everyone: rid, leonid553, fduch, neoclassic, getch, forex-k, goldtrader, timbo, fortrader. I have a lot of information, I am still digesting it. My main conclusion is the following: you have to dig here, it's worth it. P.s.: good resourceful thread, almost no flooding. Thanks again 2rid
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.
rid спасибо хорошая идея (от тиков придется тогда отказываться), фильтр от сильных убыточных движений ты имеешь ввиду "если сумарный профит меньше чего то, то закрыть все позиции".......
No. I meant the initial entry - "/if
//the size of the first candle is greater than the set value, no trading is allowed..."
//---------------------------------------
A question has arisen. Here is a function, which outputs (calculates) the average spread between instruments for the last NBars.
Please tell me how to set
//-------------
int k;
double N = 0; double Sum = 0;
for(k = 0; k < iBars(Symbol_1,Timeframe); k++)
{
if(N == NBars)
//------------------------
so that the function returns the average spread value not for all NBars bars,
but for NBars except the last bar.
In other words, I want the latest bar to be excluded from the calculation ! Or even a given number of most recent bars should not be included in the calculation.
Is there any way to "organise" this ?
(In return, I can give a good market entry on Monday, May 3. With a high probability of subsequent profitable closing!)
I'll send you a prospective entry in a moment.
One more question.
I just had an idea.
How about to make it even simpler. Set it like this:
Instead of for(k = 0; k < iBars(Symbol_1,Timeframe); k++)
set
for(k = M; k < iBars(Symbol_1,Timeframe); k++),
where M is the number of bars excluded from calculation.
Will it work ?
Until I moved from the function name "...., int NBarsSkip "
to the external parameters of the EA
extern int NBarsSkip =2
I don't know why there was an error.
But when I moved it, everything was fine.
I have read this branch from cover to cover - all 145 pages. thanks to everyone: rid, leonid553, fduch, neoclassic, getch, forex-k, goldtrader, timbo, fortrader. I have a lot of information, I am still digesting it. My main conclusion is the following: you have to dig here, it's worth it. P.s.: good resourceful thread, almost no flooding. Thanks again 2rid
Thank you!
"Information to think about.
From Monday the ZM-ZL spread (flour-oil, 5:6)
!