Code:
RoundLotSize = 1;
MarginDeposit = 350;
TickSize = 0;
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("simple reversal");
//buy and short conditions
Cond1 = Ref ( Low, -1 ) < Ref ( Low, -2 );
Cond2 = Ref ( Close, -1 ) > Ref ( Close, -2 );
Cond3 = Ref ( Close, -1 ) > Ref ( Open , -1);
Cond4 = Ref ( High , -1 ) < Ref ( High , -2 );
Cond5 = Ref (RSI (14), -2) < 30;
Cond6 = Ref (RSI (14) , -1 ) > 30 ;
Cond7 = Ref (Low, -1 ) == Ref (LLV (Low, 8) , -1 );
Cond8 = High > Ref ( High, -1 );
Cond9 = Ref ( High, -1) > Ref (High, -2 );
Cond10 = Ref ( Close, -1 ) < Ref ( Close, -2 );
Cond11 = Ref ( Close, -1 ) < Ref ( Open , -1);
Cond12 = Ref ( Low , -1 ) > Ref ( Low, -2);
Cond13 = Ref ( RSI (14) , -2 ) > 70 ;
Cond14 = Ref ( RSI (14) , -1 ) < 70 ;
Cond15 = Low < Ref (Low, -1) ;
Cond16 = Ref (High, -1 ) == Ref ( HHV (High ,8) , -1 );
Cond17 = TimeNum() < 143100 ;//signals after 2.30 r ignored
Cond18 = TimeNum() > 093100 ; // signals bfor 9.30 r ignored
Cond19 = Close > 100 ;// shares below 100 Rs r ignored
Buy = Cond1 AND Cond2 AND Cond3 AND Cond4 AND Cond5 AND Cond6 AND Cond7 AND Cond8 AND Cond17 AND Cond18 AND Cond19;
Short = Cond9 AND Cond10 AND Cond11 AND Cond12 AND Cond13 AND Cond14 AND Cond15 AND Cond16 AND Cond17 AND Cond18 AND Cond19;
Cap = Param("Capital", 50000, 1000, 100000, 1000);
risk = Param("Risk", 0.1, 0.1, 100, 0.1);
BuyPrice = ValueWhen(Buy, (Ref (High ,-1)+0.05));// with this getting correct buy price
ShortPrice = ValueWhen(Short, (Ref (Low, -1)-0.05));
LongSL = ValueWhen(Buy, Ref(Low, -1));
ShortSL = ValueWhen(Short, Ref(High, -1));
LongPoints = BuyPrice - LongSL;
ShortPoints = ShortSL - ShortPrice;
PointValue = 1;
//Shares = (Cap*risk)/LongSL;
Shares = IIf(Buy OR Short, IIf(Buy, (Cap*risk)/LongSL, (Cap*risk)/ShortSL), IIf(Nz(BarsSince(Buy))>Nz(BarsSince(Short)), (Cap*risk)/LongSL, (Cap*risk)/ShortSL));
shares = floor(shares);
SetPositionSize(shares, spsShares);
Sell = Cross(High, BuyPrice + LongPoints) OR Cross(LongSL, Low);
Cover = Cross(ShortPrice - ShortPoints, Low) OR Cross(High, ShortSL);
SellPrice = ValueWhen(Sell, LongSL);
CoverPrice = ValueWhen(Cover, ShortSL);
//printf("$" + BarsSince(Buy) + "^" + BarsSince(Short) + "^" + LongSL + "^" + shares + "\n");
//printf("$" + BarsSince(Short) + "^" + BarsSince(Buy) + "^" + ShortSL + "^" + shares + "\n");
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
R = Ref (High ,-1 ) - Ref ( Low , -1);
if(Status("action") == actionExplore);
Filter = Buy | Short;
SetOption ("NoDefaultColumns", True );
AddTextColumn(Name(), "SYMBOL");
AddColumn(DateTime(), "DATE", formatDateTime);
AddColumn(IIf(Buy, 66, 83), "TRIGGER", formatChar, colorWhite, IIf(Buy, colorGreen, colorRed));
AddColumn(IIf(Buy, Ref ( High , -1), Ref ( Low, -1 )), "TRIGGER PRICE", 1.2);
AddColumn(IIf(Buy, Ref(Low ,-1), Ref(High , -1)) , "Stop Loss", 1.2);
AddColumn(IIf(Buy, Ref (High , -1) + R , Ref (Low , -1) - R ), "Target", 1.2);
//AddColumn(IIf(Buy, 420/R ,420/R ),"shares",1.2 );
AddColumn(shares,"shares",1.2 );
//to get alert via speakers and in alert output window with the text put in aphostrophies,working fine
AlertIf( Buy, "SOUND C:\\WINDOWS\\Media\\Raga.wav", "REVBUY", 1 );
AlertIf( Short, "SOUND C:\\Windows\\Media\\Raga.wav", "REVSELL", 3 );
//to get alert in email, need to correct this, not getting mail alert
AlertIf( Buy, "EMAIL", "A sample alert on "+FullName(), 1 );
AlertIf( Short, "EMAIL", "A sample alert on "+FullName(), 3 );
PlotShapes(shapeUpArrow*Buy,colorBrightGreen,0,L);
PlotShapes (shapeDownArrow*Short, colorRed, 0, H);
PlotShapes(Cover*shapeHollowUpArrow,colorGreen,0,L);
PlotShapes (Sell*shapeHollowDownArrow, colorRed, 0, H);
_SECTION_END();
Now with this code, excess signals are avoided. Getting clean buy,sell,cover,short signals. But still not getting any backtest results. Exploration working fine.