Exit at Target Level achieved with exit indicator

Dear sir, I want to exit at when the price touch the Target3 and Sell Exit vice versa. So please modify below mentioned AFL.

////////////////////////////////////////////////////////////////////

Buyexit = when price candle touch @ Target 3 and signal should be generated @ exit point.

Sellexit = when price candle touch @ Target 3 and signal should be generated @ exit point.

///////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Realtimetips ");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack , styleNoTitle | styleCandle | GetPriceStyle() ); 
//
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-12);
exitshort = Cross(C, s5d);
PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-12);

Buy = exitshort;
//Buy = exitlong = Cross(C, s5d)> tar3 = entry - (entry * .0100);

Sell = exitlong;
Short = Sell;
Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = s5d[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0075);
tar3 = entry + (entry * .0100);
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = s5d[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0075);
tar3 = entry - (entry * .0100);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorTurquoise, styleLine|styleDots, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("Target 1 : " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText("Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);
PlotText("Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, "", colorCustom14, styleLine);
printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 2; 
x2 = 290;

y = pxHeight;

GfxSelectPen( colorLightBlue, 1); // broader color 
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;

GfxTextOut( (" ......................................."),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("Target:1 : " + tar1), 13, y -80);
GfxTextOut( ("Target:2 : " + tar2), 13,y-60);
GfxTextOut( ("Target:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;

x = 290; 
x2 = 570;
GfxSelectSolidBrush( colorTurquoise );
GfxSetTextColor( colorBlack);
GfxSelectFont( "Tahoma", 14, 100 );
GfxSetBkMode( 1 );
GfxSelectPen( colorLightBlue, 1); // broader color 
GfxRoundRect( x, y - 43, x2, y , 7, 7 ) ;

GfxSelectFont( "Tahoma", 10, 400 );

}
//

function PlotDT()
{
displacement = Param("Displacement Value", 12, 1, 100, 1);
slmode = ParamToggle("Stop Loss", "Auto|Manual", 1);
width = ParamToggle("Width", "HL|OC", 1);
Count = Param("No. of DTL", 4, 4, 20, 1);
NewDay = Day()!= Ref(Day(), -1);

for (i=BarCount-1;i > 1; i--)
{
if(NewDay[i] == 1)
{
printf("High : " + i);
if(width == 1)
{
DL = IIf(O[i] < C[i], O[i], C[i]);
DH = IIf(O[i] > C[i], O[i], C[i]);
}
else
{
DL = L[i];
DH = H[i];
}
Bars = i;
i = -1;
}
}

if(slmode==1)
{
distance = displacement;
}
else
{
distance = ((DH+DL)/2) * .01;
}

Plot(LineArray(BarCount - (BarCount-Bars+20), DH, BarCount+35, DH, 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Buy Above " + DH + "; Stop Loss = " + DL, BarCount + 0, DH, colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DH+ distance), BarCount+35, (DH+ distance), 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DH+ distance), BarCount + 0, (DH+ distance), colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), DL, BarCount+35, DL, 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Sell Below " + DL + "; Stop Loss = " + DH, BarCount + 0, DL, colorBlack, colorOrange);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DL-distance), BarCount+35, (DL-distance), 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DL-distance), BarCount + 0, (DL-distance), colorBlack, colorOrange);
}
function PlotIndicators()
{

SetChartOptions(0,chartShowArrows|chartShowDates);
/* Standard Error Bands */
Periods = Param("Standard Error", 80, 3, 200, 1); 
Smooth = Param("Smooth",14,2,100,1);


LRCurve = LinearReg( C, periods ); 
MALRCurve = MA(LRCurve, Smooth);
SEValue = StdErr( C, periods ); 
SErrorAvg = MA(SEValue, Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;

Plot( MALRCurve , "MidBand", ParamColor("ColorMB",colorIndigo) , styleDashed|styleNoTitle); 
Plot( LowerBand , "LowerBand", ParamColor("ColorLo",colorOrange) , styleLine|styleThick|styleNoTitle);
Plot( UpperBand , "UpperBand", ParamColor("ColorUp",colorGreen) , styleLine|styleThick|styleNoTitle);

Ch = TimeFrameGetPrice("C", in1Minute/60);
clr = IIf(Ch[BarCount-2] > Ch[BarCount-1],colorRed,colorLime);

Plot(LineArray(0,C[BarCount-1],BarCount-1,C[BarCount-1],15), "", Clr, styleLine|styleNoLabel, Null, Null, 30);
PlotText("CMP:" + C[BarCount-1], BarCount+5, C[BarCount-1],colorBlack,Clr);

LRPeriods = Param("Length", 40, 3, 200, 1); 
LRCurve = LinearReg( C, LRPeriods ); 

PlotLR = IIf(LRCurve < LowerBand, (LRCurve + LowerBand)/2, IIf(LRCurve > UpperBand, (LRCurve + UpperBand)/2, LRCurve));
PlotLR = (PlotLR + SwingLine)/2;
//Plot( PlotLR , "Stop Loss |", ParamColor("SLColor",colorBlue), 4+8+32+2048); 
//Plot( SwingLine, "SwingLine", ParamColor( "SWColor", colorBlue ), ParamStyle("StyleSW",style=styleThick|styleNoLabel , mask=maskDefault) ); 

bc1 = (Cross(C, MALRCurve) OR Cross(C, UpperBand) OR Cross(C, LowerBand)) AND (C > SwingLine);
bc2 = Cross(C, SwingLine) AND (C > MALRCurve OR C > UpperBand OR C > LowerBand);

sc1 = (Cross(MALRCurve, C) OR Cross(UpperBand, C) OR Cross(LowerBand, C)) AND (C < SwingLine);
sc2 = Cross(SwingLine, C) AND (C < MALRCurve OR C < UpperBand OR C < LowerBand);
Buy = bc1 OR bc2;
Sell = sc1 OR sc2;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//PlotShapes(shapeCircle*Buy + shapeCircle *Sell, IIf(Buy, colorBlue, colorRed), 0, IIf(Buy, L, H), IIf(Buy, -12, 12));

}
//PlotDT();
_SECTION_END();

For the above requirement

_SECTION_BEGIN("Realtimetips ");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack , styleNoTitle | styleCandle | GetPriceStyle() ); 
//
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-12);
exitshort = Cross(C, s5d);
PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-12);

Buy = exitshort;
//Buy = exitlong = Cross(C, s5d)> tar3 = entry - (entry * .0100);

Sell = exitlong;
Short = Sell;
Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = s5d[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0075);
tar3 = entry + (entry * .0100);
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = s5d[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0075);
tar3 = entry - (entry * .0100);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorTurquoise, styleLine|styleDots, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("Target 1 : " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText("Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);
PlotText("Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, "", colorCustom14, styleLine);
printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 2; 
x2 = 290;

y = pxHeight;

GfxSelectPen( colorLightBlue, 1); // broader color 
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;

GfxTextOut( (" ......................................."),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("Target:1 : " + tar1), 13, y -80);
GfxTextOut( ("Target:2 : " + tar2), 13,y-60);
GfxTextOut( ("Target:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;

x = 290; 
x2 = 570;
GfxSelectSolidBrush( colorTurquoise );
GfxSetTextColor( colorBlack);
GfxSelectFont( "Tahoma", 14, 100 );
GfxSetBkMode( 1 );
GfxSelectPen( colorLightBlue, 1); // broader color 
GfxRoundRect( x, y - 43, x2, y , 7, 7 ) ;

GfxSelectFont( "Tahoma", 10, 400 );

}
//

function PlotDT()
{
displacement = Param("Displacement Value", 12, 1, 100, 1);
slmode = ParamToggle("Stop Loss", "Auto|Manual", 1);
width = ParamToggle("Width", "HL|OC", 1);
Count = Param("No. of DTL", 4, 4, 20, 1);
NewDay = Day()!= Ref(Day(), -1);

for (i=BarCount-1;i > 1; i--)
{
if(NewDay[i] == 1)
{
printf("High : " + i);
if(width == 1)
{
DL = IIf(O[i] < C[i], O[i], C[i]);
DH = IIf(O[i] > C[i], O[i], C[i]);
}
else
{
DL = L[i];
DH = H[i];
}
Bars = i;
i = -1;
}
}

if(slmode==1)
{
distance = displacement;
}
else
{
distance = ((DH+DL)/2) * .01;
}

Plot(LineArray(BarCount - (BarCount-Bars+20), DH, BarCount+35, DH, 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Buy Above " + DH + "; Stop Loss = " + DL, BarCount + 0, DH, colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DH+ distance), BarCount+35, (DH+ distance), 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DH+ distance), BarCount + 0, (DH+ distance), colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), DL, BarCount+35, DL, 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Sell Below " + DL + "; Stop Loss = " + DH, BarCount + 0, DL, colorBlack, colorOrange);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DL-distance), BarCount+35, (DL-distance), 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DL-distance), BarCount + 0, (DL-distance), colorBlack, colorOrange);
}
function PlotIndicators()
{

SetChartOptions(0,chartShowArrows|chartShowDates);
/* Standard Error Bands */
Periods = Param("Standard Error", 80, 3, 200, 1); 
Smooth = Param("Smooth",14,2,100,1);

LRCurve = LinearReg( C, periods ); 
MALRCurve = MA(LRCurve, Smooth);
SEValue = StdErr( C, periods ); 
SErrorAvg = MA(SEValue, Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;

Plot( MALRCurve , "MidBand", ParamColor("ColorMB",colorIndigo) , styleDashed|styleNoTitle); 
Plot( LowerBand , "LowerBand", ParamColor("ColorLo",colorOrange) , styleLine|styleThick|styleNoTitle);
Plot( UpperBand , "UpperBand", ParamColor("ColorUp",colorGreen) , styleLine|styleThick|styleNoTitle);

Ch = TimeFrameGetPrice("C", in1Minute/60);
clr = IIf(Ch[BarCount-2] > Ch[BarCount-1],colorRed,colorLime);

Plot(LineArray(0,C[BarCount-1],BarCount-1,C[BarCount-1],15), "", Clr, styleLine|styleNoLabel, Null, Null, 30);
PlotText("CMP:" + C[BarCount-1], BarCount+5, C[BarCount-1],colorBlack,Clr);

LRPeriods = Param("Length", 40, 3, 200, 1); 
LRCurve = LinearReg( C, LRPeriods ); 

PlotLR = IIf(LRCurve < LowerBand, (LRCurve + LowerBand)/2, IIf(LRCurve > UpperBand, (LRCurve + UpperBand)/2, LRCurve));
PlotLR = (PlotLR + SwingLine)/2;
//Plot( PlotLR , "Stop Loss |", ParamColor("SLColor",colorBlue), 4+8+32+2048); 
//Plot( SwingLine, "SwingLine", ParamColor( "SWColor", colorBlue ), ParamStyle("StyleSW",style=styleThick|styleNoLabel , mask=maskDefault) ); 

bc1 = (Cross(C, MALRCurve) OR Cross(C, UpperBand) OR Cross(C, LowerBand)) AND (C > SwingLine);
bc2 = Cross(C, SwingLine) AND (C > MALRCurve OR C > UpperBand OR C > LowerBand);

sc1 = (Cross(MALRCurve, C) OR Cross(UpperBand, C) OR Cross(LowerBand, C)) AND (C < SwingLine);
sc2 = Cross(SwingLine, C) AND (C < MALRCurve OR C < UpperBand OR C < LowerBand);
Buy = bc1 OR bc2;
Sell = sc1 OR sc2;
Short = Buyexit;
Cover = Sellexit;
Buyexit = LastValue()> tar3;
Sellexit = LastValue()< tar3;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//PlotShapes(shapeCircle*Buy + shapeCircle *Sell, IIf(Buy, colorBlue, colorRed), 0, IIf(Buy, L, H), IIf(Buy, -12, 12));

}
//PlotDT();
_SECTION_END();

Dear sir, How to generate Buyexit signal (i.e. circle) on above mentioned AFL. Please reply.

you can run the afl or can scan it with the RT data in amibroker

Dear sir, My idea is when I enter in buy then want to exit @ target 3 price and a signal will go to the PI software. It is possible send signal @target 3 price to PI software.

in the above afl we have buy and sell signals and i have given Exit orders for both buy and sell at target 3 as you have defined, but, just verify as you have given same target for both short and long

Dear sir, when I back tested or live market I exit only sell signal instead of target 3 price. If I exit @ target 3 price alert should be generated to know the AFL is working well.

Dear sir, No signal generate on Target3. How to exit ? Please check the AFl.
Short = Buyexit;
Cover = Sellexit;
Buyexit = LastValue()> tar3;
Sellexit = LastValue()< tar3;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

No signal generate on Target3. Please look the afl and generate buy exit signal when below mentioned condition fulfilled.
Buy = exitshort;
Sell = exitlong;
Short = exitlong;
Cover = exitshort;
Now please write the buy exit script @ target 3 price.

in AFL there will be only buy, sell short and long , for exit @ target 3 , can only defined, as AFL does n;t know where you have took position, and in above afl there is only one tar3 , is it for both long and short? you can contact some AFL expert for this.

Here you go. You have set value 1 in Target parameter to Exit position if target 1% is Achieved(Target 3).

_SECTION_BEGIN("Realtimetips ");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, “Close”, colorBlack , styleNoTitle | styleCandle | GetPriceStyle() );
//
messageboard = ParamToggle(“Message Board”,“Show|Hide”,0);
showsl = ParamToggle(“Stop Loss Line”, “Show|Hide”, 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

Target=Param(“Target”,0.030,0.010,100,0.001,0);
//Target=Param(“Target”,0.0030,0.0001,100,0.0001,0);
Target1=Target/100;
//Target = Param( “Target%”, partar1, partar1, partar1, 0 );
//target_point=Optimize(“target_point”,Target,20,200,1);
target_point=C*Target1;
SetPositionSize(100,spsShares);

if (showsl == 0)
{Plot(s5d,“Stop Loss”,colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-12);
exitshort = Cross(C, s5d);
PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-12);

Buy = exitshort;
//Buy = exitlong = Cross(C, s5d)> tar3 = entry - (entry * .0100);

//Sell = exitlong;
Short = exitlong;
//Cover = Buy;
//Buy = ExRem(Buy,Sell);
//Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
//AlertIf( Buy, “”, "BUY @ " + C, 1 );
//AlertIf( Sell, “”, "SELL @ " + C, 2 );

sellflag_short=IIf(Short==1, True,0);
//Shortflag=Buyflag=IIf(NewDay == 1 ,2,Null);

//this is for when short is active and Buy signal is coming

Coverflag_buy=IIf(Buy==1,True,0);

// to set the flag when buy condition is true

IIf(Buy==1,Buyflag=1,0);

BuyPrice1=ValueWhen(Buy,C,1);
SellPrice1=BuyPrice1+target_point;

//printf(“n before sell signal coming SellPrice:-” +SellPrice1);
Sell_Cond=exitlong;
Sell_Cond=IIf(H >=SellPrice1,True,False);
printf(“n DD->Sell Cond Value is =>”+Sell_Cond);

//short flag is used to close the condition when buy condition is active at the same time short is also active (in short when the buy signal is active short signal is coming so closing the position of buy @short price);

printf(“n Buy flag value is =>”+BuyFlag);
printf(“n Sell_flag_short value is =>”+Sellflag_short);

//Shortflag=Close the existing position when Short Signal arrived
//End Day:-close the open position at the end of the day
Sell=IIf((BuyFlag==1) AND (Sell_Cond==1) ,True ,Null);

//this is for when buy is active and short signal is coming
Sell=IIf(((BuyFlag==1) AND (Sellflag_short==1 ) ),True ,Sell);

//Shortflag=Buyflag=IIf(NewDay == 1 ,2,Null);

Sell=ExRem(Sell,Buy);

printf(“n Buy Verible value is =>”+Buy);
printf(“n Sell Verible value is =>”+Sell);

//SellPrice=ValueWhen(Sell,H,1);
//printf(“n sellsell price is :-” +SellPrice);

ShortPrice=ValueWhen(Short,C,1);

//Setting the flag when short condition is active

IIf(Short==1,Shortflag=1,0);

printf(“Short flag value is =>”+Shortflag);

printf(“n short sell flag value is =>” +Sellflag_short);

ShortPrice1=ValueWhen(Short,C,1);

//Cover the Condition Of the Lower point

CoverPrice1=ShortPrice1-target_point;

printf (“Short price is for price1 is =>”+ ShortPrice1);
printf (“CoverPrice is for price1 is =>”+ CoverPrice1);

Cover_cond= IIf(L<=CoverPrice1,True,False);
printf(“n Cover Cond Value is =>”+Cover_Cond);
//Cover the position when Short is active AND Current price(L) is Less then Condition price OR Close the position end Of the Day

Cover=IIf((ShortFlag==1) AND Cover_Cond==1 ,True,Null) ;

//this is for covering the position when buy signal is appering when short signal is active .clsoing the existing short position

Cover=IIf((ShortFlag==1) AND (Coverflag_buy==1),True,Cover);

printf(“n Cover value is =>”+Cover);

CoverPrice=ValueWhen(Cover,C,1);

printf(“n Cover price is ->”+CoverPrice);

Cover=ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorLime, 0, H, Offset=0);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorOrange , 0, L, Offset=0);

for(i=BarCount-1;i>1;i–)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = “BUY”;
sl = s5d[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0075);
tar3 = entry + (entry * .0100);
bars = i;
i = 0;
}
if(Short[i] == 1)
{
sig = “SELL”;
entry = C[i];
sl = s5d[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0075);
tar3 = entry - (entry * .0100);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == “BUY”, colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), “”, Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), “”, Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), “”, Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), “”, colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), “”, colorTurquoise, styleLine|styleDots, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("Target 1 : " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText(“Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);
PlotText(“Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, “”, colorCustom14, styleLine);
printf(“Last " + sig + " Signal came " + (BarCount-bars) + " bars ago”);
printf(”\n” + sig + " @ : " + entry + “\nStop Loss : " + sl + " (” + WriteVal(IIf(sig == “SELL”,entry-sl,sl-entry), 2.2) + “)”+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + “\nTarget_3 : " + tar3);
printf(”\nCurrent P/L : " + WriteVal(IIf(sig == “BUY”,(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( “Tahoma”, 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig ==“BUY”)
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( “pxchartheight” ) ;
xx = Status( “pxchartwidth”);
Left = 1100;
width = 310;
x = 2;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorLightBlue, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;

GfxTextOut( (" …"),27,y-160);
GfxTextOut( (“Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago”), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig ==“BUY”,sig + " @ “,sig + " @”) + " : " + entry), 13, y-120);
GfxTextOut( (“Trailing SL : " + sl + " (” + WriteVal(IIf(sig == “SELL”,entry-sl,sl-entry), 2.2) + “)”), 13, y-100);
GfxTextOut( ("Target:1 : " + tar1), 13, y -80);
GfxTextOut( ("Target:2 : " + tar2), 13,y-60);
GfxTextOut( ("Target:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == “BUY”,(C-entry),(entry-C)),2.2)), 13, y-22);;

x = 290;
x2 = 570;
GfxSelectSolidBrush( colorTurquoise );
GfxSetTextColor( colorBlack);
GfxSelectFont( “Tahoma”, 14, 100 );
GfxSetBkMode( 1 );
GfxSelectPen( colorLightBlue, 1); // broader color
GfxRoundRect( x, y - 43, x2, y , 7, 7 ) ;

GfxSelectFont( “Tahoma”, 10, 400 );

}
//

function PlotDT()
{
displacement = Param(“Displacement Value”, 12, 1, 100, 1);
slmode = ParamToggle(“Stop Loss”, “Auto|Manual”, 1);
width = ParamToggle(“Width”, “HL|OC”, 1);
Count = Param(“No. of DTL”, 4, 4, 20, 1);
NewDay = Day()!= Ref(Day(), -1);

for (i=BarCount-1;i > 1; i–)
{
if(NewDay[i] == 1)
{
printf("High : " + i);
if(width == 1)
{
DL = IIf(O[i] < C[i], O[i], C[i]);
DH = IIf(O[i] > C[i], O[i], C[i]);
}
else
{
DL = L[i];
DH = H[i];
}
Bars = i;
i = -1;
}
}

if(slmode==1)
{
distance = displacement;
}
else
{
distance = ((DH+DL)/2) * .01;
}

Plot(LineArray(BarCount - (BarCount-Bars+20), DH, BarCount+35, DH, 1), “”, colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Buy Above " + DH + "; Stop Loss = " + DL, BarCount + 0, DH, colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DH+ distance), BarCount+35, (DH+ distance), 1), “”, colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DH+ distance), BarCount + 0, (DH+ distance), colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), DL, BarCount+35, DL, 1), “”, colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Sell Below " + DL + "; Stop Loss = " + DH, BarCount + 0, DL, colorBlack, colorOrange);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DL-distance), BarCount+35, (DL-distance), 1), “”, colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DL-distance), BarCount + 0, (DL-distance), colorBlack, colorOrange);
}
function PlotIndicators()
{

SetChartOptions(0,chartShowArrows|chartShowDates);
/* Standard Error Bands */
Periods = Param(“Standard Error”, 80, 3, 200, 1);
Smooth = Param(“Smooth”,14,2,100,1);

LRCurve = LinearReg( C, periods );
MALRCurve = MA(LRCurve, Smooth);
SEValue = StdErr( C, periods );
SErrorAvg = MA(SEValue, Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;

Plot( MALRCurve , “MidBand”, ParamColor(“ColorMB”,colorIndigo) , styleDashed|styleNoTitle);
Plot( LowerBand , “LowerBand”, ParamColor(“ColorLo”,colorOrange) , styleLine|styleThick|styleNoTitle);
Plot( UpperBand , “UpperBand”, ParamColor(“ColorUp”,colorGreen) , styleLine|styleThick|styleNoTitle);

Ch = TimeFrameGetPrice(“C”, in1Minute/60);
clr = IIf(Ch[BarCount-2] > Ch[BarCount-1],colorRed,colorLime);

Plot(LineArray(0,C[BarCount-1],BarCount-1,C[BarCount-1],15), “”, Clr, styleLine|styleNoLabel, Null, Null, 30);
PlotText(“CMP:” + C[BarCount-1], BarCount+5, C[BarCount-1],colorBlack,Clr);

LRPeriods = Param(“Length”, 40, 3, 200, 1);
LRCurve = LinearReg( C, LRPeriods );

PlotLR = IIf(LRCurve < LowerBand, (LRCurve + LowerBand)/2, IIf(LRCurve > UpperBand, (LRCurve + UpperBand)/2, LRCurve));
PlotLR = (PlotLR + SwingLine)/2;
//Plot( PlotLR , “Stop Loss |”, ParamColor(“SLColor”,colorBlue), 4+8+32+2048);
//Plot( SwingLine, “SwingLine”, ParamColor( “SWColor”, colorBlue ), ParamStyle(“StyleSW”,style=styleThick|styleNoLabel , mask=maskDefault) );

bc1 = (Cross(C, MALRCurve) OR Cross(C, UpperBand) OR Cross(C, LowerBand)) AND (C > SwingLine);
bc2 = Cross(C, SwingLine) AND (C > MALRCurve OR C > UpperBand OR C > LowerBand);

sc1 = (Cross(MALRCurve, C) OR Cross(UpperBand, C) OR Cross(LowerBand, C)) AND (C < SwingLine);
sc2 = Cross(SwingLine, C) AND (C < MALRCurve OR C < UpperBand OR C < LowerBand);
Buy = bc1 OR bc2;
Sell = sc1 OR sc2;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//PlotShapes(shapeCircle*Buy + shapeCircle *Sell, IIf(Buy, colorBlue, colorRed), 0, IIf(Buy, L, H), IIf(Buy, -12, 12));