_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("abhig");
EMA1 = EMA(Close, 5);
EMA2 = EMA(Close, 20);
threshP = Param("Min Profit trail", 1.005, 0.001, 2, 0.001);
tslfactor = Param("Tsl Factor", 0.8, 0.01, 1, 0.01);
slfactor = Param("SL factor", 0.998, 0.80, 1, .001);
Plot(EMA1, "EMA1", colorGreen, styleLine);
Plot(EMA2, "EMA2", colorRed, styleLine);
Buy = Cross(EMA1, EMA2);
Short = Cross(EMA2, EMA1);
BuyPrice = ValueWhen(Buy, Close);
ShortPrice = ValueWhen(Short, Close);
// threshold profit
tLongProfit = (BuyPrice * (threshP));
tShortProfit = (ShortPrice * (2-threshP));
// highest/lowest since last buy signal
maxLong = HighestSince(Buy, High);
lossLong = LowestSince (Buy, Low);
// highest/lowest since last short signal
maxShort = LowestSince(Short, Low);
lossShort = HighestSince (Short, High);
// Original SL, I guess
Longstoploss = (BuyPrice* slfactor);
Shortstoploss = (ShortPrice * (2-slfactor));
// Trailing SL
tslLong = tLongProfit + abs(maxLong - tLongProfit) * tslfactor;
tslShort = tShortProfit - abs(maxShort - tShortProfit) * tslfactor;
//Sell = Short OR IIf (losslong<longstoploss, Cross (losslong, Close),0) OR IIf(maxLong>tLongProfit, Cross(tslLong, Close),0);
//Cover = Buy OR IIf (lossShort>shortstoploss, Cross (Close, lossshort),0) OR IIf(maxShort<tShortProfit, Cross(Close, tslShort), 0);
Sell = Short OR Cross (losslong, Close) OR IIf(maxLong>tLongProfit, Cross(tslLong, Close),0);
Cover = Buy OR Cross (Close, lossshort) OR IIf(maxShort<tShortProfit, Cross(Close, tslShort), 0);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
PlotShapes( IIf(Buy, shapeUpArrow, shapeNone ), colorBrightGreen, layer = 0,yposition = Low, offset = -10);
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorPink, layer = 0, yposition = High, offset = -10);
PlotShapes( IIf(Cover, shapeStar,shapeNone), colorBrightGreen, layer = 0,yposition = Low, offset = -20);
PlotShapes( IIf(Sell,shapeStar,shapeNone), colorPink, layer = 0, yposition = High, offset = 20);
_SECTION_END();
_SECTION_BEGIN("Magified Market Price");
FS=Param("Font Size",30,11,100,1);
Hor=Param("Horizontal Position",940,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSetBkMode( 1 );
GfxSelectFont("Times New Roman", FS, 700, True );
-GfxSetTextColor( colorLime );
GfxTextOut(""+C, Hor+200 , Ver );
/*
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetTextColor(colorYellow );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+200 , Ver+65 );
*/
_SECTION_END();