[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: RemBuy Problem



PureBytes Links

Trading Reference Links

Rob,

I have uploaded the rembuy with a help file in 3rd section
the doc is also below
ther is only a long side, I'll do the short side tomorrow)

stephane



REMBUY

Thanks to Christian Baude who helps me to translate.

1-RemBuy TRAIL for LONG position

scRemBuyTrail is a DLL which allows you to manage your exits 
depending on your buyprice,
This DLL will eliminate the new buy signals as long as the existing 
position is not completed.

Entry and Exit are possible on the same bar

The DLL contains 8 parameters :

scRemBuyTrail(Buy,Entryprice,
StopPrice,StopLoss,TrailStop,
Target,Count,CloseBars);

1-Buy is the buy peak signal which corresponds to the open position 
bar.

2-Entryprice is your Buyprice (Close or a Buystop – in this case, in 
order to manage gaps, remember to write 
Max( BuyStop, open) )

3- StopPrice is the price that will trigger stops ( StopLoss et 
TrailingStop)
the two options are either Close or Low  , for example, choose Low <= 
stopLoss or Close <= stopLoss

4- StopLoss keeps the same value during the trade (open position).

5- Trailingstop is started on the day of the buy peak signal, it 
gives the highest value reached by your trailing stop since the buy 
peak signal HighestSince(Buy,Trailstop);

6-Target is a profitprice whose exit is managed by H>Target, it keeps 
the same value for the whole trade (open position).
This target can be expressed in % of entryprice 
Target=entryprice*1.10 ;
It can be written as a value Target=entryprice + 2*atr(10)  ;
It can be written in as Risk compared to stoploss

Pf=2;/*profit factor for target*/
Target= (1+Pf)*Entryprice - Pf*stopLoss;

7-Count is a counter (timer), which will generate an exit after n 
bars, by default this option is disable with -1 as value
But if you want exit on the second  bars after entry bar write
scRemBuyTrail(Buy,Entryprice,
StopPrice,StopLoss,TrailStop,
Target,2);

8-CloseBars is another counter(timer) which will generate an exit 
after n bars IF the Close < Entryprice, by default this option is 
disable.
for example if you write 10 bars that means that if after 10 bars the 
close is below the entryprice.
scRemBuyTrail(Buy,Entryprice,
StopPrice,StopLoss,TrailStop,
Target,-1,10); 



IN SUMMARY, THE EXIT OCCURS :

- if the stoploss is hit ( <= ) by the low or the close (option)  

- if the trailingstop is hit (<=) by the low or by the close 
(option)  

- if the gain is achieved (H>TargetPr) 

- after n bars with option Count option

- after n bars, with  CloseBars option  if the close is < entryprice


SOME OPTIONS CAN BE DELETED :

1/If you do not want any stoploss , you have to enter a value such 
that never Low < stoploss
stoploss=-1 ;

2/If you do not want any trailingstop, similarly
trailingstop=-1 ;

3/If you do not want a target, you have to give a value such that 
never High > Target
target=C*1e10 ;

4/ If you do not want any exit on a number of bars  or If you do not 
want any exit after a number of bars
Bars= -1 ;
Count=10000 ;
These two options are not active by default.

ONCE THESE PARAMETERS ARE ENTERES INTO The DLL, 
The DLL RETURNS 

a/ TrailPr, SellPr , TargetPr , StopLossPr which allows you to 
visualize and control the stops on the chart.

b/ EntryLong and exitLong Is the reason why you immediately write 
after the DLL 

Buy=EnterLong;
Sell=ExitLong;

c/ Sellpr gives the exit price while wathching for gaps à Open for 
the stops ( stoploss, trailingstop, target) and gives the close of 
the day for exit based  on a number of bars ( counter and bars)  

WHAT REMAINS IS TO SPECIFY (ENTER) YOUR BUYPRICE AND SELLPRICE

if you take a position on the day of the signal ( since your system 
works with a buystop)

Buy=EnterLong;
Sell=ExitLong;

Buyprice=Close // or Entryprice 
Sellprice=Close// or Sellpr

If you enter (or exit) on the following bar, on Open 

EITHER you write:

Buy=Ref(EnterLong,-1);
Sell=Ref(ExitLong,-1);
BuyPrice=Open;
SellPrice=Open;

OR you add:
SetTradeDelays (1,1,0,0);
with
Buy=EnterLong;
Sell=ExitLong;
BuyPrice=Open;
SellPrice=Open;

EXAMPLE


Title=Name() + " RemBuy TRAIL" ;
Buy= DayOfWeek()==5 ; /* you must convert it to one bar peak*/  

Entryprice= Close;
StopPrice= L; 
/* this is the price option for STOPLOSS AND TRAILINGSTOP you can 
choose Close or Low,
the exit price will be the low or open ( if gap) if you choose Low as 
stopprice
OR the exit price will be close if you choose close as stopprice*/

StopLoss= LLV(L,3);
/* you must give your stoploss as an array, you don't need of 
valuewhen the dll makes it for you*/

/* below is a Tips to backtest different trailing stop, the trailing 
stop is initialized the day of the buy signal*/
stop= Optimize("stop", 1, 1, 2, 1 ); 
Trailstop= 
IIf( stop==1, L-3*StDev(C,20),
IIf( stop==2, L-3*ATR(30),scCBLLong(5)));

Target= Entryprice+3*ATR(20);
/* you can disable it with an impossible target ( C*1e10) */

/* KEEP the ORDER++++*/
scRemBuyTrail(Buy,Entryprice,StopPrice,StopLoss,TrailStop,Target;
Buy=EnterLong;
Sell=ExitLong;
BuyPrice=Entryprice;
SellPrice=SellPr;/*sellpr array is given by the dll, it is Close if 
you 
choose exit on bar, Close if you choose Close as stopprice, stop OR 
Open ( if gap) if you choose Low as stopprice */ 



/* Plot the # STOPS*/

Plot(ValueWhen(Sell,SellPrice),"",colorYellow,1);
Plot(ValueWhen(Buy,BuyPrice),"",colorWhite,1);
Plot(StopLosspr,"StopLoss",colorRed,1);
Plot(TrailPr,"Trailingprice",colorGreen,1);
Plot(TargetPr,"Targetprice",colorBlue,1);

PlotShapes(IIf(Buy, shapeUpArrow,shapeNone),colorGreen,0,L,-20); 
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed,0,H,-20);  
Plot(C,"",1,64);

REMSHORT

1-RemSHORT TRAIL

NOT UPDATED






------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/