Problem with getting exact price of entry

Hi! In the code below I just tried to generate buy sell signal on crossing of some fibo level. When the 1st level cross initial and on the cross of 2nd level scale in with same position size. Everything works fine visually in chart, but on backtesting i am getting different price of entry rather than the level mentioned price although exit price was correct. From backtest setting when I change the periodicity from 15M to 5M it also stop taking the scale in entry. I think , I makes some blander in the buyprice and shortprice code. Please have a look....

_SECTION_BEGIN("Fibo_Breakout");
PSZ = Param("PositionSize",75,1,100000);
SetPositionSize(psz,spsShares);

PDC= TimeFrameGetPrice("C",inDaily,-1);
PDH = TimeFrameGetPrice("H",inDaily,-1);
PDL = TimeFrameGetPrice("L",inDaily,-1);

PDR = PDH-PDL;
X1= Param("Factor",7.3,.1,100,.1);
A1 = Param("Intra %", 11.8, .1,100);
B1 = Param("Delivery %",38.2,.1,100);


IBL = PDc+(pdr*((x1+a1)/100));//1st buy and cover level
PBL = PDc+(pdr*((x1+B1)/100));//2nd BUY LEVEL

ISL = PDC - (pdr*((x1+a1)/100));// 1st short and sell level
PSL = PDC - (pdr*((x1+b1)/100)); // 2nd short level


IB = Cross(H,IBL);
PB = Cross(H,PBL);


IS = Cross(ISL,L);
PS = Cross(PSL,L);

IB = ExRem(IB,IS);
PB = ExRem(PB,IS);
IS = ExRem(IS,IB);
PS = ExRem(PS,IB);


BothOnSameBar = IB AND PB; 
PB = ExRem(PB, IS); // Remove subsequent Entry2 signals until ExitSignal
OnlyPB = PB AND NOT IB; 

InitialEntry = BothOnSameBar OR IB;
ScaleInEntry = OnlyPB;

Buy = 	IIf(InitialEntry , 1, 
		IIf(ScaleInEntry, sigScaleIn, 0
		));

Sell = IS;






BothOnSameBar1 = IS AND PS; 
PS = ExRem(PS, IB); // Remove subsequent Entry2 signals until ExitSignal
OnlyPS = PS AND NOT IS; 

InitialEntry1 = BothOnSameBar1 OR IS;
ScaleInEntry1 = OnlyPS;

Short = 	IIf(InitialEntry1 , 1, 
		IIf(ScaleInEntry1, sigScaleIn, 0
		));

Cover = IB;


/////////////////////////////////////////////////
//////////////Get the exact price////////////////
////////////////////////////////////////////////


BuyPrice = 	IIf(Buy==InitialEntry,IBL,IIf(Buy==ScaleInEntry,PBL,Null));
SellPrice = ISL;
ShortPrice = IIf(Short==InitialEntry1,ISL,IIf(Short==ScaleInEntry1,PSL,Null));
CoverPrice = IBL;





//////////////////////////////////////////////
 Plot(IBL,"IntarBUYlevl", ParamColor("IntarBUYlevl",colorLime));
 Plot(PBL,"DeliverBUYLevel", ParamColor("DeliverBUYLevel",colorDarkGreen));
 Plot(ISL,"IntarSELLlevl", ParamColor("IntarSELLlevl",colorLightOrange));
 Plot(PSL,"DeliverSELLLevel", ParamColor("DeliverSELLLevel", colorRed));
 
 PlotShapes(Buy*shapeSquare,colorGreen,0,L,-50);
 PlotShapes(Buy*shapeSquare,colorGreen,0,L,-60);
 PlotShapes(Buy*shapeUpArrow,colorWhite,0,L,-55);

 PlotShapes(Short*shapeSquare,colorRed,0,H,50);
 PlotShapes(Short*shapeSquare,colorRed,0,H,60);
 PlotShapes(Short*shapeDownArrow,colorWhite,0,H,-55);

 
 _SECTION_END();
 

want to delet this post as I already solved the problem.

If you solved it, it is good idea to post the solution to the forum, so others can learn from your experience. This forum is not only about getting but also about giving.

6 Likes

problem was with defining the BuyPrice and ShortPrice, correct code is

BuyPrice = 	IIf(InitialEntry,IBL,IIf(ScaleInEntry,PBL,0));
SellPrice = ISL;
ShortPrice = IIf(InitialEntry1,ISL,IIf(ScaleInEntry1,PSL,0));
CoverPrice = IBL;
1 Like