Dear Nagarjuna,
Thank you for your reply. It must require to Backtest Purpose.
Here it is.
// Logic for uptrend or downtrend
k = EMA(StochK(39,3),3);
d = EMA(StochD(39,3,3),3);
uptrend= IIf( k > d, 1, 0 );
downtrend=IIf( k < d, 1, 0 );
// The current bar should be more than previous bar value + 5 points for buy in uptrend
BuyV = uptrend AND Ref(uptrend, -1) AND (H > ( Ref(H, -1) + 5));
// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = downtrend AND Ref(downtrend,-1) AND (L < ( Ref(L, -1) - 5));
// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1));
SellSB= BarsSince(Ref(SellV,-1));
// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,0);
//Datefine = 1;
// Check if it is time to close the postions.
EOD = iif(timenum() < 153000, 0, 1);
noEOD = iif(timenum() < 153000, 1, 0);
// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
// We can signal sell only if previous signal was a buy.
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
Sell = EOD AND BuySB < SellSB;
_SECTION_BEGIN("Smart Trader");
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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
PlotShapes( shapeUpArrow * Buy, colorGreen,0,L,-12);
PlotShapes( shapeDownArrow * Short, colorRed,0,H,-12);
_SECTION_END();