# User error, formula looks into the future, was: Backtesting

Hello,
When i use Amibroker in live market, with certain AFL Amibroker gives a “Open Long” on breakout candle but after 5 or 6 candle if price falls below the open value amibroker deletes the trade instead of showing loss in the result. Please help

Thks

it is not backtesting issue, it is YOUR FORMULA that is wrong and looks into the future.

Noted Sir.

Please do help me to find error in below code pls. it will be very highly appreciated.
below is the basic ichimoku buy sell which is deletes the buy order automatically in backtesting result.

_SECTION_BEGIN(“Ichi”);
n1 = Param(“Conversion Line”,9,1,200,1);
n2 = Param(“Base Line”,26,1,400,1);
n3 = Param(“Lagging Span”,52,1,600,1);

TenkanSen =(HHV(H,n1)+LLV(L,n1))/2;
KijunSen =(HHV(H,n2)+LLV(L,n2))/2;
ChinkouSpan =Ref(C,-n2);
Cks = Close;
SenkouSpanA =Ref((KijunSen+TenkanSen)/2,-n2);
SpA =(KijunSen+TenkanSen)/2;
SenkouSpanB =Ref((HHV(H,n3)+LLV(L,n3))/2,-n2);
SpB =(HHV(H,n3)+LLV(L,n3))/2;
DL = Ref( C, 52);

//DL = Optimize (“DL”, 1000, 1, 100,1);

Plot (C,“Bars”,colorYellow,styleCandle);
Plot (TenkanSen,“Tenkan-sen”,colorRed);
Plot (KijunSen, “Kijun-sen”, colorBlue);
Plot (Cks,“Chinkou Span”,colorLime, style = styleLine,0,0,-n2);
Plot (SpA,“SenkouSpanA”,colorOrange,styleDashed,0,0,n2);
Plot (SpB,“SenkouSpanB”,colorViolet,styleDashed + styleThick,0,0,n2);
PlotOHLC (SpA,SpA,SpB,SpB,“Cloud”,IIf (SpA > SpB,colorPink,colorLavender),styleCloud, 10, 10, n2 );

Sell = Cross(KijunSen,TenkanSen) AND (DL<KijunSen);

IIf( (Sell),PlotShapes(shapeStar*Sell,colorRed,0,Low,-60,0),0);

_SECTION_END();

The line below from your code looks into the future. A positive “ref” value looks forward into the future.

``DL = Ref( C, 52);``

See the example in the Function Reference link below:

https://www.amibroker.com/guide/afl/ref.html

(please also remember to use the code tags when posting code)

Thank You Bodhi…

Found my mistake. Appreciated your help.