Hi, There are a couple of problems:
1. When trying to do an equivalence test, use the equivalence operator '==' not the assignment operator '='. 2. buyrule is an array. You cannot use the if statement on an array. If you just want to see what the value is, then run an exploration: Filter = buyrule; AddColumn(MA(Close, 6), "MA(6)"); http://www.amibroker.com/guide/h_exploration.html Otherwise, add a custom metric to your backtest. Mike --- In [email protected], "chuck_win" <ch...@...> wrote: > > Hi, > > I do backtesting, and want to check MA at the time of buying. > > My code looks like > > buyrule = cross(MACD, signal); > buy = buyrule; > buyprice = close; > sellrule = cross(signal, MACD); > sell = sellrule; > sellprice = close; > if (buyrule = true) { > str = StrFormat("%0.2f", MA(Close,6)); > _TRACE(NumToStr( DateTime(), formatDateTime ) + ", " + str); > > } > > I always get the MA at the ending time of last bar instead. > > Thanks for any help! > > Charles >
