The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
This usually happens when a new tick is received for the symbol, for which the indicator is calculated.
This indicator is not required to be attached to any price chart of this symbol.
The OnCalculate() function must have a return type int. There are two possible definitions. Within one indicator you cannot use both versions of the function.
The first form is intended for those indicators that can be calculated on a single data buffer. An example of such an indicator is Custom Moving Average.
intOnCalculate (constint rates_total, // size of the price[] array constint prev_calculated, // bars handled on a previous call constint begin, // where the significant data start from constdouble& price[] // array to calculate );
The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
This usually happens when a new tick is received for the symbol, for which the indicator is calculated.
This indicator is not required to be attached to any price chart of this symbol.
The OnCalculate() function must have a return type int. There are two possible definitions. Within one indicator you cannot use both versions of the function.
The first form is intended for those indicators that can be calculated on a single data buffer. An example of such an indicator is Custom Moving Average.
intOnCalculate (constint rates_total, // size of the price[] array constint prev_calculated, // bars handled on a previous call constint begin, // where the significant data start from constdouble& price[] // array to calculate );
When I write below return code to my custom indicator then my custom indicator starts to lag. But works correct, which one I want.
return(0); // starts to lag...
And when I write below return code to my custom indicator then my custom indicator does not work correctly which one I want. I mean while fake MA cross " Arrow " does not go back to previous MA cross point.
return rates_total-1; // does not go back to previous MA cross pointreturn(rates_total-1); // and same thing here
Max Enrik: And when I write below return code to my custom indicator then my custom indicator does not work correctly which one I want. I mean while fake MA cross " Arrow " does not go back to previous MA cross point.
Post all of your code. That is meaningless without context.
string counts;
void _a()
{
counts += "a - " + IntegerToString( ObjectsTotal( OBJ_ARROW ) );
//---return;
}
void _b()
{
counts += " - b - " + IntegerToString( ObjectsTotal( OBJ_ARROW ) );
//---return;
}
Print( counts );
// while 1st loop: a - 2 - b - 4// while 2nd loop: a - 2 - b - 4a - 2 - b - 4// while 3rd loop: a - 2 - b - 4a - 2 - b - 4a - 2 - b - 4a - 2 - b - 4// and so on...// But I like only 1st loop results even that loop runs 10 thousand times
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.
OnCalculate
The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
This usually happens when a new tick is received for the symbol, for which the indicator is calculated.
This indicator is not required to be attached to any price chart of this symbol.
The OnCalculate() function must have a return type int. There are two possible definitions. Within one indicator you cannot use both versions of the function.
The first form is intended for those indicators that can be calculated on a single data buffer. An example of such an indicator is Custom Moving Average.
int OnCalculate (const int rates_total, // size of the price[] array
const int prev_calculated, // bars handled on a previous call
const int begin, // where the significant data start from
const double& price[] // array to calculate
);
OnCalculate
The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
This usually happens when a new tick is received for the symbol, for which the indicator is calculated.
This indicator is not required to be attached to any price chart of this symbol.
The OnCalculate() function must have a return type int. There are two possible definitions. Within one indicator you cannot use both versions of the function.
The first form is intended for those indicators that can be calculated on a single data buffer. An example of such an indicator is Custom Moving Average.
int OnCalculate (const int rates_total, // size of the price[] array
const int prev_calculated, // bars handled on a previous call
const int begin, // where the significant data start from
const double& price[] // array to calculate
);
( I use word " Lag " it means delays price action, order open, close, just one word takes down my MT4 platform )
I use below function for my custom indicator.
When I write below return code to my custom indicator then my custom indicator starts to lag. But works correct, which one I want.
And when I write below return code to my custom indicator then my custom indicator does not work correctly which one I want. I mean while fake MA cross " Arrow " does not go back to previous MA cross point.
Q: What can I do for this situation, please?
Thanks in advance.
Here you go.
Thanks in advance.
OK! Thanks!
I still need more clearly answer.
Thanks in advance.
Answer is: Check Both Current MA Cross and Previous MA Cross.
#Buffer ( array out of range in ) - Closed
#Custom Indicator Lagging - Closed
#First result of Loop - Open
Thanks in advance.