// Downloaded From https://www.WiseStockTrader.com
_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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

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

_SECTION_BEGIN("MA");
P2 = ParamField("Price field",-1);
Periods2 = Param("Periods", 50, 2, 300, 1, 10 );
Plot( TEMA( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

Buy= Cross(TEMA( P2, Periods2 ), LinearReg( P1, Periods1 ));
Sell=Cross(LinearReg( P1, Periods1 ), TEMA( P2, Periods2 ) );

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Filter=Buy OR Sell; 

AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange); 

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );