Questions from Beginners MQL5 MT5 MetaTrader 5 - page 441
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can you please tell me what I'm doing wrong?
I need to calculate how many bars have passed since the price last crossed the MA - excluding the zero bar.
if(Bars>1400)
{
int Stop;
double MATcycle;
for(int i=0;i!=1000 || Stop!=1; i++)
{
MATcycle=iMA(Symbol(),TFT,pMAT,shiftMAT,typeMAT,priceMAT,i+1);
if(MATcycle<High[i+1] && MATcycle>Low[i+1])
{
Stop=1;
Print("MATcycle=",MATcycle," i=",i);
}
else return (0);
}
Can you please tell me what I'm doing wrong?
You need to - count how many bars have passed since the price last crossed the MA - not including the zero bar.
if(Bars>1400)
{
int Stop;
double MATcycle;
for(int i=0;i<1000 || Stop==1; i++)
{
MATcycle=iMA(Symbol(),TFT,pMAT,shiftMAT,typeMAT,priceMAT,i+1);
if(MATcycle<High[i+1] && MATcycle>Low[i+1])
{
Stop=1;
Print("MATcycle=",MATcycle," i=",i);
}
else return (0);
}
As far as I understand, once you have identified the crossing and set stop=1, there is an immediate exit from the cycle. Ok, then you need to go further and remember the number of the candle where the crossing occurred. I.e.
It's easier to write it yourself:
This is you have identified the number of the candle. If the number = 2 and do not take into account the current one, then from the moment of crossing one candle was formed (or interpret it as you want).
As far as I understand, once you have identified the crossover and set stop=1, there is an immediate exit from the cycle. OK, then you need to go further and remember the number of the candle where the crossover occurred. I.e.
It's easier to write it yourself:
This is you have identified the number of the candle. If the number = 2 and ignore the current one, then one candle has formed since the crossing (well, or interpret it as you like).
Thank you, that's how it worked for me
int Stop=0;
if(Bars>1400)
{
double MATcycle;
for(int i=1;(i!=1000 || Stop==0); i++)
{
MATcycle=iMA(Symbol(),TFT,pMAT,shiftMAT,typeMAT,priceMAT,i);
if(MATcycle<=High[i] && MATcycle>=Low[i])
{
Print("MATcycle=",MATcycle," i=",i);
Stop=i;
break;
}
}
}
Can you tell me if this is a realistic tester figure? And is it a good or bad result for a year with a $3,000 depo?
Thank you, that's how it worked out for me
int Stop=0;
if(Bars>1400)
{
double MATcycle;
for(int i=1;(i!=1000 || Stop==0); i++)
{
MATcycle=iMA(Symbol(),TFT,pMAT,shiftMAT,typeMAT,priceMAT,i);
if(MATcycle<=High[i] && MATcycle>=Low[i])
{
Print("MATcycle=",MATcycle," i=",i);
Stop=i;
break;
}
}
}
You shouldn't write it that way, because if there was no crossover during the last 1000 bars, first, the loop will continue, and second, it may loop/error, because if the story ends and there is no crossover, there will be no exit from the loop, because Stop = 0. It's better to write it the way I mentioned above.
You shouldn't write it that way, because if there was no crossover during the last 1000 bars, firstly, the cycle will continue, and secondly, it may loop/error, because if the story ends and no crossover occurs, there will be no exit from the cycle, because Stop = 0. It's better to write it the way I mentioned above.
Doesn't the "or" sign work - the condition says that it either reaches 1000 bars or finishes as soon as the desired result is found. Or it will be over before 1000 bars, if the desired result, i.e. crossing of the MA?
|| means that if at least one of the conditions in brackets is true, the loop will be repeated, hence, even when i >= 1000, but stop = 0, the loop will continue, i will continue to increment, which will cause the wrong MA value (in case there is an outlier in the history). And break operator is responsible for termination of the loop upon finding the desired result;
Hello 2015.09.19_02:13AM MSC. In ArrayResize() function anyway the compiler writes
opposite the size of the array -- comma expected, whether you write int or not. If you don't write int, it says: "-.
I've changed it without type. And I removed & reference and square brackets - it worked!
Warnings: when it was written normally, -- compiler wrote: hides identifier
global-level declaration. And when I removed identifier declaration on a global level, - wrote
it writes: "Error, undeclared identifier. And I changed arrays High[] and Low[] to HighP[] and LowP[]. Not
helped. Compiler writes the same thing. 02:27 MSC. I'm attaching a screenshot file.
Hello 2015.09.19_02:13AM MSC. In ArrayResize() function anyway the compiler writes
opposite the size of the array -- comma expected, whether you write int or not. If you don't write int, it says: "-.
"without type. And I removed & reference and square brackets - it helped!
Warnings: when it was written normally, -- compiler wrote: hides identifier
global-level declaration. But when I removed identifier declaration on a global level, - wrote
it writes: "Error, undeclared identifier. And I changed arrays High[] and Low[] to HighP[] and LowP[]. Not
helped. Compiler writes the same thing. 02:27 MSC. I am attaching the screenshot file.
Forum on trading, automated trading systems and strategy testing
Questions from Beginners
Karputov Vladimir, 2015.09.17 18:46