Hi trying to progrmme my first ea and cant seem to work out what is wrong here. The idea is that i collect MA values for the last 10 bars and store them in an array , this should be done just the once. It works ok if i just collect values butr as soon as i put the if statement to test if it had cycled one already i got errors . i have tried to solve it but pulling my hair out- thank you
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int bar, limit=10;
double BarMa[10];
bool CanTrade = False; // Make sure default is no trade
If (int cnt = 0) // test that is has not cycled through before
{
for(bar=0; bar<limit; bar++) // collect MA Values store in array BarMa
{
BarMa[bar] = iMA(NULL,PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,bar);
Print (DoubleToStr(BarMa[bar],Digits));Print (bar); Print (cnt);
}
cnt = 1; // Cause count to set to 1 to ensure cycles once
}
else
{
Print ("cycled through once"); // check cycle happened only once
return(0);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int bar, limit=10;
double BarMa[10];
bool CanTrade = False; // Make sure default is no trade
If (int cnt = 0) // test that is has not cycled through before
{
for(bar=0; bar<limit; bar++) // collect MA Values store in array BarMa
{
BarMa[bar] = iMA(NULL,PERIOD_M1,40,0,MODE_SMA,PRICE_CLOSE,bar);
Print (DoubleToStr(BarMa[bar],Digits));Print (bar); Print (cnt);
}
cnt = 1; // Cause count to set to 1 to ensure cycles once
}
else
{
Print ("cycled through once"); // check cycle happened only once
return(0);
}
//----
return(0);
}
//+------------------------------------------------------------------+