I don't have the expertise in programming but I have been struggling 
with this same bit of code for the past 2 weeks. I have made it work 
on the long only side and would be glad to send you the EOD sys file 
I have that works. Between the detail log and the trade report you 
should be able to see what is going on and make adjustments to suite 
your needs. The switches in the backtest settings will screw you up 
if not set properly and may account for your weird results. make 
sure in the backtest settings>portfolio tab, that the limit trade 
size as % of entry bar is set to zero and just the "Trade size limit 
when..." is the only thing checked. i have my max positions set to 
one for now until I get the code fully to my liking. If you want the 
SYS file reach me at [EMAIL PROTECTED]

peace

OT

--- In [email protected], "matrix10014" <[EMAIL PROTECTED]> wrote:
>
> Hi,
> Been playing with a code that I copied to familairize myself with 
> some of the functionality of Amibroker...As you can see,the entry 
is 
> a simple moving average crossover,that exits 50% of the position 
up 
> 20% and the remaining 50% up 30%.There is also a trailing stop..
> 
> When i check a detailed log of the trade,I get very bizzare 
results.
> 
> An example is HANS..On 10/31/2005 I go long 205 shares of HANS@ 
48.59
> 
> On 11/3,I scale out of 176 [EMAIL PROTECTED] is 86% of my 
> position,when i am supposed to scale out of half.As its not my 
> code,and i am trying to learn Ami code,i really dont know what 
went 
> wrong..
> 
> 
>       
> 
> 10/31/2005
>               Enter Long, HANS, Price: 48.59, Shares: 205, 
> Commission: 0, Rank: 1, Equity 100000, Margin Loan: 0, Fx rate: 1
> 
> 
>                       11/3/2005
>               Exit signals:HANS=Scale-Out, 
>       Scale-Out Long HANS, Price 59.74, Shares 176, Fx Rate 1, 
> Number of shares - Current: 29, Exited: 176, Max: 205, Avg. Entry 
> Price 48.59, Avg. Exit Price 59.74, Avg Fx. Rate Entry 1, Exit 1, 
>       
> 
> 
> The code is as follows
>                               
> Buy = Cross(C, MA( C,21) ); 
> Sell = 0; 
> 
> // the system will exit 
> // 50% of position if FIRST PROFIT TARGET stop is hit 
> // 50% of position is SECOND PROFIT TARGET stop is hit 
> // 100% of position if TRAILING STOP is hit 
> 
> FirstProfitTarget = 20; // profit 
> SecondProfitTarget =30; // in percent 
> TrailingStop = 50; // also in percent 
> 
> 
> priceatbuy=0; 
> highsincebuy = 0; 
> 
> exit = 0; 
> 
> for( i = 0; i < BarCount; i++ ) 
> { 
>    if( priceatbuy == 0 AND Buy[ i ] ) 
>     { 
>        priceatbuy = BuyPrice[ i ]; 
>     } 
> 
>    if( priceatbuy > 0 ) 
>     { 
>        highsincebuy = Max( High[ i ], highsincebuy ); 
> 
>       if( exit == 0 AND 
>           High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * 
> priceatbuy ) 
>        { 
>          // first profit target hit - scale-out 
>          exit = 1; 
>          Buy[ i ] = sigScaleOut; 
>        } 
> 
>       if( exit == 1 AND 
>           High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * 
> priceatbuy ) 
>        { 
>          // second profit target hit - exit 
>          exit = 2; 
>          SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget 
* 
> 0.01 ) * priceatbuy ); 
>        } 
> 
>       if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy ) 
>        { 
>          // trailing stop hit - exit 
>          exit = 3;    
>          SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 
> 0.01 ) * highsincebuy ); 
>        } 
> 
>       if( exit >= 2 ) 
>        { 
>          Buy[ i ] = 0; 
>          Sell[ i ] = exit + 1; // mark appropriate exit code 
>          exit = 0; 
>          priceatbuy = 0; // reset price 
>          highsincebuy = 0; 
>        } 
>     } 
> } 
> 
> SetPositionSize( 10, spsPercentOfEquity ); 
> SetPositionSize( 50, spsPercentOfPosition * ( Buy == 
> sigScaleOut ) ); // scale out 50% of position
>







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/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:
    [EMAIL PROTECTED]

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


Reply via email to