I start to write an EA fo MT4 and want to first analyze the strategy.

From start i got a problem to get properly in time the last good computed bar value! So my question is: What i am doing wrong. Here below a fraction of the code showing the logic to start the computation at new bar. The problem is that the first bar(0) seem the actual wild value and the bar(1) is the preeceding bar value, as i start on a 15 min chart a time modulo 15+ some seconds i get the value of the bar 15 minutes ago in bar(1) so in fact it's bar(2)!

The other problem is that the iCustom value was off about 40 pips! but it's maybe an indicator problem.

int start() {

//----+ Declaration of local variables

int bar,Vol[4];

double StepF[4], StepS[4], Atr[4], Cprice[4], dMov12, dMov23;

//----+ Declaration of static variables

static int LastBars_Up, LastBars_Dn;

static bool BUY_Sign, BUY_Stop, SELL_Sign, SELL_Stop;

//----++ CODE FOR LONG POSITIONS

if (Test_Up) {

int IBARS_Up = iBars(NULL, Timeframe_Up);

if (IBARS_Up >= MinBar_Up) {

if (LastBars_Up != IBARS_Up) { // We get a new bar!

//---- refresh price data

RefreshRates();

//----+ Initialization of variables

BUY_Sign = false;

BUY_Stop = false;

LastBars_Up = IBARS_Up;

//----+ CALCULATING INDICATOR VALUES AND UPLOADING THEM TO BUFFERS

for(bar = 1; bar <= 4; bar++) {

//StepF[bar-1] = iCustom(Symbol(),Timeframe_Up,"StepMa_v3",FPeriod_ Up,Kwatr_Up,Advance_Up,HighLow_Up,bar-1);

StepS[bar-1] = iCustom(Symbol(),Timeframe_Up,"StepMa_v3",SPeriod_ Up,Kwatr_Up,Advance_Up,HighLow_Up,bar-1);

//Vol[bar-1] = iVolume(Symbol(),Timeframe_Up, bar-1);

//Atr[bar-1] = iATR(Symbol(),Timeframe_Up,14, bar-1);

//Cprice[bar-1] = iClose(Symbol(),Timeframe_Up, bar-1);

}

//----+ DEFINING SIGNALS FOR TRADES

if (Close[0] > StepS[0]) // Above StepS

//if (StepF[1] > StepF[2]) // StepF moving up

//if (Atr[1] > Atrmin // < dline[2]) // previous Main under signal

//if (Vol[1] > Volmin) // Enough Volume?

BUY_Sign = true;

if (BUY_Sign == true) SELL_Stop = true; // force sell close before buy to avoid Hedging

if (BUY_Sign && Debug) {

Print ("Longopen S0 ",DoubleToStr(StepS[0],Digits)," S1 ",DoubleToStr(StepS[1],Digits),

" S2 ",DoubleToStr(StepS[2],Digits), "S3 ",DoubleToStr(StepS[3],Digits));

Print (" CL ",DoubleToStr(Close[0],Digits)," CL1 ",DoubleToStr(Close[1],Digits)," CL2 ",DoubleToStr(Close[2],Digits),

" CL3 ",DoubleToStr(Close[3],Digits));

}

if (Close[0] < StepS[0]) // Under StepS

//if (StepF[1] < StepF[2]) // StepF moving down

//if (Atr[1] > Atrmin // < dline[2]) // previous Main under signal

//if (Vol[1] > Volmin) // Enough Volume?

BUY_Stop = true;

if (BUY_Stop && Debug) {

Print ("Longclose S0 ",DoubleToStr(StepS[0],Digits)," S1 ",DoubleToStr(StepS[1],Digits),

" S2 ",DoubleToStr(StepS[2],Digits), "S3 ",DoubleToStr(StepS[3],Digits));

Print (" CL1 ",DoubleToStr(Cprice[1],Digits)," F0 ",DoubleToStr(StepF[1],Digits)," F1 ",DoubleToStr(StepF[2],Digits),

" F2 ",DoubleToStr(StepF[3],Digits));

}

} //----End (NewBar_Up)

Unable to load a .doc file??

Thanks

Marcel