Reputation: 1
I have this code working without error. Basically, this code is to show value of Moving Averages on five previous bars per 5 minutes. MA's current value is omitted.
int TrendMinDurationBar = 5,
SlowPeriod = 14,
FastPeriod = 7;
void OnTick()
{
if ( NewBar( PERIOD_M5 ) == true ) MA( PERIOD_M5 );
}
void MA( int TF )
{
double Slow[], Fast[];
ArrayResize( Slow, TrendMinDurationBar + 1 );
ArrayResize( Fast, TrendMinDurationBar + 1 );
for ( int i = 1; i <= TrendMinDurationBar; i++ )
{ Slow[i] = NormalizeDouble( iMA( Symbol(), TF, SlowPeriod, 0, MODE_EMA, PRICE_OPEN, i ), Digits );
Fast[i] = NormalizeDouble( iMA( Symbol(), TF, FastPeriod, 0, MODE_EMA, PRICE_OPEN, i ), Digits );
Alert( "DataSlow" + ( string )i + ": " + DoubleToStr( Slow[i], Digits ) );
}
}
bool NewBar( int TF )
{
static datetime lastbar = 0;
datetime curbar = iTime( Symbol(), TF, 0 );
if ( lastbar != curbar )
{ lastbar = curbar; return( true );
}
else return( false );
}
When #property strict
is included, the code is only working once after compiled. After new bar on M5
chart exist, it doesn't make any iteration.
What's the solution if I insist to use #property strict
?
Upvotes: 0
Views: 766
Reputation: 1
New
-MQL4.56789
Catch-22My candidate from Help > MQL4 Reference > Updated MQL4
is
this one ( column [New MQL4 with #property strict]
)
Functions of any type should return a value
and
one more to be reviewed,
code simply loses the logic even for static double
alternative it would be extremely inefficient under these circumstances:
Local arrays are released when exiting {} block
Upvotes: 0
Reputation: 210
Works perfectly well with #property strict
as an EA in MT4 Build 950.
Are you sure you are running it as EA and not as Script or Indicator?
Upvotes: 0