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

[amibroker] Re: Applystop again



PureBytes Links

Trading Reference Links

Hi Terry,

thank you for your suggestion anyway! But the meaning of your code 
is, the stops would be executed when the price of the share reaches 
1000 or 700. This in most cases never happens.

With following code I came close to the expected results, but in 
most cases I did not, because backtester uses 5% of the current 
cumulated capital, which I also prefer but cannot calculate:

TargetStop =  1000.00;	
StopLoss   =   700.00;				

Capital	   = GetOption("InitialEquity");
Investment = IIf(PositionSize<0,Capital*abs
(PositionSize)/100,PositionSize);

NumberOfShares = investment/BuyPrice;

TargetStopPoints = TargetStop/NumberOfShares;
StopLossPoints	 = StopLoss/NumberOfShares;

ApplyStop(stopTypeLoss,stopModePoint, 
amount=StopLossPoints,ExitAtStop=1,Volatile=False,ReEntryDelay=1);
	
ApplyStop(stopTypeProfit,stopModePoint, 
amount=TargetStopPoints,ExitAtStop=1,Volatile=False,ReEntryDelay=1);


enzo

--- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxxx> wrote:
> Try this or some variation:
> 
>  
> 
> PositionSize = -5; //Spends 5% of your equity
> 
> ApplyStop(StopModeProfit, stopModePoint, 1000, exitatstop = 0, 1 
or 2,
> 0, re-entry delay = 0,1,2...); 
> 
> ApplyStop(StopModeLoss, stopModePoint, 700, exitatstop = 0, 1 or 
2, 0,
> re-entry delay = 0,1,2...);
> 
>  
> 
> Buy = your buy conditions;
> 
> Sell = your buy conditions;
> 
>  
> 
> If you want to buy multiple positions then also set 
MaxOpenPositions and
> adjust PositionSize to be -5 * MaxOpenPositions.
> 
>  
> 
> MaxOpen = 5; //Buy up to 5 positions
> 
> SetOptions(MaxOpenPositions,MaxOpen);
> 
> PositionSize = MaxOpen * -5; //Spend 5% of portfolio on each 
position
> 
>  
> 
> (Note: code not tested.)
> 
> --
> 
> Terry
> 
>  
> 
> | -----Original Message-----
> 
> | From: amibroker@xxxxxxxxxxxxxxx 
[mailto:amibroker@xxxxxxxxxxxxxxx] On
> 
> | Behalf Of enzo
> 
> | Sent: Wednesday, September 07, 2005 07:08
> 
> | To: amibroker@xxxxxxxxxxxxxxx
> 
> | Subject: [amibroker] Applystop again
> 
> | 
> 
> | Hello Usergroup,
> 
> | 
> 
> | I read dozens of mails of this group about this but it seems my
> 
> | applystop-problem has not been discussed before.
> 
> | 
> 
> | I want to backtest a strategy in non-futures-mode where 5% of the
> 
> | capital is beeing used to open a position and profit-target-stops
> 
> | and Stop-Loss are executed after a certain amount, say 1000 as
> 
> | profit and 700 as loss is reached for the whole position.
> 
> | 
> 
> | Is there an easy way to calculate the number of shares beeing 
bought
> 
> | or shorted? Results of my calculation
> 
> | (NumberOfShares=investment/BuyPrice;) are always different from 
the
> 
> | numbers the backtester calculates.
> 
> | 
> 
> | Has anyone coded the same strategy and would like to help me with
> 
> | the snippet of code that I need for axecuting the stops?
> 
> | 
> 
> | Thank you in advance
> 
> | enzo
> 
> | 
> 
> | 
> 
> | 
> 
> | 
> 
> | 
> 
> | 
> 
> | ------------------------ Yahoo! Groups Sponsor ------------------
--~--
> 
> | >
> 
> | Help Sudanese refugees rebuild their lives through GlobalGiving.
> 
> | http://us.click.yahoo.com/hjNroD/EbOLAA/cosFAA/GHeqlB/TM
> 
> | -----------------------------------------------------------------
---~-
> 
> | >
> 
> | 
> 
> | Please note that this group is for discussion between users only.
> 
> | 
> 
> | To get support from AmiBroker please send an e-mail directly to
> 
> | SUPPORT {at} amibroker.com
> 
> | 
> 
> | For other support material please check also:
> 
> | http://www.amibroker.com/support.html
> 
> | 
> 
> | 
> 
> | Yahoo! Groups Links
> 
> | 
> 
> |     http://groups.yahoo.com/group/amibroker/
> 
> | 
> 
> |     amibroker-unsubscribe@xxxxxxxxxxxxxxx
> 
> | 
> 
> |     http://docs.yahoo.com/info/terms/
> 
> |




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Help tsunami villages rebuild at GlobalGiving. The real work starts now.
http://us.click.yahoo.com/njNroD/KbOLAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

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