- Peter Horvath: I have one problem, in mq4 code,
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
And I use IndicatorCounted() in Start function: int start()
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016) -
See How to do your lookbacks correctly #9 — #14 & #19.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone!
I have one problem, in mq4 code, I make indicator, this is Fractal component system.
And I use IndicatorCounted() in Start function:
int start()
{
int i=0, j=0;
cbars = IndicatorCounted()/25;
//cbars = WindowFirstVisibleBar()/25;
if(cbars<0) return(-1);
if(cbars>0) cbars--;
pos=0;
if(cbars > (Bars-cnt-1)) pos=(Bars-cnt-1);
else pos=cbars+nRightUp;
And below run the code, and when come good signal (SELL OR BUY), (fractal component complex system)
Before I open a position, I count backwards a certain amount of bars according to a certain system, I saved into that variable.
And I add it to the IndicatorCounted () function. I'll show you how:
...
if(pos == nLeftUp+1) iHCount_FINISH = FALSE;
...
if(!iHCount_FINISH) // allows 1 period to run
{ // LOOKS BACK SEARCHES IN ARRAY EXISTING IHIGH VALUE. IT'S A FRACTAL VALUE HERE
iHCount = 1;
while(DFUPI_ONE != COUNT_H_PRICE_BAR)
{
COUNT_H_PRICE_BAR = iHigh(NULL, 0, iHCount);
iHCount++;
iHCount_FINISH = TRUE;
}
iHCount = iHCount - pos;
Target_Bars_S = (IndicatorCounted()-1) + iHCount; // EXAMPLE: 1200 + 12 = 1212
}
It does this and I show it with the Comment() function. And he shows me. Then we need the IndicatorCounted() function again to write the number of bars to a variable from the position opening.
And now comes the problem, that when I start a backtest, it counts for a few bars and stops counting all of a sudden.
Why is that?
Is the IndicatorCounted() function not working properly when running backtest?
Or why is this?
Ok, I haven’t tried a demo account like the M1 time icon, but I think the backtest is for us to see full mirror info about our work when we write the code.
Thanks in advance for your help, I look forward to helping anyone who can comment on this issue.
Thanks Peter