Coding help needed for setting stop loss / exit

hey guys

tried altering a code which i already was using

just tried changing the stop loss / exit to swing high and swing low

so tried adding the codes to the existing ones but then it stopped taking trades

can you guys help me out

basically u enter using donchain high and low and it also sees into a higher time frame before taking trades
was using donchain middle line to exit trades on closing basis
so wanted to change that to swings
heres the code :slight_smile:

_SECTION_BEGIN("Donchian Channel trading System");
SetPositionSize(1,spsShares);
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 ) ) ));

//Initial Parameters
SetTradeDelays( 0,0,0, 0 );

Plot( Close, "Price", colorWhite, styleCandle );

FirstTradeTime = 093000; //Earliest time to take a trades
LastTradeTime = 153000; //Latest time to take new trades

FirstTradeTime = ParamTime( "Start Time", "09:30" );
LastTradeTime = ParamTime( "End Time", "15:30" );

pds=Param("DonchianPeriods",1,1,100,1);

//15 minutes
DonchianUpper =HHV(Ref(H,-1),pds);
DonchianLower = LLV(Ref(L,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;

//inHourly
TimeFrameSet( inHourly );
hdu = HHV(Ref(H,-1),pds);
hdl = LLV(Ref(L,-1),pds);
hdm = (hdu+hdl)/2;
TimeFrameRestore();

wdu = TimeFrameExpand(hdu,inHourly, expandFirst);
wdl = TimeFrameExpand(hdl,inHourly, expandFirst);
wdm = TimeFrameExpand(hdm,inHourly, expandFirst);

printf("\nDonchianLower : " + wdm);

no=Param( "Swing", 12, 1, 55 );

tsl_col=ParamColor( "Color", colorLightGrey );

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);
tsl=IIf(avn==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase);
//Plot(wdm,"DM",colorGreen,styleLine|styleDots|styleThick);

Buy=Cross(High,DonchianUpper) AND Cross(High,wdu) AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Short=Cross(DonchianLower,Low) AND Cross(wdl,Low) AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Sell= Cross(tsl,LastValue(0));
Cover=Cross(LastValue(0),tsl);

/BuyPrice=DonchianUpper;
SellPrice=DonchianMiddle;
ShortPrice=DonchianLower;
CoverPrice=DonchianMiddle;
/

BuyPrice=IIf(Open>DonchianUpper,Close,DonchianUpper);
SellPrice=Close;
ShortPrice=IIf(Open<DonchianLower,Close,DonchianLower);
CoverPrice=Close;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGold, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);

@sadayappan,

Please use 'Code Blocks'.

See How to use this site

sorry about not using code blocks will use the same in the future
thx