Dear All,
Please help,
This code by "Mastermind007" Sir, for the karthik's strategy of EMA110/CCI914).
I have added Entry/Exit time for intraday setup, it is working for entry but not covering/closing at exit time, it should close the position as per settings of end time in parameters.
i added following time param:
startTime = Param("Start Trading",100000,0,240000);
endTime = Param("Stop Trading",230000,0,240000);
//////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("EMA-CCI");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ColorRGB(192,192, 192));
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);
Plot(NewDay, "", ParamColor("NewDay", colorWhite), 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);
if (Interval() == in5Minute)
{
FilterPercent = Param("Filter Percent %", 0.2, 0.1, 2, 0.1) / 100;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 )
+" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
//========================================================================
EMA110 = EMA(C,110);
CCI14 = CCI(14);
startTime = Param("Start Trading",100000,0,240000);
endTime = Param("Stop Trading",230000,0,240000);
if (ParamToggle("Entry Line", "Show|Hide", 1) == 1)
{
Plot(EMA110,"EMA110",colorBlue,styleLine);
Plot(CCI14,"CCI(14)",colorBlue, styleOwnScale | styleNoLine);
}
bullish = C > EMA110 AND CCI14 > 100;
bearish = C < EMA110 AND CCI14 < -100;
LEP = (1 + FilterPercent) * H;
SEP = (1 - FilterPercent) * L;
CandleColor=IIf(bullish,colorGreen,IIf(bearish,colorRed,colorBlack));
Plot( C, "Close", CandleColor , styleNoTitle | styleCandle );
//========================================================================
BuyMode = Flip(bullish, bearish);
SellMode = Flip(bearish, bullish);
//========================================================================
LongEntryPrice = ValueWhen(BuyMode == 1 AND Ref(BuyMode,-1) == 0, LEP);
LongTargetPrice = LongEntryPrice + Param("Target",100, 0, 500, 0.01);
LongSLPrice = ValueWhen(BuyMode == 1 AND Ref(BuyMode,-1) == 0, L) - 10;
Buy = (BuyMode == 1) AND bullish AND Cross(H,LongEntryPrice) AND TimeNum() >= startTime AND TimeNum() < endTime;
Sell= (( ( Ref (BuyMode,-1) == 1) AND (BuyMode == 0))
OR Cross(H,LongTargetPrice)
OR Cross(LongSLPrice,L));
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
//========================================================================
ShortEntryPrice = ValueWhen(SellMode == 1 AND Ref(SellMode,-1) == 0, SEP);
ShortTargetPrice = ShortEntryPrice - Param("Target",10, 0, 500, 0.01);
ShortSLPrice = ValueWhen(SellMode == 1 AND Ref(SellMode,-1) == 0, H) + 10;
Short = (SellMode == 1) AND Cross(ShortEntryPrice, L)AND TimeNum() >= startTime AND TimeNum() < endTime;
Cover = ( ((Ref(SellMode,-1) == 1) AND (SellMode == 0))
OR (ShortTargetPrice >= L)
OR (H >= ShortSLPrice));
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
//========================================================================
PlotShapes(IIf(Buy , shapeUpArrow,shapeNone),colorGreen,0,L,Offset=-10);
PlotShapes(IIf(Sell, shapeStar, shapeNone), colorRed,0,H,Offset=-10);
PlotShapes(IIf(Cover, shapeStar, shapeNone), colorGreen,0,L,Offset=-10);
PlotShapes(IIf(Short, shapeDownArrow,shapeNone),colorRed,0,H,Offset=-10);
//========================================================================
if ( (SelectedValue(BuyMode) == 1) AND ((SelectedValue(BarsSince(Sell)) == 0) OR (SelectedValue(BarsSince(Sell)) >= SelectedValue(BarsSince(Buy)))))
{
endingBar = SelectedValue(BarIndex()) + 25;
startingBar = SelectedValue(BarIndex()) - 5;
Plot(LineArray(startingBar, SelectedValue(LongEntryPrice), endingBar, SelectedValue(LongEntryPrice), 0, True), "Long Entry", colorGreen, styleNoTitle| styleThick | styleDashed | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(LongTargetPrice), endingBar, SelectedValue(LongTargetPrice), 0, True), "Long Target", colorGreen, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(LongSLPrice), endingBar, SelectedValue(LongSLPrice), 0, True), "Stop Loss", colorRed, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(LongEntryPrice,"\nLong Entry Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(LongTargetPrice,"Long Target Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(LongSLPrice,"Long Stop Loss Price",colorRed, styleOwnScale | styleDashed | styleNoLine);
} else if ( ( SelectedValue(SellMode) == 1) AND ((SelectedValue(BarsSince(Cover)) == 0) OR (SelectedValue(BarsSince(Cover)) >= SelectedValue(BarsSince(Short)))))
{
endingBar = SelectedValue(BarIndex()) + 25;
startingBar = SelectedValue(BarIndex()) - 5;
Plot(LineArray(startingBar, SelectedValue(ShortEntryPrice), endingBar, SelectedValue(ShortEntryPrice), 0, True), "Short Entry", colorGreen, styleNoTitle| styleThick | styleDashed | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(ShortTargetPrice), endingBar, SelectedValue(ShortTargetPrice), 0, True), "Short Target", colorGreen, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(LineArray(startingBar, SelectedValue(ShortSLPrice), endingBar, SelectedValue(ShortSLPrice), 0, True), "Stop Loss", colorRed, styleNoTitle | styleDots | styleNoLabel, Null, Null);
Plot(ShortEntryPrice,"\nShort Entry Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(ShortTargetPrice,"Short Target Price",colorGreen, styleOwnScale | styleDashed | styleNoLine);
Plot(ShortSLPrice,"Short Stop Loss Price",colorRed, styleOwnScale | styleDashed | styleNoLine);
}
//========================================================================
segments = IIf( Interval() < inDaily, Day(), Month() );
segments = segments != Ref( segments , -1 );
Plot(segments, "", colorRed, styleHistogram | styleOwnScale );
//========================================================================
} else
{
_N(Title = "\n\n\n\n\n\n\n\nSORRY, BUT THIS AFL IS MEANT TO WORK ON INTERVAL OF 5 MINUTES ONLY");
}
_SECTION_END();
//===================================================================================
Please Help.
Ramulu