ROC takes an array as argument. If you pass a scaler, then that scaler gets 
treated as an array with all its elements set to the same value. In other 
words, no change from one bar to the next.

Just calculate ROC normally, then access the result using your bar index. e.g.

foreignROC = ROC(Close);
var1 = foreignROC[bar];

Mike

--- In [email protected], "senior_banana" <senior_ban...@...> wrote:
>
> I'm trying to use ROC() on a per bar basis, but all I get is zero.
> 
> Abbreviated example below, but
>  - C[bar] works as expected.
>  - ROC(C) gives the same result for every bar (as expected)
>  - ROC(C[bar]) gives me Zero.  I would expect this to give me ROC for that 
> bar.  Is there a way to do that?
> 
> Thanks,
> Ryan
> 
> 
> SetCustomBacktestProc("");
> 
> if (Status("action") == actionPortfolio) {
>       barDates = DateTime();
> 
>       bo = GetBacktesterObject();
>       bo.PreProcess();
> 
>       for (bar = 0; bar < BarCount; bar++) {
>               barDate = barDates[bar];
> 
>               for (sig = bo.GetFirstSignal(bar); sig; sig = 
> bo.GetNextSignal(bar)) {
>                       if (sig.IsEntry() && sig.IsLong()) {
>                               SetForeign("XLE");
>       
>                               //THIS NUMBER IS ALWAYS ZERO???
>                               Var1 = ROC(C[bar]);
> 
>                               _TRACE(NumToStr(bar)+" "+NumToStr(C[bar])+" 
> "+NumToStr(Var1));
>       
>                               RestorePriceArrays();   
>                       }
>               }
>               bo.HandleStops(bar);
>               bo.UpdateStats(bar, 1);
>               bo.UpdateStats(bar, 2);
>       }
>       bo.PostProcess();
> }
> 
> Buy = C > MA(C,300);
> Sell = C < MA(C,300);
>


Reply via email to