Seniors Help pl,Buy/Sell Signal after closing of the 2nd candle

#1
Below the code of AFL, linear regression 34 days/price crossover. I like to get buy/sell signal when price crossing linear regression.Buy signal should appear only when two candles closes above the linear regression line, Seniors help pl.

_SECTION_BEGIN("Price");
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() );
_SECTION_END();

_SECTION_BEGIN("Linear Regression");
P = ParamField("Price field",-1);
Periods = Param("Periods", 34, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

/*Buy or Sell Condition*/
Buy = Cross((C),LinearReg( Close , 34 ));
Sell = Cross(LinearReg( Close , 34 ), C);


/*Pot Buy or Sell Arrows*/
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

_SECTION_END();
 

Similar threads