PureBytes Links
Trading Reference Links
|
Hello,
I have done an update to the rem plugin
the pligin give the sellpr or coverpr in case of a stop with low or
high, otherwise the sellpr or coverpr is the close
I have added an extra parameters to backtest intraday ( exit if time
is 1700 for example)
the sellpr or coverpr in this case is the next open bar at 1701
and the definition of the bars exit is :" if for a long side after n
bars the close is below your entryprice and on stop are reached,
exit the market on next open)
two examples below with trailing stop
/********************************************/
/****************SHORT***********************/
/************************************************/
Title=Name() + " RemShortTrail_Dll " ;
LL = ValueWhen(LLV( L, 3 ) == Ref(L,-1),Ref(L,-1)) ;
Short = L < LL ; // buystop
Short=Hold(Short==0,2) AND Short;
Ep= Close;/*entryprice*/
Stop= HHV(C,3)+ EMA(ATR(1),10);
/*StopLoss*/
Bars= -1;/*Optimize("Bars",100,4,14,1);*/
Trail=HHV(C,3)+ 2*EMA(ATR(1),10);/*trailstop*/
Profit=(3*Ep - 2*stop);
exit=DayOfWeek()==3;
/*
Capital=100000;
Risk=0.01*capital;
PositionSize=risk/(2*ATR(20))*EP;
*/
scRemShortTrail(Short,H,Ep,Stop,Profit,Trail,0,Bars);
Short=Short;
Cover=Cover;
ShortPrice=Ep;
CoverPrice=Coverpr;
Ep=ValueWhen(Short,Ep);
Stop=ValueWhen(Short,Stop);
Trail=LowestSince(Short,Trail);
Profit=(3*Ep - 2*stop);
MaxGraph=14;
Plot(Close,"close",IIf( Short, 6, IIf(Cover , 4 ,1 )),64);
Plot(Ep,"Ep",6,1);
Plot(Stop,"LL",4,1);
Plot(Trail,"Trail",7,1);
Plot(Profit,"Profit",8,1);
Plot(ValueWhen(Cover,CoverPrice),"",2,1);
Plot(Short*10,"",6,2);
Plot(Cover*5,"",7,2);
/****************************************/
/****************LONG*********************/
/******************************************/
Title=Name() + " RemBuyTrail_Dll " ;
HH = ValueWhen(HHV( H, 3 ) == Ref(H,-1),Ref(H,-1)) ;
Buy = H > HH ; // buystop
Buy= Hold(Buy==0,2) AND Buy ;/* convert to one bar */
Ep= Close;/*entryprice*/
Stop= Max(LLV(C,3)- 2*EMA(ATR(1),10),LLV(L,3)*0.995);
/*StopLoss*/
Bars= -1 ;/*Optimize("Bars",100,4,14,1);*/
Trail=LLV(C,3)- 2*EMA(ATR(1),10);/*trailstop*/
Profit=(3*Ep - 2*stop);
exit=DayOfWeek()==5;
scRemBuyTrail(Buy,L,Ep,Stop,Profit,Trail,exit,Bars);
Buy=Buy;
Sell=Sell;
BuyPrice=Ep;/*array*/
SellPrice=Sellpr;/*array*/
Ep=ValueWhen(Buy,Ep);
stop=ValueWhen(Buy,stop);
Profit=(3*Ep - 2*stop);
Trail=HighestSince(Buy,Trail);
MaxGraph=14;
Plot(Close,"close",IIf( Buy, 6, IIf(Sell , 4 ,1 )),64);
Plot(Ep,"Ep",3,1);
Plot(stop,"stop",4,1);
Plot(Profit,"Profit",7,1);
Plot(Trail,"Trail",5,1);
Plot(ValueWhen(Sell,SellPrice),"",2,1);
Plot(Buy*10,"",6,2);
Plot(Sell*5,"",7,2);
|