Thanks so much Mike for your help. It works on backtester now. I will try to make it work on optimize next.
Charles --- In [email protected], "Mike" <sfclimb...@...> wrote: > > Charles, > > You got scared away from the earlier example that I referred you to ( > http://finance.groups.yahoo.com/group/amibroker/message/146164 ). Yet, with a > one line change, it would give you exactly what you want. > > Just change: > > foreignATR = ATR( 14 ); > > To > > foreignATR = MA( Close, 6 ); > > Do this and, I believe, you would have exactly what you're asking for. You > would likely then want to change the names and output strings to refer to MA > instead of ATR. But, there would be no further change in logic other than > that one line. > > Mike > > --- In [email protected], "chuck_win" <chaoy@> wrote: > > > > Hi Mike, > > > > I need to run optimize, and have spent a lot of time to add a custom column > > of MA on optimize result list and no luck so far. > > > > Is it possible to find the bar index or bar number of buying and use the > > number to refer the MA like > > > > myMA = ref(MA(close, 6), -17); > > > > Thank you very much! > > > > Charles > > > > > > > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > > > 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" <chaoy@> 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 > > > > > > > > > >
