Different results in ami and nest?

while back testing ,why ami and nest showing different results?

Please specify in brief by posting the code and conditions , so that i can check and let you know.

Hi Biju..

1. The Price shown in During Amibroker Scan is the Close Price of the Signal bar..(Always)

2. The Price shown in During Amibroker Back-test is may be any one of the Below

It depends on what settings u have in Back tester Settings under Trades Tab OR

U can control it in Formula level by Assigning BuyPrice / SellPrice / ShortPrice / CoverPrice

Close Price of The Signal Bar or

Open Price of The Signal Bar or

High Price of The Signal Bar or

Low Price of The Signal Bar or

Avg Price of The Signal Bar or

3. The Price U have in Nest/Pi is the Price at that time of Signal

To understand More easily..

Ur Database base interval is 1 min

Below is the sample 1min Data from 10:00:00 am to 10:09:59 am

Ticker,Date,Time,Open,High,Low,Close,Volume

AXISBANK,11-03-2015,10:09:00,589.65,590.25,589.1,589.65,23916  //Highest of the 10 min Bar

AXISBANK,11-03-2015,10:08:00,589.2,589.7,589.1,589.65,4643

AXISBANK,11-03-2015,10:07:00,589.35,589.5,588.75,589.4,75740

AXISBANK,11-03-2015,10:06:00,589.25,589.4,588.35,589.3,25061   //Lowest of the 10 min Bar

AXISBANK,11-03-2015,10:05:00,589.35,589.95,588.95,589.25,12904

AXISBANK,11-03-2015,10:04:00,588.6,589.45,588.6,589.35,10685

AXISBANK,11-03-2015,10:03:00,589,589,588.5,588.85,5166

AXISBANK,11-03-2015,10:02:00,589.2,589.3,588.45,589,7128

AXISBANK,11-03-2015,10:01:00,589.5,589.6,588.9,589.2,8707

AXISBANK,11-03-2015,10:00:00,589.5,589.6,589.4,589.5,4850

U r testing Ur Strategy in 10 min Chart interval

Suppose U get a Buy Signal at 10:03:59 am..

Ur Buy Order 'll be fired to Nest/Pi with price at 10:03:59 am i.e. 588.85 (See Above Quote)

So Ur Nest/Pi price 'll be 588.85..

Buy when U Scan ...It 'll show only the Close price of the Signal Bar...in this case it is 10 min Bar..

Its Opening Price is Open price at 10:00:00 am i.e. 589.5

Its Closing Price is Close price at 10:09:59 am i.e. 589.65

Ur Scan price will be  589.65

Same way Ur backtest price also ..

If Ur afl has Buyprice variable

For example

BuyPrice = valuewhen(Buy,C); then backtest price 'll be  589.65  (Close Price of 10Min Bar)

or

BuyPrice = valuewhen(Buy,O); then backtest price 'll be  589.5  (Open Price of 10Min Bar)

or

BuyPrice = valuewhen(Buy,H); then backtest price 'll be  590.25  (High Price of 10Min Bar)

or

BuyPrice = valuewhen(Buy,L); then backtest price 'll be  588.35  (Low Price of 10Min Bar)

U can't set the Price in Scan Bcoz it always show Close price of Signal Bar..

But in Backtest..If U want the Same price as it is in Nest ..U have code it accordingly..

Hope I explained it Clearly..

am using ADX AFL strategy ,when i bactest in PI and NEST(bar replay) with amibroker it gives results that is extremely different than the scan results in amibroker,but PI and NEST generates same results,as per this AFL ony buy and sell signals only,no short and cover,

_SECTION_BEGIN(“Chart Options”);
GfxSetBkMode(0);
SetChartOptions (0,chartShowDates|chartShowArrows,chartGridMiddle,0,0,10);
SetChartBkColor( colorBlack ) ;
SetChartBkGradientFill( colorBlack,colorBlack);
SetBarFillColor( IIf( C > O, colorLime, IIf(C <= O,colorRed,colorBlack ) ));
Plot(Close,“Close”,IIf( C > O, colorLime, IIf(C <= O,colorRed,colorBlack ) ),styleCandle|styleNoTitle);
pxw = Status(“pxwidth”);
pxh = Status(“pxheight”);
GfxSelectFont( “Lucida Fax”, 16, 700, False );
GfxSetTextColor( colorYellow );
GfxGradientRect( 1, 1, pxw, 30, colorGrey50, colorDarkGrey);
GfxTextOut( “AMIBROKER - NESTPLUGIN “, (pxw/2)-120, 4 );
GfxSetTextColor( colorGold );
GfxTextOut( Name(), 5, 4 );
GfxTextOut( Date(), PXW-250, 4 );
GfxSelectFont( “Lucida Fax”, 24, 700, False );
GfxSetTextColor( colorOrange );
GfxTextOut( “LTP:”+” “+WriteVal(LastValue(C,1),1.2), (PXW/2)-80, 60 );
GfxSelectFont( “Lucida Fax”, 11, 700, False );GfxSetTextColor( colorWhite );
//GfxTextOut( “Op :”+WriteVal(Open,1.2)+” Hi :”+WriteVal(High,1.2)+" Lo :"+WriteVal(Low,1.2)+" Cl :"+WriteVal(Close,1.2), 3, 35);
_SECTION_END();
_SECTION_BEGIN(“Inputs For Nest Plugin”);
Buy=Sell=Short=Cover=0;
BarN = ValueWhen(DateNum()!= Ref(DateNum(),-1),BarIndex());
BarNo = IIf(IsEmpty(BarN),BarIndex()+1,BarIndex()-BarN+1);
Bvalue = LastValue(ValueWhen(BarNo==1,C),1);
PrvC = IIf(IsEmpty(TimeFrameGetPrice(“C”,inDaily,-1)),ValueWhen(BarNo==1,O),TimeFrameGetPrice(“C”,inDaily,-1));
NClientId =“RB0730”;//Change To Ur Zerodha Client Id-Line No 30
NExch = “NFO”;//Change as per Ur Trading segment-Line No 31
NTrdSymbol = “JUSTDIAL15MARFUT”;//Name()+“FUT”;//Since Ur Ticker Format is SBIN15MAR…adding FUT to last 'll make Trade Symbol
NProdType = “MIS”;//Line No 33
NOrdType = “LIMIT”;//Line No 34
NLotNo = 1;//Enter Ur No of lots to Trade … DoNot Enter Lot size here-Line No 35
NOrder=“Null”;
_SECTION_END();
_SECTION_BEGIN(“Trading System”);
//Sample Trading System…Replace It with your own
_SECTION_BEGIN(“Background_Setting - “);
SetChartBkGradientFill( ParamColor(“BgTop”, colorBlack),
ParamColor(“BgBottom”, colorDarkGrey),ParamColor(“TitleBack”,colorGrey40) );
SetChartBkColor(ParamColor(“Outer Panel”,colorPaleBlue));
SetChartOptions(0,chartShowArrows|chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor(“Candle UP Color”, colorGreen),IIf(C<=O,ParamColor(“Candle Down Color”, colorRed),colorLightGrey)));
Plot(C,“Price”,IIf(C>O,ParamColor(“Wick UP Color”, colorDarkGreen),IIf(C<=O,ParamColor(“Wick Down Color”, colorDarkRed),colorLightGrey)),64,0,0,0,0);
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,””,31,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
_SECTION_END();
_SECTION_BEGIN(“Custom ADX settings”);
range = Param(“ADX Range”, 14, 2, 200, 1 );
no=Param(“TSL val”,5,2,25,1);
fc=Param(“tgt fct”,0.004,0.0025,1,0.01);
pd=PDI(range);
md=MDI(range);
a=Cross(pd,md);
b=Cross(md,pd);
a=ExRem(a,b);
b=ExRem(b,a);
col=IIf(a,ColorRGB(0,100,0),ColorRGB(100,0,0));
//Plot(a,"",col,styleHistogram|styleDashed|styleOwnS cale|styleNoLabel,0,1,0,0);
//Plot(b,"",col,styleHistogram|styleDashed|styleOwnS cale|styleNoLabel,0,1,0,0);
function TBR(no)
{
dres=HHV(H,no);
dsup=LLV(L,no);
davd=IIf(H>Ref(dres,-1),1,IIf(L<Ref(dsup,-1),-1,0));
davn=ValueWhen(davd!=0,davd,1);
dtsl1=IIf(davn==1,dsup,dres);
return dtsl1;
}
dtsl=TBR(no);
Buy = a AND (H>O );//AND O!=H);
Sell= b AND (L<O); //AND O!=L);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
SellPrice=ValueWhen(Sell,O,1);
BuyPrice=ValueWhen(Buy,O,1);
Buy=Ref(Buy,-1); // buy at the open of next bar of the signal
Sell=Ref(Sell,-1); // sell at the open of next bar of the signal
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), 51, layer = 0,yposition = Low, offset = -20);
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), 42, layer = 0, yposition = High, offset = -20); //shapeSmallCircle
Plot(dtsl, “”,colorGrey40, styleLine);// trail sl added
dist = 1.5ATR(8);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( “” + C[ i ], i, L[ i ] - dist[i], colorBrightGreen); // alteration - C instead of H/L
if( Sell[i] ) PlotText( “” + C[ i ], i, H[ i ] + dist[i], colorOrange);
}
for (i=BarCount-1; i>1; i–) {
if (Buy[i] == 1)
{
entry = O[i];
sig = “BUY”;
sl = dtsl[i];
tar1 = entry + (entry * fc);
tar2 = entry + (entry * 2
fc);
bars = i;
i = 0;
}
if (Sell[i] == 1)
{
sig = “SELL”;
entry = O[i];
sl = dtsl[i];
tar1 = entry - (entry * fc);
tar2 = entry - (entry * 2*fc);
bars = i;
i = 0;
}
}
GraphXSpace=10;
_SECTION_END();
_SECTION_BEGIN(“Title”);
Title =EncodeColor(colorYellow) + " ADX x~OVER " + “\n”
+EncodeColor(colorWhite)+ Name () + " | “
+EncodeColor(33) + Date() + “\n “
+EncodeColor(colorWhite)+ “Op : “+ EncodeColor(colorWhite)+ O + " | “
+EncodeColor(colorWhite)+ “Hi : “+ EncodeColor(colorWhite)+ H + " | “
+EncodeColor(colorWhite)+ “Lo : “+ EncodeColor(colorWhite)+ L + " | “
+EncodeColor(colorWhite)+ “Cls : “+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorOrange))+ C + " | “
+EncodeColor(colorWhite)+ “Change : (”+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorOrange)) + WriteVal(C-Ref(C,-1))+” Rs.”
+EncodeColor(colorWhite)+ " /”+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal( ROC( C, 1 ))+””+ " % “
+EncodeColor(colorWhite)+ “)\nVolume : " + WriteIf(V> Ref(V, -1),EncodeColor(colorBrightGreen),EncodeColor(colorOrange))+ WriteVal(V,1.0)+ “\n\n”
+EncodeColor(colorWhite)+ “Tgt1 : Rs “+ EncodeColor(colorWhite)+tar1 + “\n “
+EncodeColor(colorWhite)+ “Tgt2 : Rs “+ EncodeColor(colorWhite)+tar2+ “\n\n “
+EncodeColor(colorWhite)+ “Trail SL : Rs “+ EncodeColor(colorWhite)+ dtsl ;
_SECTION_END();
_SECTION_BEGIN(“NestPluginAPI”);
ORder = IIf(Buy,1,IIf(Sell,2,IIf(Short,3,IIf(Cover,4,0))));
BSCond = LastValue(ORder,1);
NLmtPrice = LastValue(ValueWhen(BSCond >0,C),1);
Checkone=StaticVarGetText(“Check”+StrFormat(Name()));
Checktwo = StrFormat(Name())+”-”+NumToStr(LastValue((Cum(Buy)+Cum(Sell)+Cum(Short)+Cum(Cover)),1),1.0)+”-”+NumToStr(GetChartID(),1.0);
if (LastValue(Buy)){NOrder=“BUY”;NRefNo = Name()+”-”+“Buy”+”-”+NumToStr(Cum(Buy),1.0)+”-”+Now(0); }
if (LastValue(Short)){NOrder=“SELL”;NRefNo = Name()+”-”+“Short”+”-”+NumToStr(Cum(Short),1.0)+”-”+Now(0); }
if (LastValue(Sell)){NOrder=“SELL”;NRefNo = Name()+”-”+“Sell”+”-”+NumToStr(Cum(Sell),1.0)+”-”+Now(0); }
if (LastValue(Cover)){NOrder=“BUY”;NRefNo = Name()+"-"+“Cover”+"-"+NumToStr(Cum(Cover),1.0)+"-"+Now(0); }
if (BSCond >0 AND CheckOne != CheckTwo){
{plus = CreateStaticObject(“Nest.PlusApi”);
plus.SetObjectName(NClientId); // result = Null;
plus.PlaceOrder(NOrder,NRefNo,NExch,NTrdSymbol,“DAY”,NOrdType,NLotNo,NLmtPrice,0,0,NProdType,NClientId);}
StaticVarSetText(“Check”+StrFormat(Name()),CheckTwo );}
_SECTION_END();

Hi Biju…
Ur AFL assigns the buy price as Open price of the Prev Candle…
U have to modify Like this…
Cut the Below Code in ue AFl
SellPrice=ValueWhen(Sell,O,1);
BuyPrice=ValueWhen(Buy,O,1);
and Paste it above the Line
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), 51, layer = 0,yposition = Low, offset = -20);
U’ll Get same Price in all…

hi algoGeek,
price changed but sitll difference
thanks

hi chocks,
thanks for your simple explanation