PART 1
Code:
_SECTION_BEGIN("Back_Set");
SetChartBkGradientFill( ParamColor("BT", colorGreen),
ParamColor("BB", colorOrange),ParamColor("Title",colorGreen) );
SetChartBkColor(ParamColor("OuterPanel",colorOrange));
SetChartOptions(0,chartShowArrows|chartShowDates);
noteboard =ParamToggle("Message Board","Show|Hide",0);
optno = Optimize("TSL",Param("A (Change To Optimise)",10, 1, 55 ,1),1,20 ,1);
multi1 = Optimize("Multi1",Param("B (Chng2Opt)",5, 1, 55 ,1),1, 25 ,1);
multi2 = Optimize("Multi2",Param("C (Chng2Opt)",22, 1, 55 ,1),1, 25 ,1);
Tsl =ParamToggle("SlLine","No|Yes");
stoprev =ParamToggle("Swch2Stop&Rev","No|Yes");
CAtEnd = ParamToggle("ClosetradeEOD", "No|Yes");
mktc=Param("MarktEndTime",152500,000000,235959,1 );
function TBR(optno)
{
dres=HHV(H,optno);
dsup=LLV(L,optno);
davd=IIf(H>Ref(dres,-1),1,IIf(L<Ref(dsup,-1),-1,0));
davn=ValueWhen(davd!=0,davd,1);
dtsl1=IIf(davn==1,dsup,dres);
return dtsl1;
}
SetChartOptions(0,chartShowArrows|chartShowDates);
atsl=TBR(optno);
Hr=360;
Hr1=25;
Vr=14;
dB=H>atsl;
dS=L<atsl;
TimeFrameSet(multi1*Interval());
btsl=TBR(optno);
WB=H>btsl;
WS=L<btsl;
TimeFrameRestore();
ctsl=TimeFrameExpand(btsl,multi1*Interval(),expandFirst);
wb=TimeFrameExpand(WB,multi1*Interval(),expandFirst);
ws=TimeFrameExpand(WS,multi1*Interval(),expandFirst);
TimeFrameSet(multi2*Interval());
dtsl=TBR(optno);
MB=H>dtsl;
MS=L<dtsl;
TimeFrameRestore();
mtsl=TimeFrameExpand(dtsl,multi2*Interval(),expandFirst);
mb=TimeFrameExpand(MB,multi2*Interval(),expandFirst);
ms=TimeFrameExpand(MS,multi2*Interval(),expandFirst);
Buy = IIf((Low > ctsl AND Low > dtsl), DB, ((WB AND Low > atsl AND Low > dtsl) OR (MB AND Low > atsl AND Low > ctsl)));
Sell=IIf(CAtEnd==False, (DS OR (DS AND WS) AND (Low > dtsl)), (DS OR (DS AND WS) AND (Low > dtsl)) OR TimeNum() > mktc);
Short = IIf((High < ctsl AND High < dtsl), DS, (WS AND High < atsl AND High < dtsl) OR (MS AND High < atsl AND High < ctsl ));
Cover=IIf(CAtEnd==False, (DB OR (DB AND WB) AND (High < dtsl)), (DB OR (DB AND WB) AND (High < dtsl)) OR TimeNum() > mktc);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
lg=Flip(Buy,Sell);
St=Flip(Short,Cover);
Relax = NOT lg AND NOT Buy AND NOT St AND NOT Sell AND NOT Sell AND NOT Cover;
SellSL=ValueWhen(Short,atsl,1);
BuySL=ValueWhen(Buy,atsl,1);
BuyDifference= BuyPrice - BuySL;
SellDifference = SellSL - SellPrice;
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGold, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
PlotShapes(IIf(CAtEnd==True AND TimeNum() > mktclose AND NOT Relax, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
tsl = IIf(Buy OR lg OR Short OR St AND NOT Relax, atsl,Null);
tslcolor = IIf(Buy OR lg AND NOT Relax, colorBrightGreen, colorCustom12);
Plot(tsl, "",tslcolor, styleLine);
SellPrice=ValueWhen(Short,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Short,Cover);
Relax = NOT Long AND NOT Buy AND NOT St AND NOT Sell AND NOT Sell AND NOT Cover;
SellSL=ValueWhen(Short,atsl,1);
BuySL=ValueWhen(Buy,atsl,1);
BuyDifference= BuyPrice - BuySL;
SellDifference = SellSL - SellPrice;
tar1 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + BuyDifference), (SellPrice - SellDifference));
tar2 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (2*BuyDifference)), (SellPrice - (2*SellDifference)));
tar3 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (4*BuyDifference)), (SellPrice - (4*SellDifference)));
buyach1 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar1, 0);
buyach2 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar2, 0);
buyach3 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar3, 0);
sellach1 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar1, 0);
sellach2 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar2, 0);
sellach3 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar3, 0);
Trend = ADX(14) > 25 AND NOT ADX(14) < Ref(ADX(14), -1);
Range = ADX(14) < 25 AND NOT ADX(14) > Ref(ADX(14), -1);
mycolor=IIf(Long, colorBrightGreen,(IIf(shrt,colorCustom12,colorDarkGrey)));
SetBarFillColor( mycolor );
trendup = IIf(Long, colorDarkGreen, colorDarkGrey);
trendcolor = IIf(shrt, colorRed, trendup);
Plot( C, "Close", trendcolor, styleCandle );
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorGrey40,styleHistogram|styleDots|styleNoLabel|styleOwnScale);