Hi seniors, Please help me. This is the complete formula But I am facing one problem in this formula.
Buy signal is generating Short side Please remove Buy signal from Short side.
I have tried but failed so kindly help me seniors.
(Please note I have written 5 Buy conditions in this formula Please don't change)
_SECTION_BEGIN("Realtimetips ");
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", colorBlack , styleNoTitle | styleCandle | GetPriceStyle() );
//
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);
if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
//PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-20);
exitshort = Cross(C,s5d);
//PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-20);
Buy = exitshort;
Sell = exitlong;
Short = exitlong;
Cover = exitshort;
//AlertIf( Buy, "", "BUY @ " + C, 1 );
//AlertIf( Sell, "", "SELL @ " + C, 2 );
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;
Buy0 = entry + (entry * .05);
tar0 = entry + (entry * .10);
tar1 = entry + (entry * .15);
tar2 = entry + (entry * .30);
tar3 = entry + (entry * .45);
tar4 = entry + (entry * 0.60);
StopLoss1 = entry - (entry * .10);
StopLoss2 = entry - (entry * .20);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "Sell";
entry = C;
sl = s5d;
Buy0 = entry - (entry * .05);
tar0 = entry - (entry * .10);
tar1 = entry - (entry * .15);
tar2 = entry - (entry * .30);
tar3 = entry - (entry * .45);
tar4 = entry - (entry * 0.60);
StopLoss1 = entry - (entry * .10);
StopLoss2 = entry - (entry * .20);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];
Plot(LineArray(bars-Offset, StopLoss1, BarCount, StopLoss1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, StopLoss2, BarCount, StopLoss2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, Buy0, BarCount, Buy0,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar0, BarCount, tar0,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar4, BarCount, tar4,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorTurquoise, styleLine|styleDots, Null, Null, Offset);
for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("StopLoss1 : @ " + StopLoss1, BarCount+3, StopLoss1, Null, Clr);
PlotText("StopLoss2 : @ " + StopLoss2, BarCount+3, StopLoss2, Null, Clr);
PlotText("Buy0 : @ " + Buy0, BarCount+3, Buy0, Null, Clr);
PlotText("Target 0 : @ " + tar0, BarCount+3, tar0, Null, Clr);
PlotText("Target 1 : @ " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText("Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);
PlotText("Target 4 : @ " + tar4, BarCount+3, tar4, Null, Clr);
PlotText("Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, "", colorCustom14, styleLine);
/////////////M
//GfxRectangle(pxw/2,1,(pxw/2)-5,pxh);
BarB = BeginValue(BarIndex());//Beginvalue of Barindex
BarE = EndValue(BarIndex());//EndValue of Barindex
BarC = BarIndex();//Current Barindex
BarL = LastValue(BarC,1);//LastValue of Barindex
BarT = BarIndex() - Nz(ValueWhen(Day()!= Ref(Day(),-1) ,BarIndex()),0) ;
TrdBegin = ParamTime("Trading Begin Time","09:15",0);
TrdEnd = ParamTime("Trading End Time","15:10",0);
SqOff = ParamTime("Square Off Time","15:14",0);
Lossp = Param("Loss Percentage",20.0,0.05,20,0.05)/100;// 20% Final// Lossp = Param("Loss Percentage",0.6,0.05,20,0.05)/100;
Profitp = Param("Profit Percentage",10.0,0.05,20,0.05)/100;
BuyPrice = ValueWhen(Buy,C);
ShortPrice = ValueWhen(Short,C);//short
BuySL = BuyPrice - (BuyPrice*Lossp);
ShortSL = ShortPrice + (ShortPrice*Lossp);
Buy0 = BuyPrice + (BuyPrice*Profitp);
Short0 = ShortPrice - (ShortPrice*Profitp);
////////////////////////////////
//Buy set 1 perfect
Buy1 = Cross(exitshort,0) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy2 = Cross(exitshort,0) OR Cross(Buy0,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy3 = Cross(exitshort,0) OR Cross(tar0,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy4 = Cross(exitshort,0) OR Cross(tar1,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy5 = Cross(exitshort,0) OR Cross(tar2,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy = Buy1 = Buy2 = Buy3 = Buy4 = Buy5;//Final
//Buy = Buy1 AND Buy2 AND Buy3 AND Buy4 AND Buy5;
//Buy = Buy1 OR Buy2 OR Buy3 OR Buy4 OR Buy5;
Sell = Cross(C,Short) OR Cross(BuySL,C) OR Cross(Buy,C) OR Cross(Buy1,C) OR Cross(StopLoss1,C) OR Cross(StopLoss2,C) OR Cross(tar0,C) OR Cross(tar1,C) OR Cross(tar2,C) OR Cross(tar3,C) OR Cross(tar4,C) OR TimeNum() >= SqOff;
Buytmp=Cross(Buy,0);
Buy = IIf(Ref(Buytmp, -1),1,0);
Selltmp=Cross(Sell,0);// this is required don't ignore
Sell = IIf(Ref(Selltmp, -1),1,0);
//Short Condition
Short = Cross(exitlong,0) OR TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Cover = Cross(Buy,C) OR Cross(C,ShortSL) OR Cross(tar0,C) OR Cross(tar1,C) OR Cross(C,tar2) OR Cross(C,tar3) OR Cross(C,tar4) OR TimeNum() >= SqOff;;//
Shorttmp=Cross(Short,0);
Short = IIf(Ref(Shorttmp, -1),1,0);
Covertmp=Cross(Cover,0);// this is required don't ignore
Cover = IIf(Ref(Covertmp, -1),1,0);
//testing
Buy = IIf(Ref(Sum(Buy,BarT),-1)==0,Buy,ExRem(Buy,Sell)); //Don't change setting
Sell = IIf(Ref(Sum(Sell,BarT),-1)==0,Sell,ExRem(Sell,Buy));
Short = IIf(Ref(Sum(Short,BarT),-1)==0,Short,ExRem(Short,Cover));
Cover = IIf(Ref(Sum(Cover,BarT),-1)==0,Cover,ExRem(Cover,Short));
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorYellow, 0,L, Offset=-30);
//PlotShapes(IIf(Buy2, shapeUpArrow, shapeNone),colorYellow, 0,L, Offset=-30);
//PlotShapes(IIf(Buy3, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-50);
PlotShapes(IIf (Sell, shapeCircle, shapeNone),colorRed);
//PlotShapes(IIf(Sell2, shapeCircle, shapeNone),colorYellow, 0,L, Offset=-35);
//PlotShapes(IIf(Sell3, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-50);