I want to limit the number of rentry trades to once on the buy side and once on the sell side if the SL is hit on a certain day I used the below formula but it is not working . Can someone help me how can i limit the trades
The below formula i used which is not working
Nooftradeperday = Param( "No of Signal Perday", 2, 1, 100,1 );
This is the actual trading strategy where I need help, appreciate if anyone can help in this regard
Noofcontractparam = Param("No of Contract/share", 1, 1, 500, 1);
Noofcontract = IIf(RoundLotSize>0, RoundLotSize*Noofcontractparam, Noofcontractparam);
SetPositionSize( Noofcontract, spsShares ); // trade 1 contract
// The Standard Pivot Formula for One Timeframe
Buffter = Optimize( "Buffter ",1, 0, 50,1 );
Type=-1;
Displayshow = ParamList("Show Pivots", "selected only|all|hide" );
Hslide = Param("Slide Horizontally",70,1,500,1);
Vslide = 50;
GraphLabelDecimals = 2;
dn1= inDaily;
separator = Day()!= Ref(Day() , -1 );
// Get Prices
Yhigh = TimeFrameGetPrice( "H", dn1, Type );
Ylow = TimeFrameGetPrice( "L", dn1, Type );
Yclose = TimeFrameGetPrice( "C", dn1, Type );
if (Interval() < dn1)Plot( separator, "", Colorlightgrey, Stylehistogram |Styledashed| Styleownscale|Stylenolabel |styleNoTitle, Null, Null, 0,-256, 1);
_SECTION_BEGIN("Trading Time");
EntryStart = ParamTime( "Trade After", "09:15" );
EntryEnd = ParamTime( "No Trade After", "15:00" );
ExitAll = ParamTime( "Exit All Pos", "15:20" );
_SECTION_END();
dn = DateNum();
Newday = dn!=Ref(dn,-1);
FirstCandletime = ValueWhen(Newday, TimeNum());
FirstCandletimec = FirstCandletime >= EntryStart;
if (Interval() < inDaily) Plot(Newday , "", Colorlightgrey, Stylehistogram |Styledashed| Styleownscale|Stylenolabel |styleNoTitle, Null, Null, 0,-256, 1);
EntryStart1 = Ref(TimeNum(), -1) < EntryStart AND TimeNum()>= EntryStart;
EntryStart2 = IIf(FirstCandletimec, Newday, EntryStart1);
EntryEnd1 = Ref(TimeNum(), -1) < EntryEnd AND TimeNum()>= EntryEnd;
ExitTiming1 = Ref(TimeNum(), -1) < ExitAll AND TimeNum()>=ExitAll;
Nextday = dn!=Ref(dn, 1);
LastCandletime = ValueWhen(Nextday, TimeNum());
LastCandletimec = LastCandletime <= ExitAll;
TradeTiming = Flip(EntryStart2, EntryEnd1);
ExitTiming = IIf(LastCandletimec, Nextday, ExitTiming1);
// THE STANDARD FLOOR PIVOTS FORMULA
Pivot = ( Yhigh+ Ylow + Yclose )/3;
BC = ( Yhigh+ Ylow )/2;
YR1 = (2*Pivot)-Ylow;
YR2 = Pivot +(Yhigh -Ylow);
YR3 = YR1 +(Yhigh-Ylow);
YR4 = YR3 + (YR2 - YR1);
TC = (Pivot - BC) + Pivot;
Pivot = ( Yhigh+ Ylow + Yclose )/3;
BC = ( Yhigh+ Ylow )/2;
YS1 = (2*Pivot)-Yhigh;
YS2 = Pivot -(Yhigh - Ylow);
YS3 = YS1 - (Yhigh-Ylow);
YS4 = YS3 - (YS1 - YS2);
Buy = Low > YR1 AND TradeTiming AND Ref(Low, -1) < YR1;
Sell = Low < (YR1 - Buffter) OR ExitTiming;
Short = High < YS1 AND TradeTiming AND Ref(High, -1) > YS1;
Cover = High > (YS1 + Buffter) OR ExitTiming;
Nooftradeperday = Param( "No of Signal Perday", 2, 1, 100,1 );
Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
//BUY SHORT ARROW
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-15);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-25);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-20);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=15);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-20);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorOrange, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorViolet, 0,H, Offset= 20);
// PARAMETERS
//day
PivotR4 = ParamList("R4", "HIDE|SHOW");
PivotR3 = ParamList("R3", "HIDE|SHOW");
PivotR2 = ParamList("R2", "HIDE|SHOW");
PivotR1 = ParamList("R1", "SHOW|HIDE");
PivotTC = ParamList("TC", "HIDE|SHOW");
PivotP = ParamList("Pivot","SHOW|HIDE", 1);
PivotBC = ParamList("BC", "HIDE|SHOW");
PivotS1 = ParamList("S1", "SHOW|HIDE");
PivotS2 = ParamList("S2", "HIDE|SHOW");
PivotS3 = ParamList("S3", "HIDE|SHOW");
PivotS4 = ParamList("S4", "HIDE|SHOW");
Rcolor = ParamColor("Resistance Color", colorOrange);
Pcolor = ParamColor("Central Color", colorDarkYellow);
Scolor = ParamColor("Support Color", colorBrightGreen);
// PLOTS
//day
if ((PivotP=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (Pivot,"\nPivot ",Pcolor,styleLine);
if ((PivotTC=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (TC,"\nTC ",Pcolor,styleDashed);
if ((PivotBC=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (BC,"\nBC ",Pcolor,styleDashed);
if ((PivotR1=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot(YR1,"\nR1 ",Rcolor,styleDashed);
if ((PivotR2=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot(YR2,"\nR2 ",Rcolor,styleDashed);
if ((PivotR3=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot(YR3,"\nR3 ",Rcolor,styleDashed);
if ((PivotR4=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot(YR4,"\nR4 ",Rcolor,styleDashed);
if ((PivotS1=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (YS1,"\nS1 ",Scolor,styleDashed);
if ((PivotS2=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (YS2,"\nS2 ",Scolor,styleDashed);
if ((PivotS3=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (YS3,"\nS3 ",Scolor,styleDashed);
if ((PivotS4=="SHOW" OR Displayshow=="all") && Displayshow!="hide" && Interval() < dn1) Plot (YS4,"\nS4 ",Scolor,styleDashed);
// LABELS
Timeframe = "Daily";
for( i = 0; i < BarCount; i++ )
{
//day
if(i+Hslide== BarCount && (PivotR1=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" R1 :"+Prec(SelectedValue(YR1), 2) ,i+Vslide,SelectedValue(YR1) ,Rcolor );
if(i+Hslide== BarCount && (PivotR2=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" R2 :"+Prec(SelectedValue(YR2), 2) ,i+Vslide,SelectedValue(YR2) ,Rcolor );
if(i+Hslide== BarCount && (PivotR3=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" R3 :"+Prec(SelectedValue(YR3), 2) ,i+Vslide,SelectedValue(YR3) ,Rcolor );
if(i+Hslide== BarCount && (PivotR4=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" R4 :"+Prec(SelectedValue(YR4), 2) ,i+Vslide,SelectedValue(YR4) ,Rcolor );
if(i+Hslide== BarCount && (PivotTC=="SHOW" OR Displayshow=="all") && Displayshow!="hide") PlotText( ""+Timeframe+" TC :"+Prec(SelectedValue(TC), 2) ,i+Vslide,SelectedValue(TC) ,Pcolor);
if(i+Hslide== BarCount && (PivotP=="SHOW" OR Displayshow=="all") && Displayshow!="hide") PlotText( ""+Timeframe+" Pivot :"+Prec(SelectedValue(Pivot), 2) ,i+Vslide,SelectedValue(Pivot) ,Pcolor);
if(i+Hslide== BarCount && (PivotBC=="SHOW" OR Displayshow=="all") && Displayshow!="hide") PlotText( ""+Timeframe+" BC :"+Prec(SelectedValue(BC), 2) ,i+Vslide,SelectedValue(BC) ,Pcolor);
if(i+Hslide== BarCount && (PivotS1=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" S1 :"+Prec(SelectedValue(YS1), 2) ,i+Vslide,SelectedValue(YS1) ,Scolor );
if(i+Hslide== BarCount && (PivotS2=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" S2 :"+Prec(SelectedValue(YS2), 2) ,i+Vslide,SelectedValue(YS2) ,Scolor );
if(i+Hslide== BarCount && (PivotS3=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" S3 :"+Prec(SelectedValue(YS3), 2) ,i+Vslide,SelectedValue(YS3) ,Scolor );
if(i+Hslide== BarCount && (PivotS3=="SHOW" OR Displayshow=="all")&& Displayshow!="hide") PlotText( ""+Timeframe+" S4 :"+Prec(SelectedValue(YS4), 2) ,i+Vslide,SelectedValue(YS4) ,Scolor );
}
YupcANDlebackColor= Colorrgb(0,177, 88);
YdowncANDlebackColor= Colorrgb(246,70, 65);
YwickColorbackColor= Colorrgb(88, 97, 100);
Setchartoptions(0,Chartshowarrows|chartShowDates);
SetbarfillColor(Iif( C > O, YupcANDlebackColor,YdowncANDlebackColor ));
Plot( C, "Price", Iif( C > O, YupcANDlebackColor,YdowncANDlebackColor ), styleCandle|styleNoTitle);
_N(Title = EncodeColor(colorOrange)+ StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open = %g, Hi = %g, Lo = %g, Close = %g, Volume = %g Change = (%.1f%%) {{VALUES}}", O, H, L, C, V, SelectedValue( ROC( C, 1 ) ) ));