_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorBlack));
SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartOptions(0,chartShowArrows|chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
grid_day = Day()!=Ref(Day(),-1);
Plot(grid_day,"",colorGrey40,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
_SECTION_END();
_SECTION_BEGIN("Parameters");
messageboard =ParamToggle("Message Board","Show|Hide",0);
beginTradeTime= Param("Strt Time",091700,091500,151000,10);
endTradeTime= Param("End Time",151500,091500,151000,10);
EndDay = ParamTime( "No trade after ", "15:10:00" );
EndDay2 = ParamTime( "close position ", "15:10:00" );
tn = TimeNum();
dn = DateNum();
Exit = Ref( tn < EndDay2, -1 ) AND ( tn >= EndDay2 OR dn < Ref( dn, 1 ) );
_SECTION_END();
_SECTION_BEGIN("trade system");
fact=U=Param("Main Curve Factor > 0",100,10,2000,1);
fact2=P=Param("Support Curve Factor..0-100",10,0,100,1);
ST=(P*U/100);
tMONITOR= TEMA(C,10);
tslow=TEMA(TEMA(Close,10),10);
Slptslow = (1000000*((tslow- Ref(tslow, -1))/tslow));
slptmonitor= (1000000*((tmonitor- Ref(tmonitor, -1))/tmonitor));
//Plot (tmonitor, "", colorGold, ParamStyle("Style"));
//Plot (tslow,"", colorWhite,ParamStyle(" Slope Style"));
Buy = Sell = Short =
Cover = 0;
Buy = slptslow > fact AND Tn<EndDay;
Short = slptslow <-fact AND Tn<EndDay;
//Sell= ((Short) OR slptslow < ST ) OR exit; ;
//Cover= ((Buy) OR slptslow > ST ) OR exit;
Buysetup =
Flip(Buy,Short);
Shortsetup =Flip(Short,Buy);
Sell = Shortsetup OR exit;
Cover = Buysetup OR exit;
ApplyStop(stopTypeTrailing ,2,Optimize( "max. profit stop level", 5, 2, 10, 1 ),1,False,0); // stop loss trailing of 5 % of the profit
ApplyStop(stopTypeLoss,stopModePercent,Optimize( "max. loss stop level", 5, 2, 10, 1 ),True,0);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
SellPrice1=ValueWhen(Sell,H,1);
BuyPrice1=ValueWhen(Buy,L,1);
ShortPrice1=ValueWhen(Short,H,1);
CoverPrice1=ValueWhen(Cover,L,1);
BuyPrice = ValueWhen(Buy,BuyPrice1); bp=NumToStr(BuyPrice,1.2);
ShortPrice = ValueWhen(Short,shortPrice1); shp=NumToStr(ShortPrice,1.2);
SellPrice = ValueWhen(Sell,sellPrice1);
CoverPrice = ValueWhen(Cover,coverPrice1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy);
GraphXSpace=10;
/*
printf("\nBuy = " + NumToStr(Buy, 1.2) +
" Sell = " + NumToStr(Sell, 1.2) +
" Short = " + NumToStr(Short, 1.2) +
" Cover = " + NumToStr(Cover, 1.2) + "\n");
BuyInd = LastValue(Buy);
ShortInd = LastValue(Short);
SellInd = LastValue(Sell);
CoverInd = LastValue(Cover);
_TRACE("#, Indicators 2, Static, BuyInd = " + NumToStr(BuyInd,1.0) +
", SellInd = " + NumToStr(SellInd, 1.0) +
", ShortInd = " + NumToStr(ShortInd, 1.0) +
", CoverInd = " + NumToStr(CoverInd, 1.0) );*/
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorAqua, layer = 0,yposition = Low, offset = -10);
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -10);
PlotShapes( IIf(Cover, shapeHollowUpArrow,shapeNone), colorAqua, layer = 0,yposition = Low, offset = 10);
PlotShapes( IIf(Sell,shapeHollowDownArrow,shapeNone), colorPink, layer = 0, yposition = High, offset = -10);
//profit calculation
prf_ln= NumToStr((C-BuyPrice),1.2);
prf_sh= NumToStr((SellPrice-C),1.2);
//total equity calculation
firstTradeBarOfDay = TimeNum() >= beginTradeTime ;
firstTradeBarOfDay = firstTradeBarOfDay - Ref(firstTradeBarOfDay,-1);
inBuy1 = Flip(Buy,Sell);
inShort1 = Flip(Short,Cover);
totalPositions = IIf(inBuy1,1,0) * 1 + IIf(inShort1,-1,0) * 1;
actionAtBar = totalPositions - Ref(totalPositions,-1);
tc2 = TimeNum() >= beginTradeTime AND TimeNum() <= 151000;
eq1 = totalPositions * 1 * (C - Ref(C,-1));
eq2 = actionAtBar * 1 * (C - Ref(C,-1));
price_entry_exit = IIf(Buy,BuyPrice,IIf(Sell,SellPrice,IIf(Short,ShortPrice,IIf(Cover,CoverPrice,0))));
eq3 = actionAtBar * 1 * (C - price_entry_exit);
eqTotal = eq1 - eq2 + eq3 ;
rtEquity = tc2 * Sum(eqTotal,BarsSince(Ref(firstTradeBarOfDay,1) == 1));
StaticVarSet("eqSI_CAM",rtEquity);
_SECTION_END();
_SECTION_BEGIN("msg brd");
if
(messageboard == 0 )
{
SetChartOptions(0,chartShowArrows|chartShowDates);
GfxSelectFont( "Tahoma", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorDarkGrey );
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 230;
x = 5;
x2 = 230;
y = pxHeight;
GfxSelectPen( colorLightBlue, 1);
GfxRoundRect( x, y - 120, x2, y , 7, 7 ) ;
GfxTextOut( Name(), 13, y-105);
GfxTextOut( Date(), 13, y-85);
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Long At : "+(BP) + "","")), 13, y-65);
GfxTextOut( ("" + WriteIf (Shrt AND NOT Short, "Short At : "+(ShP) + "","")), 13, y-65);
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Current P/L : "+prf_ln+" / lot","")), 13, y-45);
GfxTextOut( ("" + WriteIf (Shrt AND NOT Short, "Current P/L : "+ prf_sh+" / lot","")), 13, y-45);
GfxTextOut("Total P/L Today = Rs. " + NumToStr((rtequity),1.2)+" / lot", 13 , y-25);
}
_SECTION_END();