_SECTION_BEGIN("Test_code");
Lot1=Param("Lot1",1,1,20,1);
Lot2=Param("Lot2",1,1,20,1);
Lot3=Param("Lot3",1,1,20,1);
Lot4=Param("Lot4",1,1,20,1);
GAP1=Param("GAP1",2,1,20,1);
GAP2=Param("GAP2",6,1,20,1);
GAP3=Param("GAP3",12,1,20,1);
GAP4=Param("GAP4",1,1,20,1);
Tar1=Param("Tar1",3,1,20,1);
Tar2=Param("Tar2",6,1,20,1);
Tar3=Param("Tar3",9,1,20,1);
Tar4=Param("Tar4",1,1,20,1);
Plot( C, "Close", colorWhite, styleCandle, Zorder = 1);
SetChartOptions(0,chartShowArrows | chartShowDates);
//to calculate the avg price
function Calculate_Avg_Price(Avg_price,Gap_Price)
{
Avg_price1= (Avg_price +Gap_Price)/2;
return Avg_price1;
}
Gap=Lot=1;
//Buy=TimeFrameGetPrice("C",inWeekly,-1,expandFirst);
global Avg_Price;
//Avg_Price=0;
//consider the first trade price is
BuyPrice=270;
Avg_Price=BuyPrice;
//Avg_Price
PTar1=BuyPrice+Tar1;
//PTar2=BuyPrice+Tar2;
//PTar3=BuyPrice+Tar3;
//PTar1=Tar1+Avg_Price;
PTar2=Tar2+Avg_Price;
PTar3=Tar3+Avg_Price;
PGap1=BuyPrice-Gap1;
PGap2=BuyPrice-Gap2;
PGap3=BuyPrice-Gap3;
printf("\n P Tar1 value is =>"+PTar1);
printf("\n P Tar2 value is =>"+PTar2);
dist = 1.5*ATR(10);
flag_gap=flag_tar=0;
for(i=0;i<BarCount;i++)
{
// printf("\n ith value is =>"+i);
//Calculating the first target
//i.e. Verify the expected target is between the Value Of target1 AND target 2
if (C>=PTar1 AND C<=PTar2 )
{
Lot=Lot+1;
printf("\n Current log size is =>"+Lot);
//PlotText( "\n Target 1 price is " +PTar1 , i, H[ i ]-dist, colorYellow );
}
//calculate the gap
//if we take a Buy AND the price is moving downwards then add 1 more Lot for the FIRst gap
//also after addiding the first lot we need to calculate the avg price i.e. buyprice +gap price /2
if ( C<PGap1 AND C>PGap2 )
{
Gap=Gap+1;
Avg_Price=Calculate_Avg_Price(BuyPrice,PGap1);
//PlotText( "\n Gap 1 price is " +PGap1 , i+1, H[ i+1 ]-dist, colorWhite );
//PlotText( "\n Avg price is " +Avg_Price , i, H[ i ]-dist, colorWhite );
flag_gap=1;
}
//Calculate the second target
if (C>=PTar2 AND C<=PTar3 AND flag_tar!=2)
{
Lot=Lot+1;
//PlotText( "\n Target 1 price is " +PTar2 , i, H[ i ]-dist, colorYellow );
}
//Calculate the Second gap
if ( C<PGap2 AND C>PGap3 AND flag_gap!=2 )
{
Gap=Gap+1;
Avg_Price=Calculate_Avg_Price(Avg_Price,PGap2);
//PlotText( "\n Gap 2 price is " +PGap2 , i, H[ i ]-dist, colorYellow );
flag_gap=2;
//PlotText( "\n Avg price is " +Avg_Price , i+1, H[ i+1 ]-dist, colorWhite );
}
}
Plot(PTar1,"",colorGreen,styleDots) ;
Plot(PTar2,"",colorGreen,styleLine) ;
Plot(PGap1,"",colorYellow,styleDots) ;
Plot(PGap2,"",colorYellow,styleLine) ;
I am not able to plat gap value line .as per the avg price value in the above
code .
The above plot function is able to plot the Fix gap value .Its not considering the AVg_price value while draw the line .Verified with print statement
avg price calculation is correct