Need help in improving Non- rapainting AFL to scan stocks

#1
Hi, I’m working on a intraday stock scanner which is plotting the signal on previous bars in many cases(see the attached image for clarification). I would be grateful if anyone can help me modifying its behavior and plot the signal on current bar.

https://ibb.co/czL8p6

https://ibb.co/h1ypwm


Code:
_SECTION_BEGIN("TRIAL");
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

/* TIMEFRAME  */
//H50 =  Ref(HHV(C,3750),-1);
H20 =  Ref(HHV(C,1500),-1);
L20 = Ref(LLV(C,1500),-1);

DOpen = TimeFrameGetPrice( "O", inDaily, 0 ); // gives you Todays Open price.
DHigh = TimeFrameGetPrice( "H", inDaily, 0 ); // gives you Todays High price.
DLow = TimeFrameGetPrice( "L", inDaily, 0 ); // gives you Todays Low price.
DLast = TimeFrameGetPrice( "C", inDaily, 0); // gives you Todays Last traded price.
DOpenY = TimeFrameGetPrice( "O", inDaily, -1 ); // gives you YESTERDAYS Open price.
DCloseY = TimeFrameGetPrice( "C", inDaily, -1 ); //

NetP = log(DLast)*((DLast - DLow)/DLow*100);
NetN = log(DLast)*((DLast - DHigh)/DHigh*100);


Buy =  NetP >=15.0 AND (Ref(C, 0))>= H20  AND  (PDI(14) - MDI(14)) >25;
Sell =  NetN<= -15.0 AND (Ref(C, 0))<= L20 AND  (MDI(14) - PDI(14)) >25;;

Buy[BarCount-1]=Null;
Sell[BarCount-1]=Null;


AddColumn( Buy, "Buy" );
AddColumn( Sell, "Sell" );
settradedelays( 0, 0, 0, 0 );
Filter = Buy OR Sell ;

pchng= ((Dlast - DCloseY)/DCloseY*100);
Net = IIf( Buy, NetP, IIf(Sell, NetN, Null));

colorstatus = IIf( Net == NetN, colorRed, IIf(Net == NetP, colorGreen, Null));

AddColumn( Net, "NET ",2.2,colorWhite,colorstatus );
AddColumn(pchng, "%CHG",2.2 );


shape = Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorLime, colorRed),0,IIf( Buy, low, high) );

_SECTION_END();
 

copypasteaee

Humbled by Markets
#2
use exrem

buy = exrem(buy,sell);
sell =...........